* [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd
@ 2015-07-13 9:32 Christophe JAILLET
2015-07-13 9:46 ` Kirill A. Shutemov
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Christophe JAILLET @ 2015-07-13 9:32 UTC (permalink / raw)
To: jejb, deller, mpatocka, kirill.shutemov
Cc: linux-parisc, linux-kernel, kernel-janitors, Christophe JAILLET
Commit 0e0da48dee8d ("parisc: mm: don't count preallocated pmds")
introduced a memory leak.
After this commit, the 'return' statement in pmd_free is executed in all
cases. Even for pmd that are not attached to the pgd.
So 'free_pages' can never be called anymore, leading to a memory leak.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is *untested* as I don't have the hardware to test it.
This is just a guess based on the indentation, the comment in the code
and the commit log.
---
arch/parisc/include/asm/pgalloc.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
index 3a08eae..f66d3738 100644
--- a/arch/parisc/include/asm/pgalloc.h
+++ b/arch/parisc/include/asm/pgalloc.h
@@ -72,7 +72,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
{
- if(pmd_flag(*pmd) & PxD_FLAG_ATTACHED)
+ if (pmd_flag(*pmd) & PxD_FLAG_ATTACHED) {
/*
* This is the permanent pmd attached to the pgd;
* cannot free it.
@@ -81,6 +81,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
*/
mm_inc_nr_pmds(mm);
return;
+ }
free_pages((unsigned long)pmd, PMD_ORDER);
}
--
2.1.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* RE: [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd
2015-07-13 9:32 [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd Christophe JAILLET
@ 2015-07-13 9:46 ` Kirill A. Shutemov
2015-07-13 12:48 ` Mikulas Patocka
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Kirill A. Shutemov @ 2015-07-13 9:46 UTC (permalink / raw)
To: Christophe JAILLET
Cc: jejb, deller, mpatocka, kirill.shutemov, linux-parisc,
linux-kernel, kernel-janitors
Christophe JAILLET wrote:
> Commit 0e0da48dee8d ("parisc: mm: don't count preallocated pmds")
> introduced a memory leak.
>
> After this commit, the 'return' statement in pmd_free is executed in all
> cases. Even for pmd that are not attached to the pgd.
> So 'free_pages' can never be called anymore, leading to a memory leak.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> ---
> This patch is *untested* as I don't have the hardware to test it.
>
> This is just a guess based on the indentation, the comment in the code
> and the commit log.
> ---
> arch/parisc/include/asm/pgalloc.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
> index 3a08eae..f66d3738 100644
> --- a/arch/parisc/include/asm/pgalloc.h
> +++ b/arch/parisc/include/asm/pgalloc.h
> @@ -72,7 +72,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
>
> static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
> {
> - if(pmd_flag(*pmd) & PxD_FLAG_ATTACHED)
> + if (pmd_flag(*pmd) & PxD_FLAG_ATTACHED) {
> /*
> * This is the permanent pmd attached to the pgd;
> * cannot free it.
> @@ -81,6 +81,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
> */
> mm_inc_nr_pmds(mm);
> return;
> + }
> free_pages((unsigned long)pmd, PMD_ORDER);
> }
>
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd
2015-07-13 9:32 [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd Christophe JAILLET
2015-07-13 9:46 ` Kirill A. Shutemov
@ 2015-07-13 12:48 ` Mikulas Patocka
2015-07-13 18:52 ` Helge Deller
2015-07-14 11:09 ` Dan Carpenter
3 siblings, 0 replies; 6+ messages in thread
From: Mikulas Patocka @ 2015-07-13 12:48 UTC (permalink / raw)
To: Christophe JAILLET
Cc: jejb, deller, kirill.shutemov, linux-parisc, linux-kernel,
kernel-janitors
On Mon, 13 Jul 2015, Christophe JAILLET wrote:
> Commit 0e0da48dee8d ("parisc: mm: don't count preallocated pmds")
> introduced a memory leak.
>
> After this commit, the 'return' statement in pmd_free is executed in all
> cases. Even for pmd that are not attached to the pgd.
> So 'free_pages' can never be called anymore, leading to a memory leak.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
also add this, so that it is backported to 4.0 and 4.2:
Cc: stable@vger.kernel.org # 4.0+
Fixes: 0e0da48dee8d
> ---
> This patch is *untested* as I don't have the hardware to test it.
>
> This is just a guess based on the indentation, the comment in the code
> and the commit log.
> ---
> arch/parisc/include/asm/pgalloc.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
> index 3a08eae..f66d3738 100644
> --- a/arch/parisc/include/asm/pgalloc.h
> +++ b/arch/parisc/include/asm/pgalloc.h
> @@ -72,7 +72,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
>
> static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
> {
> - if(pmd_flag(*pmd) & PxD_FLAG_ATTACHED)
> + if (pmd_flag(*pmd) & PxD_FLAG_ATTACHED) {
> /*
> * This is the permanent pmd attached to the pgd;
> * cannot free it.
> @@ -81,6 +81,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
> */
> mm_inc_nr_pmds(mm);
> return;
> + }
> free_pages((unsigned long)pmd, PMD_ORDER);
> }
>
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd
2015-07-13 9:32 [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd Christophe JAILLET
2015-07-13 9:46 ` Kirill A. Shutemov
2015-07-13 12:48 ` Mikulas Patocka
@ 2015-07-13 18:52 ` Helge Deller
2015-07-20 19:28 ` Meelis Roos
2015-07-14 11:09 ` Dan Carpenter
3 siblings, 1 reply; 6+ messages in thread
From: Helge Deller @ 2015-07-13 18:52 UTC (permalink / raw)
To: Christophe JAILLET, jejb, mpatocka, kirill.shutemov
Cc: linux-parisc, linux-kernel, kernel-janitors, John David Anglin,
Meelis Roos
Hi Christophe,
On 13.07.2015 11:32, Christophe JAILLET wrote:
> Commit 0e0da48dee8d ("parisc: mm: don't count preallocated pmds")
> introduced a memory leak.
>
> After this commit, the 'return' statement in pmd_free is executed in all
> cases. Even for pmd that are not attached to the pgd.
> So 'free_pages' can never be called anymore, leading to a memory leak.
That's really great!!! Thanks for spotting this!
I assume this fixes the leak which killed our debian buildds with OOM
after an uptime of 1-4 days and which only happened since kernel 4.0.
Meelis Roos reported the issue already in this thread:
http://marc.info/?l=linux-parisc&m\x142999113232154&w=2
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Helge Deller <deller@gmx.de>
Will this patch be pushed via linux-mm or another tree, if
not I can take it via the parisc tree?
Helge
> ---
> This patch is *untested* as I don't have the hardware to test it.
>
> This is just a guess based on the indentation, the comment in the code
> and the commit log.
> ---
> arch/parisc/include/asm/pgalloc.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
> index 3a08eae..f66d3738 100644
> --- a/arch/parisc/include/asm/pgalloc.h
> +++ b/arch/parisc/include/asm/pgalloc.h
> @@ -72,7 +72,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
>
> static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
> {
> - if(pmd_flag(*pmd) & PxD_FLAG_ATTACHED)
> + if (pmd_flag(*pmd) & PxD_FLAG_ATTACHED) {
> /*
> * This is the permanent pmd attached to the pgd;
> * cannot free it.
> @@ -81,6 +81,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
> */
> mm_inc_nr_pmds(mm);
> return;
> + }
> free_pages((unsigned long)pmd, PMD_ORDER);
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd
2015-07-13 9:32 [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd Christophe JAILLET
` (2 preceding siblings ...)
2015-07-13 18:52 ` Helge Deller
@ 2015-07-14 11:09 ` Dan Carpenter
3 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2015-07-14 11:09 UTC (permalink / raw)
To: Christophe JAILLET
Cc: jejb, deller, mpatocka, kirill.shutemov, linux-parisc,
linux-kernel, kernel-janitors
I assume you found this with Coccinelle? Smatch can also find this bug
but you would need a cross compile environment set up.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd
2015-07-13 18:52 ` Helge Deller
@ 2015-07-20 19:28 ` Meelis Roos
0 siblings, 0 replies; 6+ messages in thread
From: Meelis Roos @ 2015-07-20 19:28 UTC (permalink / raw)
To: Helge Deller
Cc: Christophe JAILLET, jejb, mpatocka, kirill.shutemov, linux-parisc,
linux-kernel, kernel-janitors, John David Anglin
> Hi Christophe,
>
> On 13.07.2015 11:32, Christophe JAILLET wrote:
> > Commit 0e0da48dee8d ("parisc: mm: don't count preallocated pmds")
> > introduced a memory leak.
> >
> > After this commit, the 'return' statement in pmd_free is executed in all
> > cases. Even for pmd that are not attached to the pgd.
> > So 'free_pages' can never be called anymore, leading to a memory leak.
>
> That's really great!!! Thanks for spotting this!
>
> I assume this fixes the leak which killed our debian buildds with OOM
> after an uptime of 1-4 days and which only happened since kernel 4.0.
> Meelis Roos reported the issue already in this thread:
> http://marc.info/?l=linux-parisc&m\x142999113232154&w=2
Yes, the patch that is merged in 4.2-rc3 fixed my RP3410 with 1G RAM.
--
Meelis Roos (mroos@linux.ee)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-07-20 19:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-13 9:32 [PATCH] parisc: mm: Fix a memory leak related to pmd not attached to the pgd Christophe JAILLET
2015-07-13 9:46 ` Kirill A. Shutemov
2015-07-13 12:48 ` Mikulas Patocka
2015-07-13 18:52 ` Helge Deller
2015-07-20 19:28 ` Meelis Roos
2015-07-14 11:09 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox