Skip to content

Commit 4645915

Browse files
Michal Hockotehcaster
authored andcommitted
mm: kvmalloc: make kmalloc fast path real fast path
There are users like xfs which need larger allocations with NOFAIL sementic. They are not using kvmalloc currently because the current implementation tries too hard to allocate through the kmalloc path which causes a lot of direct reclaim and compaction and that hurts performance a lot (see 8dc9384 ("xfs: reduce kvmalloc overhead for CIL shadow buffers") for more details). kvmalloc does support __GFP_RETRY_MAYFAIL semantic to express that kmalloc (physically contiguous) allocation is preferred and we should go more aggressive to make it happen. There is currently no way to express that kmalloc should be very lightweight and as it has been argued [1] this mode should be default to support kvmalloc(NOFAIL) with a lightweight kmalloc path which is currently impossible to express as __GFP_NOFAIL cannot be combined by any other reclaim modifiers. This patch makes all kmalloc allocations GFP_NOWAIT unless __GFP_RETRY_MAYFAIL is provided to kvmalloc. This allows to support both fail fast and retry hard on physically contiguous memory with vmalloc fallback. There is a potential downside that relatively small allocations (smaller than PAGE_ALLOC_COSTLY_ORDER) could fallback to vmalloc too easily and cause page block fragmentation. We cannot really rule that out but it seems that xlog_cil_kvmalloc use doesn't indicate this to be happening. [1] https://lore.kernel.org/all/[email protected]/T/#u Signed-off-by: Michal Hocko <[email protected]> Acked-by: Shakeel Butt <[email protected]> Link: https://patch.msgid.link/Z-48K0OdNxZXcnkB@tiehlicka Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 9c32cda commit 4645915

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mm/slub.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4982,14 +4982,16 @@ static gfp_t kmalloc_gfp_adjust(gfp_t flags, size_t size)
49824982
* We want to attempt a large physically contiguous block first because
49834983
* it is less likely to fragment multiple larger blocks and therefore
49844984
* contribute to a long term fragmentation less than vmalloc fallback.
4985-
* However make sure that larger requests are not too disruptive - no
4986-
* OOM killer and no allocation failure warnings as we have a fallback.
4985+
* However make sure that larger requests are not too disruptive - i.e.
4986+
* do not direct reclaim unless physically continuous memory is preferred
4987+
* (__GFP_RETRY_MAYFAIL mode). We still kick in kswapd/kcompactd to
4988+
* start working in the background
49874989
*/
49884990
if (size > PAGE_SIZE) {
49894991
flags |= __GFP_NOWARN;
49904992

49914993
if (!(flags & __GFP_RETRY_MAYFAIL))
4992-
flags |= __GFP_NORETRY;
4994+
flags &= ~__GFP_DIRECT_RECLAIM;
49934995

49944996
/* nofail semantic is implemented by the vmalloc fallback */
49954997
flags &= ~__GFP_NOFAIL;

0 commit comments

Comments
 (0)