Skip to contentSkip to conversation

Revert "kmemleak: allow to coexist with fault injection"

PATCH In review Yang Shi 4 participants 11 messages Jul 16, 2019 – Jul 27, 2019

Subsystems (2)
lore
Share & tools
lore

Yang Shi

author
#0 lore raw

PATCH 1/1 Revert "kmemleak: allow to coexist with fault injection"

When running ltp's oom test with kmemleak enabled, the below warning was triggerred since kernel detects __GFP_NOFAIL & ~__GFP_DIRECT_RECLAIM is passed in:

WARNING: CPU: 105 PID: 2138 at mm/page_alloc.c:4608 __alloc_pages_nodemask+0x1c31/0x1d50
Modules linked in: loop dax_pmem dax_pmem_core ip_tables x_tables xfs virtio_net net_failover virtio_blk failover ata_generic virtio_pci virtio_ring virtio libata
CPU: 105 PID: 2138 Comm: oom01 Not tainted 5.2.0-next-20190710+ #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.2-0-g5f4c7b1-prebuilt.qemu-project.org 04/01/2014
RIP: 0010:__alloc_pages_nodemask+0x1c31/0x1d50
...
 kmemleak_alloc+0x4e/0xb0
 kmem_cache_alloc+0x2a7/0x3e0
 ? __kmalloc+0x1d6/0x470
 ? ___might_sleep+0x9c/0x170
 ? mempool_alloc+0x2b0/0x2b0
 mempool_alloc_slab+0x2d/0x40
 mempool_alloc+0x118/0x2b0
 ? __kasan_check_read+0x11/0x20
 ? mempool_resize+0x390/0x390
 ? lock_downgrade+0x3c0/0x3c0
 bio_alloc_bioset+0x19d/0x350
 ? __swap_duplicate+0x161/0x240
 ? bvec_alloc+0x1b0/0x1b0
 ? do_raw_spin_unlock+0xa8/0x140
 ? _raw_spin_unlock+0x27/0x40
 get_swap_bio+0x80/0x230
 ? __x64_sys_madvise+0x50/0x50
 ? end_swap_bio_read+0x310/0x310
 ? __kasan_check_read+0x11/0x20
 ? check_chain_key+0x24e/0x300
 ? bdev_write_page+0x55/0x130
 __swap_writepage+0x5ff/0xb20

The mempool_alloc_slab() clears __GFP_DIRECT_RECLAIM, however kmemleak has __GFP_NOFAIL set all the time due to commit d9570ee3bd1d4f20ce63485f5ef05663866fe6c0 ("kmemleak: allow to coexist with fault injection"). But, it doesn't make any sense to have __GFP_NOFAIL and ~__GFP_DIRECT_RECLAIM specified at the same time.

According to the discussion on the mailing list, the commit should be reverted for short term solution. Catalin Marinas would follow up with a better solution for longer term.

The failure rate of kmemleak metadata allocation may increase in some circumstances, but this should be expected side effect.

Cc Michal Hocko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc David Rientjes <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Qian Cai <[email protected]>
---
 mm/kmemleak.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +1 -1
index 9dd581d..884a5e3 100644
@@ -114,7 +114,7 @@
 /* GFP bitmask for kmemleak internal allocations */
 #define gfp_kmemleak_mask(gfp)	(((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \
 				 __GFP_NORETRY | __GFP_NOMEMALLOC | \
-				 __GFP_NOWARN | __GFP_NOFAIL)
+				 __GFP_NOWARN)
 
 /* scanning area inside a memory block */
 struct kmemleak_scan_area {
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 43 lines · Yang Shi

When running ltp's oom test with kmemleak enabled, the below warning was triggerred since kernel detects __GFP_NOFAIL & ~__GFP_DIRECT_RECLAIM is passed in:

WARNING: CPU: 105 PID: 2138 at mm/page_alloc.c:4608
__alloc_pages_nodemask+0x1c31/0x1d50
Modules linked in: loop dax_pmem dax_pmem_core ip_tables x_tables xfs
virtio_net net_failover virtio_blk failover ata_generic virtio_pci virtio_ring
virtio libata
CPU: 105 PID: 2138 Comm: oom01 Not tainted 5.2.0-next-20190710+ #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.2-0-
g5f4c7b1-prebuilt.qemu-project.org 04/01/2014
RIP: 0010:__alloc_pages_nodemask+0x1c31/0x1d50
...
 kmemleak_alloc+0x4e/0xb0
 kmem_cache_alloc+0x2a7/0x3e0
 ? __kmalloc+0x1d6/0x470
 ? ___might_sleep+0x9c/0x170
 ? mempool_alloc+0x2b0/0x2b0
 mempool_alloc_slab+0x2d/0x40
 mempool_alloc+0x118/0x2b0
 ? __kasan_check_read+0x11/0x20
 ? mempool_resize+0x390/0x390
 ? lock_downgrade+0x3c0/0x3c0
 bio_alloc_bioset+0x19d/0x350
 ? __swap_duplicate+0x161/0x240
 ? bvec_alloc+0x1b0/0x1b0
 ? do_raw_spin_unlock+0xa8/0x140
 ? _raw_spin_unlock+0x27/0x40
 get_swap_bio+0x80/0x230
 ? __x64_sys_madvise+0x50/0x50
 ? end_swap_bio_read+0x310/0x310
 ? __kasan_check_read+0x11/0x20
 ? check_chain_key+0x24e/0x300
 ? bdev_write_page+0x55/0x130
 __swap_writepage+0x5ff/0xb20

The mempool_alloc_slab() clears __GFP_DIRECT_RECLAIM, however kmemleak has __GFP_NOFAIL set all the time due to commit d9570ee3bd1d4f20ce63485f5ef05663866fe6c0 ("kmemleak: allow to coexist with fault injection").  But, it doesn't make any sense to have __GFP_NOFAIL and ~__GFP_DIRECT_RECLAIM specified at the same time.

Quoted 7 lines

According to the discussion on the mailing list, the commit should be reverted for short term solution.  Catalin Marinas would follow up with a better
solution for longer term.

The failure rate of kmemleak metadata allocation may increase in some circumstances, but this should be expected side effect.

As mentioned in anther thread, the situation for kmemleak under memory pressure has already been unhealthy. I don't feel comfortable to make it even worse by reverting this commit alone. This could potentially make kmemleak kill itself easier and miss some more real memory leak later.

To make it really a short-term solution before the reverting, I think someone needs to follow up with the mempool solution with tunable pool size mentioned in,

https://lore.kernel.org/linux-mm/[email protected]/

I personally not very confident that Catalin will find some time soon to implement embedding kmemleak metadata into the slab. Even he or someone does eventually, it probably need quite some time to test and edge out many of corner cases that kmemleak could have by its natural.

Quoted 26 lines
Cc Michal Hocko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc David Rientjes <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Qian Cai <[email protected]>

---
 mm/kmemleak.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +1 -1
index 9dd581d..884a5e3 100644
@@ -114,7 +114,7 @@
  /* GFP bitmask for kmemleak internal allocations */
  #define gfp_kmemleak_mask(gfp)	(((gfp) & (GFP_KERNEL | GFP_ATOMIC)) |
 \
  				 __GFP_NORETRY | __GFP_NOMEMALLOC | \
-				 __GFP_NOWARN | __GFP_NOFAIL)
+				 __GFP_NOWARN)


 /* scanning area inside a memory block */
 struct kmemleak_scan_area {

author
#2 lore raw
Quoted 60 lines · Qian Cai
Quoted 43 lines · Yang Shi

When running ltp's oom test with kmemleak enabled, the below warning was triggerred since kernel detects __GFP_NOFAIL & ~__GFP_DIRECT_RECLAIM is passed in:

WARNING: CPU: 105 PID: 2138 at mm/page_alloc.c:4608
__alloc_pages_nodemask+0x1c31/0x1d50
Modules linked in: loop dax_pmem dax_pmem_core ip_tables x_tables xfs
virtio_net net_failover virtio_blk failover ata_generic virtio_pci virtio_ring
virtio libata
CPU: 105 PID: 2138 Comm: oom01 Not tainted 5.2.0-next-20190710+ #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.2-0-
g5f4c7b1-prebuilt.qemu-project.org 04/01/2014
RIP: 0010:__alloc_pages_nodemask+0x1c31/0x1d50
...
  kmemleak_alloc+0x4e/0xb0
  kmem_cache_alloc+0x2a7/0x3e0
  ? __kmalloc+0x1d6/0x470
  ? ___might_sleep+0x9c/0x170
  ? mempool_alloc+0x2b0/0x2b0
  mempool_alloc_slab+0x2d/0x40
  mempool_alloc+0x118/0x2b0
  ? __kasan_check_read+0x11/0x20
  ? mempool_resize+0x390/0x390
  ? lock_downgrade+0x3c0/0x3c0
  bio_alloc_bioset+0x19d/0x350
  ? __swap_duplicate+0x161/0x240
  ? bvec_alloc+0x1b0/0x1b0
  ? do_raw_spin_unlock+0xa8/0x140
  ? _raw_spin_unlock+0x27/0x40
  get_swap_bio+0x80/0x230
  ? __x64_sys_madvise+0x50/0x50
  ? end_swap_bio_read+0x310/0x310
  ? __kasan_check_read+0x11/0x20
  ? check_chain_key+0x24e/0x300
  ? bdev_write_page+0x55/0x130
  __swap_writepage+0x5ff/0xb20

The mempool_alloc_slab() clears __GFP_DIRECT_RECLAIM, however kmemleak has __GFP_NOFAIL set all the time due to commit d9570ee3bd1d4f20ce63485f5ef05663866fe6c0 ("kmemleak: allow to coexist with fault injection").  But, it doesn't make any sense to have __GFP_NOFAIL and ~__GFP_DIRECT_RECLAIM specified at the same time.

Quoted 7 lines

According to the discussion on the mailing list, the commit should be reverted for short term solution.  Catalin Marinas would follow up with a better
solution for longer term.

The failure rate of kmemleak metadata allocation may increase in some circumstances, but this should be expected side effect.

As mentioned in anther thread, the situation for kmemleak under memory pressure has already been unhealthy. I don't feel comfortable to make it even worse by reverting this commit alone. This could potentially make kmemleak kill itself easier and miss some more real memory leak later.

To make it really a short-term solution before the reverting, I think someone needs to follow up with the mempool solution with tunable pool size mentioned in,

Quoted 6 lines

https://lore.kernel.org/linux-mm/[email protected]/

I personally not very confident that Catalin will find some time soon to implement embedding kmemleak metadata into the slab. Even he or someone does eventually, it probably need quite some time to test and edge out many of corner cases that kmemleak could have by its natural.

Thanks for sharing some background. I didn't notice this topic had been discussed. I'm not sure if this revert would make things worse since I'm supposed real memory leak would be detected sooner before oom kicks in, and kmemleak is already broken with __GFP_NOFAIL.

It seems everyone agree __GFP_NPFAIL should be removed? Anyway, I would like leave the decision to Catalin.

Quoted 26 lines
Quoted 26 lines
Cc Michal Hocko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc David Rientjes <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Qian Cai <[email protected]>
---
  mm/kmemleak.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +1 -1
index 9dd581d..884a5e3 100644
@@ -114,7 +114,7 @@
  /* GFP bitmask for kmemleak internal allocations */
  #define gfp_kmemleak_mask(gfp)	(((gfp) & (GFP_KERNEL | GFP_ATOMIC)) |
 \
  				 __GFP_NORETRY | __GFP_NOMEMALLOC | \
-				 __GFP_NOWARN | __GFP_NOFAIL)
+				 __GFP_NOWARN)
 
  /* scanning area inside a memory block */

 struct kmemleak_scan_area {

#3 lore raw
Quoted 78 lines · Yang Shi
Quoted 67 lines · Qian Cai
Quoted 44 lines · Yang Shi

When running ltp's oom test with kmemleak enabled, the below warning was triggerred since kernel detects __GFP_NOFAIL & ~__GFP_DIRECT_RECLAIM is passed in:

WARNING: CPU: 105 PID: 2138 at mm/page_alloc.c:4608
__alloc_pages_nodemask+0x1c31/0x1d50
Modules linked in: loop dax_pmem dax_pmem_core ip_tables x_tables xfs
virtio_net net_failover virtio_blk failover ata_generic virtio_pci
virtio_ring
virtio libata
CPU: 105 PID: 2138 Comm: oom01 Not tainted 5.2.0-next-20190710+ #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.2-0-
g5f4c7b1-prebuilt.qemu-project.org 04/01/2014
RIP: 0010:__alloc_pages_nodemask+0x1c31/0x1d50
...
  kmemleak_alloc+0x4e/0xb0
  kmem_cache_alloc+0x2a7/0x3e0
  ? __kmalloc+0x1d6/0x470
  ? ___might_sleep+0x9c/0x170
  ? mempool_alloc+0x2b0/0x2b0
  mempool_alloc_slab+0x2d/0x40
  mempool_alloc+0x118/0x2b0
  ? __kasan_check_read+0x11/0x20
  ? mempool_resize+0x390/0x390
  ? lock_downgrade+0x3c0/0x3c0
  bio_alloc_bioset+0x19d/0x350
  ? __swap_duplicate+0x161/0x240
  ? bvec_alloc+0x1b0/0x1b0
  ? do_raw_spin_unlock+0xa8/0x140
  ? _raw_spin_unlock+0x27/0x40
  get_swap_bio+0x80/0x230
  ? __x64_sys_madvise+0x50/0x50
  ? end_swap_bio_read+0x310/0x310
  ? __kasan_check_read+0x11/0x20
  ? check_chain_key+0x24e/0x300
  ? bdev_write_page+0x55/0x130
  __swap_writepage+0x5ff/0xb20

The mempool_alloc_slab() clears __GFP_DIRECT_RECLAIM, however kmemleak has __GFP_NOFAIL set all the time due to commit d9570ee3bd1d4f20ce63485f5ef05663866fe6c0 ("kmemleak: allow to coexist with fault injection").  But, it doesn't make any sense to have __GFP_NOFAIL and ~__GFP_DIRECT_RECLAIM specified at the same time.

Quoted 7 lines

According to the discussion on the mailing list, the commit should be reverted for short term solution.  Catalin Marinas would follow up with a better
solution for longer term.

The failure rate of kmemleak metadata allocation may increase in some circumstances, but this should be expected side effect.

As mentioned in anther thread, the situation for kmemleak under memory pressure
has already been unhealthy. I don't feel comfortable to make it even worse by
reverting this commit alone. This could potentially make kmemleak kill itself
easier and miss some more real memory leak later.

To make it really a short-term solution before the reverting, I think someone
needs to follow up with the mempool solution with tunable pool size mentioned
in,

Quoted 8 lines

https://lore.kernel.org/linux-mm/[email protected]
/

I personally not very confident that Catalin will find some time soon to implement embedding kmemleak metadata into the slab. Even he or someone does eventually, it probably need quite some time to test and edge out many of corner
cases that kmemleak could have by its natural.

Quoted 4 lines

Thanks for sharing some background. I didn't notice this topic had been discussed. I'm not sure if this revert would make things worse since I'm supposed real memory leak would be detected sooner before oom kicks in, and kmemleak is already broken with __GFP_NOFAIL.

Well, people could inject some memory pressure at the middle of a test run. OOM does not necessarily mean kmemleak would always be disabled, as it sometimes could survive if the memory is recovering fast enough.

Thanks to this commit, there are allocation with __GFP_DIRECT_RECLAIM that succeeded would keep trying with __GFP_NOFAIL for kmemleak tracking object allocations. Otherwise, one kmemleak object allocation failure would kill the whole kmemleak.

Quoted 33 lines

It seems everyone agree __GFP_NPFAIL should be removed? Anyway, I would like leave the decision to Catalin.

Quoted 27 lines
Quoted 27 lines
Cc Michal Hocko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc David Rientjes <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Qian Cai <[email protected]>

---
  mm/kmemleak.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +0 -0
index 9dd581d..884a5e3 100644
@@ -114,7 +114,7 @@
   /* GFP bitmask for kmemleak internal allocations */
   #define gfp_kmemleak_mask(gfp)	(((gfp) & (GFP_KERNEL |

GFP_ATOMIC)) |
\
    __GFP_NORETRY | __GFP_NOMEMALLOC | \

mm/kmemleak.c +1 -1
-				 __GFP_NOWARN | __GFP_NOFAIL)
+				 __GFP_NOWARN)


  /* scanning area inside a memory block */
  struct kmemleak_scan_area {

#4 lore raw

On Tue 16-07-19 15:21:17, Qian Cai wrote:
[...]

Quoted 3 lines

Thanks to this commit, there are allocation with __GFP_DIRECT_RECLAIM that succeeded would keep trying with __GFP_NOFAIL for kmemleak tracking object allocations.

Well, not really. Because low order allocations with __GFP_DIRECT_RECLAIM basically never fail (they keep retrying) even without GFP_NOFAIL because that flag is actually to guarantee no failure. And for high order allocations the nofail mode is actively harmful. It completely changes the behavior of a system. A light costly order workload could put the system on knees and completely change the behavior. I am not really convinced this is a good behavior of a debugging feature TBH.

Quoted 2 lines

Otherwise, one kmemleak object allocation failure would kill the whole kmemleak.

Which is not great but quite likely a better than an unpredictable MM behavior caused by NOFAIL storms. Really, this NOFAIL patch is a completely broken behavior. There shouldn't be much discussion about reverting it. I would even argue it shouldn't have been merged in the first place. It doesn't have any acks nor reviewed-bys while it abuses __GFP_NOFAIL which is generally discouraged to be used.

Thanks!

Signature · 2 lines
Michal Hocko
SUSE Labs
#5 lore raw
Quoted 6 lines · Michal Hocko

On Tue 16-07-19 15:21:17, Qian Cai wrote:
[...]

Quoted 3 lines

Thanks to this commit, there are allocation with __GFP_DIRECT_RECLAIM that succeeded would keep trying with __GFP_NOFAIL for kmemleak tracking object allocations.

Quoted 8 lines

Well, not really. Because low order allocations with __GFP_DIRECT_RECLAIM basically never fail (they keep retrying) even without GFP_NOFAIL because that flag is actually to guarantee no failure. And for high order allocations the nofail mode is actively harmful. It completely changes the behavior of a system. A light costly order workload could put the system on knees and completely change the behavior. I am not really convinced this is a good behavior of a debugging feature TBH.

While I agree your general observation about GFP_NOFAIL, I am afraid the discussion here is about "struct kmemleak_object" slab cache from a single call site create_object().

Quoted 10 lines
Quoted 3 lines

Otherwise, one kmemleak object allocation failure would kill the whole kmemleak.

Which is not great but quite likely a better than an unpredictable MM behavior caused by NOFAIL storms. Really, this NOFAIL patch is a completely broken behavior. There shouldn't be much discussion about reverting it. I would even argue it shouldn't have been merged in the first place. It doesn't have any acks nor reviewed-bys while it abuses __GFP_NOFAIL which is generally discouraged to be used.

Again, it seems you are talking about GFP_NOFAIL in general. I don't really see much unpredictable MM behavior which would disrupt the testing or generate false-positive bug reports when "struct kmemleak_object" allocations with GFP_NOFAIL apart from some warnings. All I see is that kmemleak stay alive help find real memory leaks.

#6 lore raw
Quoted 16 lines · Qian Cai
Quoted 6 lines · Michal Hocko

On Tue 16-07-19 15:21:17, Qian Cai wrote:
[...]

Quoted 3 lines

Thanks to this commit, there are allocation with __GFP_DIRECT_RECLAIM that succeeded would keep trying with __GFP_NOFAIL for kmemleak tracking object allocations.

Quoted 8 lines

Well, not really. Because low order allocations with __GFP_DIRECT_RECLAIM basically never fail (they keep retrying) even without GFP_NOFAIL because that flag is actually to guarantee no failure. And for high order allocations the nofail mode is actively harmful. It completely changes the behavior of a system. A light costly order workload could put the system on knees and completely change the behavior. I am not really convinced this is a good behavior of a debugging feature TBH.

Quoted 3 lines

While I agree your general observation about GFP_NOFAIL, I am afraid the discussion here is about "struct kmemleak_object" slab cache from a single call site create_object().

OK, this makes it less harmfull because the order aspect doesn't really apply here. But still stretches the NOFAIL semantic a lot. The kmemleak essentially asks for NORETRY | NOFAIL which means no oom but retry for ever semantic for sleeping allocations. This can still lead to unexpected side effects. Just consider a call site that holds locks and now cannot make any forward progress without anybody else hitting the oom killer for example. As noted in other email, I would simply drop NORETRY flag as well and live with the fact that the oom killer can be invoked. It still wouldn't solve the NOWAIT contexts but those need a proper solution anyway.

Signature · 2 lines
Michal Hocko
SUSE Labs
maintainer
#7 lore raw
In reply to Qian Cai
Quoted 10 lines · Qian Cai

As mentioned in anther thread, the situation for kmemleak under memory pressure has already been unhealthy. I don't feel comfortable to make it even worse by reverting this commit alone. This could potentially make kmemleak kill itself easier and miss some more real memory leak later.

To make it really a short-term solution before the reverting, I think someone needs to follow up with the mempool solution with tunable pool size mentioned in,

https://lore.kernel.org/linux-mm/[email protected]/

Before my little bit of spare time disappears, let's add the tunable to the mempool size so that I can repost the patch. Are you ok with a kernel cmdline parameter or you'd rather change it at runtime? The latter implies a minor extension to mempool to allow it to refill on demand. I'd personally go for the former.

Signature · 1 line
Catalin
#8 lore raw
Quoted 14 lines · Catalin Marinas
Quoted 9 lines · Qian Cai

As mentioned in anther thread, the situation for kmemleak under memory pressure has already been unhealthy. I don't feel comfortable to make it even worse by reverting this commit alone. This could potentially make kmemleak kill itself easier and miss some more real memory leak later.

To make it really a short-term solution before the reverting, I think someone needs to follow up with the mempool solution with tunable pool size mentioned in,

Quoted 7 lines
Quoted 1 line

https://lore.kernel.org/linux-mm/[email protected]/

Before my little bit of spare time disappears, let's add the tunable to the mempool size so that I can repost the patch. Are you ok with a kernel cmdline parameter or you'd rather change it at runtime? The latter implies a minor extension to mempool to allow it to refill on demand. I'd personally go for the former.

Agreed. The cmdline is good enough.

Acked-by on v1 1/1
#9 lore raw
In reply to Yang Shi
Quoted 46 lines · Yang Shi

When running ltp's oom test with kmemleak enabled, the below warning was triggerred since kernel detects __GFP_NOFAIL & ~__GFP_DIRECT_RECLAIM is passed in:

WARNING: CPU: 105 PID: 2138 at mm/page_alloc.c:4608 __alloc_pages_nodemask+0x1c31/0x1d50
Modules linked in: loop dax_pmem dax_pmem_core ip_tables x_tables xfs virtio_net net_failover virtio_blk failover ata_generic virtio_pci virtio_ring virtio libata
CPU: 105 PID: 2138 Comm: oom01 Not tainted 5.2.0-next-20190710+ #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.2-0-g5f4c7b1-prebuilt.qemu-project.org 04/01/2014
RIP: 0010:__alloc_pages_nodemask+0x1c31/0x1d50
...
 kmemleak_alloc+0x4e/0xb0
 kmem_cache_alloc+0x2a7/0x3e0
 ? __kmalloc+0x1d6/0x470
 ? ___might_sleep+0x9c/0x170
 ? mempool_alloc+0x2b0/0x2b0
 mempool_alloc_slab+0x2d/0x40
 mempool_alloc+0x118/0x2b0
 ? __kasan_check_read+0x11/0x20
 ? mempool_resize+0x390/0x390
 ? lock_downgrade+0x3c0/0x3c0
 bio_alloc_bioset+0x19d/0x350
 ? __swap_duplicate+0x161/0x240
 ? bvec_alloc+0x1b0/0x1b0
 ? do_raw_spin_unlock+0xa8/0x140
 ? _raw_spin_unlock+0x27/0x40
 get_swap_bio+0x80/0x230
 ? __x64_sys_madvise+0x50/0x50
 ? end_swap_bio_read+0x310/0x310
 ? __kasan_check_read+0x11/0x20
 ? check_chain_key+0x24e/0x300
 ? bdev_write_page+0x55/0x130
 __swap_writepage+0x5ff/0xb20

The mempool_alloc_slab() clears __GFP_DIRECT_RECLAIM, however kmemleak has __GFP_NOFAIL set all the time due to commit d9570ee3bd1d4f20ce63485f5ef05663866fe6c0 ("kmemleak: allow to coexist with fault injection"). But, it doesn't make any sense to have __GFP_NOFAIL and ~__GFP_DIRECT_RECLAIM specified at the same time.

According to the discussion on the mailing list, the commit should be reverted for short term solution. Catalin Marinas would follow up with a better solution for longer term.

The failure rate of kmemleak metadata allocation may increase in some circumstances, but this should be expected side effect.

Quoted 7 lines
Cc Michal Hocko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc David Rientjes <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Qian Cai <[email protected]>

I forgot

Quoted 19 lines
---
 mm/kmemleak.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +1 -1
index 9dd581d..884a5e3 100644
@@ -114,7 +114,7 @@
 /* GFP bitmask for kmemleak internal allocations */
 #define gfp_kmemleak_mask(gfp)	(((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \
 				 __GFP_NORETRY | __GFP_NOMEMALLOC | \
-				 __GFP_NOWARN | __GFP_NOFAIL)
+				 __GFP_NOWARN)
 
 /* scanning area inside a memory block */
 struct kmemleak_scan_area {
Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko
SUSE Labs
#10 lore raw
Quoted 55 lines · Michal Hocko
Quoted 46 lines · Yang Shi

When running ltp's oom test with kmemleak enabled, the below warning was triggerred since kernel detects __GFP_NOFAIL & ~__GFP_DIRECT_RECLAIM is passed in:

WARNING: CPU: 105 PID: 2138 at mm/page_alloc.c:4608 __alloc_pages_nodemask+0x1c31/0x1d50
Modules linked in: loop dax_pmem dax_pmem_core ip_tables x_tables xfs virtio_net net_failover virtio_blk failover ata_generic virtio_pci virtio_ring virtio libata
CPU: 105 PID: 2138 Comm: oom01 Not tainted 5.2.0-next-20190710+ #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.2-0-g5f4c7b1-prebuilt.qemu-project.org 04/01/2014
RIP: 0010:__alloc_pages_nodemask+0x1c31/0x1d50
...
 kmemleak_alloc+0x4e/0xb0
 kmem_cache_alloc+0x2a7/0x3e0
 ? __kmalloc+0x1d6/0x470
 ? ___might_sleep+0x9c/0x170
 ? mempool_alloc+0x2b0/0x2b0
 mempool_alloc_slab+0x2d/0x40
 mempool_alloc+0x118/0x2b0
 ? __kasan_check_read+0x11/0x20
 ? mempool_resize+0x390/0x390
 ? lock_downgrade+0x3c0/0x3c0
 bio_alloc_bioset+0x19d/0x350
 ? __swap_duplicate+0x161/0x240
 ? bvec_alloc+0x1b0/0x1b0
 ? do_raw_spin_unlock+0xa8/0x140
 ? _raw_spin_unlock+0x27/0x40
 get_swap_bio+0x80/0x230
 ? __x64_sys_madvise+0x50/0x50
 ? end_swap_bio_read+0x310/0x310
 ? __kasan_check_read+0x11/0x20
 ? check_chain_key+0x24e/0x300
 ? bdev_write_page+0x55/0x130
 __swap_writepage+0x5ff/0xb20

The mempool_alloc_slab() clears __GFP_DIRECT_RECLAIM, however kmemleak has __GFP_NOFAIL set all the time due to commit d9570ee3bd1d4f20ce63485f5ef05663866fe6c0 ("kmemleak: allow to coexist with fault injection"). But, it doesn't make any sense to have __GFP_NOFAIL and ~__GFP_DIRECT_RECLAIM specified at the same time.

According to the discussion on the mailing list, the commit should be reverted for short term solution. Catalin Marinas would follow up with a better solution for longer term.

The failure rate of kmemleak metadata allocation may increase in some circumstances, but this should be expected side effect.

Quoted 7 lines
Cc Michal Hocko <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc David Rientjes <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Qian Cai <[email protected]>
Quoted 2 lines

I forgot

Btw. If this leads to early allocation failures too often then dropping __GFP_NORETRY should help for now until a better solution is available. It could lead to OOM killer invocation which is probably the reason why it has been added but probably better than completely disabling kmemleak altogether. Up to Catalin I guess.

Quoted 23 lines
Quoted 19 lines
---
 mm/kmemleak.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +1 -1
index 9dd581d..884a5e3 100644
@@ -114,7 +114,7 @@
 /* GFP bitmask for kmemleak internal allocations */
 #define gfp_kmemleak_mask(gfp)	(((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \
 				 __GFP_NORETRY | __GFP_NOMEMALLOC | \
-				 __GFP_NOWARN | __GFP_NOFAIL)
+				 __GFP_NOWARN)
 
 /* scanning area inside a memory block */
 struct kmemleak_scan_area {
Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko
SUSE Labs
Signature · 2 lines
Michal Hocko
SUSE Labs