netfs: Fix missing alloc tagging of direct mempool allocations
Subsystems (3)
PATCH 1/1 netfs: Fix missing alloc tagging of direct mempool allocations
Commit 1d78d56c43ef ("netfs: Fix folio_queue ENOMEM in writeback by adding a mempool") added a mempool for the folio_queues and made the request, subrequest and folio_queue allocations distinguish between writeback and everything else. Writeback is part of memory reclaim and must not fail due to ENOMEM, so it allocates under GFP_NOFS through mempool_alloc(), which may dip into the pool's reserve and, if that runs empty, wait for elements to be returned. The GFP_KERNEL paths, which can return -ENOMEM to their callers, invoke the pool's ->alloc() callback directly instead.
The direct call, however, skips the alloc_hooks() wrapper that the mempool_alloc() macro provides. The pool callbacks, mempool_alloc_slab() and mempool_kmalloc(), call kmem_cache_alloc_noprof() and kmalloc_noprof() and rely on current->alloc_tag having been set by the caller. With CONFIG_MEM_ALLOC_PROFILING_DEBUG=y this leads to
current->alloc_tag not set
WARNING: ./include/linux/alloc_tag.h:161 at __alloc_tagging_slab_alloc_hook alloc_tag was not set
WARNING: ./include/linux/alloc_tag.h:166 at __alloc_tagging_slab_free_hook
at allocation and free time respectively, as reported when reading files on a CIFS mount. The allocations are also missing from /proc/allocinfo.
Wrap the direct ->alloc() invocations in alloc_hooks() with the new netfs_mempool_alloc_noreserve() helper. The GFP_KERNEL paths keep their failable allocation semantics, they just get tagged now.
--- fs/netfs/internal.h | 3 +++ fs/netfs/objects.c | 4 ++-- fs/netfs/rolling_buffer.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)
fs/netfs/internal.h +3 -0
@@ -45,6 +45,9 @@ extern mempool_t netfs_request_pool;extern mempool_t netfs_subrequest_pool;extern mempool_t netfs_folioq_pool; +#define netfs_mempool_alloc_noreserve (_pool, _gfp) \ + alloc_hooks((_pool)->alloc(_gfp, (_pool)->pool_data)) +#ifdef CONFIG_PROC_FS static inline void netfs_proc_add_rreq (struct netfs_io_request *rreq) {
fs/netfs/objects.c +2 -2
@@ -34,7 +34,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, rreq =mempool_alloc (mempool, gfp); }else { - rreq = mempool->alloc (gfp, mempool->pool_data); + rreq =netfs_mempool_alloc_noreserve (mempool, gfp);if (!rreq)return ERR_PTR (-ENOMEM ); }
@@ -214,7 +214,7 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreqstruct kmem_cache *cache = mempool->pool_data;if (rreq->gfp ==GFP_KERNEL ) - subreq = mempool->alloc (rreq->gfp, mempool->pool_data); + subreq =netfs_mempool_alloc_noreserve (mempool, rreq->gfp);else subreq =mempool_alloc (mempool, rreq->gfp);if (!subreq)
fs/netfs/rolling_buffer.c +1 -1
@@ -29,7 +29,7 @@ struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,struct folio_queue *fq;if (gfp ==GFP_KERNEL ) - fq = netfs_folioq_pool.alloc (gfp, netfs_folioq_pool.pool_data); + fq =netfs_mempool_alloc_noreserve (&netfs_folioq_pool, gfp);else fq =mempool_alloc (&netfs_folioq_pool, gfp);if (fq) {
Signature · 1 line
2.25.1
Quoted 47 lines · Hao Ge
Commit
1d78d56c43ef("netfs: Fixfolio_queueENOMEM in writeback by adding a mempool") added a mempool for thefolio_queuesand made the request, subrequest andfolio_queueallocations distinguish between writeback and everything else. Writeback is part of memory reclaim and must not fail due to ENOMEM, so it allocates underGFP_NOFSthroughmempool_alloc(), which may dip into the pool's reserve and, if that runs empty, wait for elements to be returned. TheGFP_KERNELpaths, which can return-ENOMEMto their callers, invoke the pool's ->alloc() callback directly instead.The direct call, however, skips the
alloc_hooks()wrapper that themempool_alloc()macro provides. The pool callbacks,mempool_alloc_slab()andmempool_kmalloc(), callkmem_cache_alloc_noprof()andkmalloc_noprof()and rely oncurrent->alloc_taghaving been set by the caller. WithCONFIG_MEM_ALLOC_PROFILING_DEBUG=ythis leads to
current->alloc_tagnot set
WARNING:./include/linux/alloc_tag.h:161at__alloc_tagging_slab_alloc_hookalloc_tagwas not set
WARNING:./include/linux/alloc_tag.h:166at__alloc_tagging_slab_free_hookat allocation and free time respectively, as reported when reading files on a CIFS mount. The allocations are also missing from
/proc/allocinfo.Wrap the direct ->alloc() invocations in
alloc_hooks()with the newnetfs_mempool_alloc_noreserve()helper. TheGFP_KERNELpaths keep their failable allocation semantics, they just get tagged now.Fixes 1d78d56c43ef ("netfs: Fix folio_queue ENOMEM in writeback by adding a mempool")Reported-by Erhard Furtner <[email protected]>Tested-by Erhard Furtner <[email protected]>Signed-off-by Hao Ge <[email protected]>--- fs/netfs/internal.h | 3 +++ fs/netfs/objects.c | 4 ++-- fs/netfs/rolling_buffer.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)fs/netfs/internal.h +0
-0
fs/netfs/internal.h extern mempool_t netfs_request_pool; · line 49
Quoted 5 lines
fs/netfs/internal.h +2
-0@@ -45,6 +45,9 @@ extern mempool_t netfs_request_pool;extern mempool_t netfs_subrequest_pool;extern mempool_t netfs_folioq_pool; +#define netfs_mempool_alloc_noreserve (_pool, _gfp) \ + alloc_hooks((_pool)->alloc(_gfp, (_pool)->pool_data))
I think this macro should reside in include/linux/mempool.h and not be netfs-specific. Something like:
#define mempool_alloc_noreserve(_pool, _gfp) \
alloc_hooks((_pool)->alloc(_gfp, (_pool)->pool_data))Quoted 43 lines
fs/netfs/internal.h +1
-0+#ifdef CONFIG_PROC_FS static inline void netfs_proc_add_rreq (struct netfs_io_request *rreq) {fs/netfs/objects.c +2
-2@@ -34,7 +34,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, rreq =mempool_alloc (mempool, gfp); }else { - rreq = mempool->alloc (gfp, mempool->pool_data); + rreq =netfs_mempool_alloc_noreserve (mempool, gfp);if (!rreq)return ERR_PTR (-ENOMEM ); }@@ -214,7 +214,7 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreqstruct kmem_cache *cache = mempool->pool_data;if (rreq->gfp ==GFP_KERNEL ) - subreq = mempool->alloc (rreq->gfp, mempool->pool_data); + subreq =netfs_mempool_alloc_noreserve (mempool, rreq->gfp);else subreq =mempool_alloc (mempool, rreq->gfp);if (!subreq)fs/netfs/rolling_buffer.c +1
-2@@ -29,7 +29,7 @@ struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,struct folio_queue *fq;if (gfp ==GFP_KERNEL ) - fq = netfs_folioq_pool.alloc (gfp, netfs_folioq_pool.pool_data); + fq =netfs_mempool_alloc_noreserve (&netfs_folioq_pool, gfp);else fq =mempool_alloc (&netfs_folioq_pool, gfp);if (fq) { --2.25.1
Hi Suren
Thanks for your review.
Quoted 51 lines · Suren Baghdasaryan
Quoted 50 lines · Hao Ge
Commit
1d78d56c43ef("netfs: Fixfolio_queueENOMEM in writeback by adding a mempool") added a mempool for thefolio_queuesand made the request, subrequest andfolio_queueallocations distinguish between writeback and everything else. Writeback is part of memory reclaim and must not fail due to ENOMEM, so it allocates underGFP_NOFSthroughmempool_alloc(), which may dip into the pool's reserve and, if that runs empty, wait for elements to be returned. TheGFP_KERNELpaths, which can return-ENOMEMto their callers, invoke the pool's ->alloc() callback directly instead.The direct call, however, skips the
alloc_hooks()wrapper that themempool_alloc()macro provides. The pool callbacks,mempool_alloc_slab()andmempool_kmalloc(), callkmem_cache_alloc_noprof()andkmalloc_noprof()and rely oncurrent->alloc_taghaving been set by the caller. WithCONFIG_MEM_ALLOC_PROFILING_DEBUG=ythis leads to
current->alloc_tagnot set
WARNING:./include/linux/alloc_tag.h:161at__alloc_tagging_slab_alloc_hookalloc_tagwas not set
WARNING:./include/linux/alloc_tag.h:166at__alloc_tagging_slab_free_hookat allocation and free time respectively, as reported when reading files on a CIFS mount. The allocations are also missing from
/proc/allocinfo.Wrap the direct ->alloc() invocations in
alloc_hooks()with the newnetfs_mempool_alloc_noreserve()helper. TheGFP_KERNELpaths keep their failable allocation semantics, they just get tagged now.Fixes 1d78d56c43ef ("netfs: Fix folio_queue ENOMEM in writeback by adding a mempool")Reported-by Erhard Furtner <[email protected]>Tested-by Erhard Furtner <[email protected]>Signed-off-by Hao Ge <[email protected]>--- fs/netfs/internal.h | 3 +++ fs/netfs/objects.c | 4 ++-- fs/netfs/rolling_buffer.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)fs/netfs/internal.h +0
-0@@ -45,6 +45,9 @@ extern mempool_t netfs_request_pool;extern mempool_t netfs_subrequest_pool;extern mempool_t netfs_folioq_pool;
Quoted 9 lines
fs/netfs/internal.h extern mempool_t netfs_request_pool; · line 49
Quoted 2 lines
fs/netfs/internal.h +2
-0+#define netfs_mempool_alloc_noreserve (_pool, _gfp) \ + alloc_hooks((_pool)->alloc(_gfp, (_pool)->pool_data))I think this macro should reside in
include/linux/mempool.hand not be netfs-specific. Something like:#define mempool_alloc_noreserve(_pool, _gfp) \ alloc_hooks((_pool)->alloc(_gfp, (_pool)->pool_data))
Sure. I kept it in netfs initially since we're the only ones calling ->alloc() directly today, but it is indeed a better fit for mempool.h.
Will fix that in v2.
Thanks
Best Regards
Hao
Quoted 43 lines
Quoted 43 lines
fs/netfs/internal.h +1
-0+#ifdef CONFIG_PROC_FS static inline void netfs_proc_add_rreq (struct netfs_io_request *rreq) {fs/netfs/objects.c +2
-2@@ -34,7 +34,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, rreq =mempool_alloc (mempool, gfp); }else { - rreq = mempool->alloc (gfp, mempool->pool_data); + rreq =netfs_mempool_alloc_noreserve (mempool, gfp);if (!rreq)return ERR_PTR (-ENOMEM ); }@@ -214,7 +214,7 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreqstruct kmem_cache *cache = mempool->pool_data;if (rreq->gfp ==GFP_KERNEL ) - subreq = mempool->alloc (rreq->gfp, mempool->pool_data); + subreq =netfs_mempool_alloc_noreserve (mempool, rreq->gfp);else subreq =mempool_alloc (mempool, rreq->gfp);if (!subreq)fs/netfs/rolling_buffer.c +1
-2@@ -29,7 +29,7 @@ struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,struct folio_queue *fq;if (gfp ==GFP_KERNEL ) - fq = netfs_folioq_pool.alloc (gfp, netfs_folioq_pool.pool_data); + fq =netfs_mempool_alloc_noreserve (&netfs_folioq_pool, gfp);else fq =mempool_alloc (&netfs_folioq_pool, gfp);if (fq) { --2.25.1