mm: slub: allocate slab object extensions non-contiguously
Subsystems (2)
PATCH 1/2 mm: slub: allocate slab object extensions non-contiguously
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g. zs_handle zswap slab which will be 512 objsperslab x 16 bytes per slabobj_ext (order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.
--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));if (!vec) {/* Mark vectors which failed to allocate */
Signature · 1 line
2.47.1
PATCH 2/2 mm: slub: only warn once when allocating slab obj extensions fails
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to WARN_ONCE.
--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))return NULL ;
Signature · 1 line
2.47.1
Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails
Quoted 9 lines · Usama Arif
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to
WARN_ONCE.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>---
Hi,
Please Cc SLAB ALLOCATOR folks in MAINTAINERS on patches that touch slab code ;)
Quoted 8 lines
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0
mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2107
Quoted 7 lines
mm/slub.c +1
-1@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))
I think this should be pr_warn_once()?
I'm not sure why this was WARN() in the first place.
The coding style guide explicitly states that:
Quoted 10 lines
Do not WARN lightly
===================WARN*() is intended for unexpected, this-should-never-happen situations. WARN*() macros are not to be used for anything that is expected to happen during normal operation. These are not pre- or post-condition asserts, for example. Again: WARN*() must not be used for a condition that is expected to trigger easily, for example, by user space actions.
pr_warn_once()is a possible alternative, if you need to notify the user of a problem.
And failing to allocate the extension vector can happen during normal operations.
panic_on_warn users will be unhappy if they notice their kernel panicked just because their kernel failed to allocate slab extension vectors, which is a totally normal situtation.
Quoted 5 lines
return NULL;
Signature · 1 line
2.47.1
Signature · 2 lines
Cheers, Harry / Hyeonggon
Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails
Quoted 11 lines · Harry Yoo
Quoted 9 lines · Usama Arif
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to
WARN_ONCE.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>---
Quoted 5 lines
Hi,
Please Cc SLAB ALLOCATOR folks in
MAINTAINERSon patches that touch slab code ;)
Thanks for adding them to CC! I was just thinking of this as a memory allocation profiling issue and added the maintainers for it, but should have added slab maintainers as well.
Quoted 9 lines
Quoted 9 lines
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)
Quoted 10 lines
mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2107
Quoted 6 lines
mm/slub.c +1
-1slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))I think this should be
pr_warn_once()?
I'm not sure why this wasWARN()in the first place.
Isn't WARN_ONCE the same as pr_warn_once but with needing the condition of the first arg to be true? We only want to warn if alloc_slab_obj_exts returns non-zero. So WARN_ONCE should be ok?
Quoted 25 lines
The coding style guide explicitly states that:
Quoted 10 lines
Do not WARN lightly
===================WARN*() is intended for unexpected, this-should-never-happen situations. WARN*() macros are not to be used for anything that is expected to happen during normal operation. These are not pre- or post-condition asserts, for example. Again: WARN*() must not be used for a condition that is expected to trigger easily, for example, by user space actions.
pr_warn_once()is a possible alternative, if you need to notify the user of a problem.And failing to allocate the extension vector can happen during normal operations.
panic_on_warnusers will be unhappy if they notice their kernel panicked just because their kernel failed to allocate slab extension vectors, which is a totally normal situtation.Quoted 5 lines
return NULL;
Signature · 1 line
2.47.1
Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails
Quoted 45 lines · Usama Arif
Quoted 11 lines · Harry Yoo
Quoted 9 lines · Usama Arif
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to
WARN_ONCE.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>---
Quoted 5 lines
Hi,
Please Cc SLAB ALLOCATOR folks in
MAINTAINERSon patches that touch slab code ;)Thanks for adding them to CC! I was just thinking of this as a memory allocation profiling issue and added the maintainers for it, but should have added slab maintainers as well.
Quoted 9 lines
Quoted 9 lines
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)Quoted 10 lines
mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2107
Quoted 6 lines
mm/slub.c +1
-1slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))I think this should be
pr_warn_once()?
I'm not sure why this wasWARN()in the first place.
Quoted 4 lines
Isn't
WARN_ONCEthe same aspr_warn_oncebut with needing the condition of the first arg to be true? We only want to warn ifalloc_slab_obj_extsreturns non-zero. SoWARN_ONCEshould be ok?
The difference is the impact on panic_on_warn users which are mostly testing bots. This warning is not actionable, so I agree with Harry to covert this to pr_warn_once().
Quoted 26 lines
Quoted 25 lines
The coding style guide explicitly states that:
Quoted 10 lines
Do not WARN lightly
===================WARN*() is intended for unexpected, this-should-never-happen situations. WARN*() macros are not to be used for anything that is expected to happen during normal operation. These are not pre- or post-condition asserts, for example. Again: WARN*() must not be used for a condition that is expected to trigger easily, for example, by user space actions.
pr_warn_once()is a possible alternative, if you need to notify the user of a problem.And failing to allocate the extension vector can happen during normal operations.
panic_on_warnusers will be unhappy if they notice their kernel panicked just because their kernel failed to allocate slab extension vectors, which is a totally normal situtation.Quoted 5 lines
return NULL;
Signature · 1 line
2.47.1
Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails
Quoted 47 lines · Shakeel Butt
Quoted 45 lines · Usama Arif
Quoted 11 lines · Harry Yoo
Quoted 9 lines · Usama Arif
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to
WARN_ONCE.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>---
Quoted 5 lines
Hi,
Please Cc SLAB ALLOCATOR folks in
MAINTAINERSon patches that touch slab code ;)Thanks for adding them to CC! I was just thinking of this as a memory allocation profiling issue and added the maintainers for it, but should have added slab maintainers as well.
Quoted 19 lines
Quoted 8 lines
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2107
Quoted 7 lines
mm/slub.c +1
-1@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))I think this should be
pr_warn_once()?
I'm not sure why this wasWARN()in the first place.
Quoted 7 lines
Quoted 4 lines
Isn't
WARN_ONCEthe same aspr_warn_oncebut with needing the condition of the first arg to be true? We only want to warn ifalloc_slab_obj_extsreturns non-zero. SoWARN_ONCEshould be ok?The difference is the impact on
panic_on_warnusers which are mostly testing bots.
Another difference is that pr_warn() does not spit out the call stack.
Quoted 2 lines
This warning is not actionable, so I agree with Harry to covert this to
pr_warn_once().
Makes sense.
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
The coding style guide explicitly states that:
Quoted 10 lines
Do not WARN lightly
===================WARN*() is intended for unexpected, this-should-never-happen situations. WARN*() macros are not to be used for anything that is expected to happen during normal operation. These are not pre- or post-condition asserts, for example. Again: WARN*() must not be used for a condition that is expected to trigger easily, for example, by user space actions.
pr_warn_once()is a possible alternative, if you need to notify the user of a problem.And failing to allocate the extension vector can happen during normal operations.
panic_on_warnusers will be unhappy if they notice their kernel panicked just because their kernel failed to allocate slab extension vectors, which is a totally normal situtation.Quoted 5 lines
return NULL;--
2.47.1
Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails
In reply to Shakeel ButtQuoted 46 lines · Shakeel Butt
Quoted 45 lines · Usama Arif
Quoted 11 lines · Harry Yoo
Quoted 9 lines · Usama Arif
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to
WARN_ONCE.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>---
Quoted 5 lines
Hi,
Please Cc SLAB ALLOCATOR folks in
MAINTAINERSon patches that touch slab code ;)Thanks for adding them to CC! I was just thinking of this as a memory allocation profiling issue and added the maintainers for it, but should have added slab maintainers as well.
Quoted 19 lines
Quoted 8 lines
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2107
Quoted 7 lines
mm/slub.c +1
-1@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))I think this should be
pr_warn_once()?
I'm not sure why this wasWARN()in the first place.
Quoted 9 lines
Quoted 4 lines
Isn't
WARN_ONCEthe same aspr_warn_oncebut with needing the condition of the first arg to be true? We only want to warn ifalloc_slab_obj_extsreturns non-zero. SoWARN_ONCEshould be ok?The difference is the impact on
panic_on_warnusers which are mostly testing bots. This warning is not actionable, so I agree with Harry to covert this topr_warn_once().
Sounds good! Will change it to below for the next revision. Will wait for the kvmalloc conversation to conclude before sending the next revision.
mm/slub.c +7 -5
@@ -2101,11 +2101,13 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)return NULL ; slab =virt_to_slab (p); -if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), -"%s, %s: Failed to create slab extension vector!\n" , - __func__, s->name)) -return NULL ; +if (!slab_obj_exts (slab)) { +if (alloc_slab_obj_exts (slab, s, flags, false)) +pr_warn_once ("%s, %s: Failed to create slab extension vector!\n" , + __func__, s->name); +else +return NULL ; + }return slab_obj_exts (slab) +obj_to_index (s, slab, p); }
Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails
Quoted 72 lines · Usama Arif
Quoted 46 lines · Shakeel Butt
Quoted 45 lines · Usama Arif
Quoted 11 lines · Harry Yoo
Quoted 9 lines · Usama Arif
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to
WARN_ONCE.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>---
Quoted 5 lines
Hi,
Please Cc SLAB ALLOCATOR folks in
MAINTAINERSon patches that touch slab code ;)Thanks for adding them to CC! I was just thinking of this as a memory allocation profiling issue and added the maintainers for it, but should have added slab maintainers as well.
Quoted 19 lines
Quoted 8 lines
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2107
Quoted 7 lines
mm/slub.c +1
-1@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))I think this should be
pr_warn_once()?
I'm not sure why this wasWARN()in the first place.Quoted 9 lines
Quoted 4 lines
Isn't
WARN_ONCEthe same aspr_warn_oncebut with needing the condition of the first arg to be true? We only want to warn ifalloc_slab_obj_extsreturns non-zero. SoWARN_ONCEshould be ok?The difference is the impact on
panic_on_warnusers which are mostly testing bots. This warning is not actionable, so I agree with Harry to covert this topr_warn_once().Sounds good! Will change it to below for the next revision. Will wait for the kvmalloc conversation to conclude before sending the next revision.
mm/slub.c +0
-1@@ -2101,11 +2101,13 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)return NULL ; slab =virt_to_slab (p); - if (!slab_obj_exts(slab) &&
mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2109
Quoted 10 lines
mm/slub.c +6
-4-WARN (alloc_slab_obj_exts (slab, s, flags, false), -"%s, %s: Failed to create slab extension vector!\n" , - __func__, s->name)) - return NULL; +if (!slab_obj_exts (slab)) { +if (alloc_slab_obj_exts (slab, s, flags, false)) +pr_warn_once ("%s, %s: Failed to create slab extension vector!\n" , + __func__, s->name); +else +return NULL ;
Returning NULL when alloc_slab_obj_exts() succeeds doesn't make sense. I think you meant something like this?
if (!slab_obj_exts(slab) &&
alloc_slab_obj_exts(slab, s, flags, false)) {
pr_warn_once("%s, %s: Failed to create slab extension vector!\n",
__func__, s->name);
return NULL;
}Quoted 5 lines
mm/slub.c +1
-0+ }return slab_obj_exts (slab) +obj_to_index (s, slab, p); }
Signature · 2 lines
Cheers, Harry / Hyeonggon
Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails
Quoted 87 lines · Harry Yoo
Quoted 72 lines · Usama Arif
Quoted 46 lines · Shakeel Butt
Quoted 45 lines · Usama Arif
Quoted 11 lines · Harry Yoo
Quoted 9 lines · Usama Arif
In memory bound systems, a large number of warnings for failing this allocation repeatedly may mask any real issues in the system during memory pressure being reported in dmesg. Change this to
WARN_ONCE.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>---
Quoted 5 lines
Hi,
Please Cc SLAB ALLOCATOR folks in
MAINTAINERSon patches that touch slab code ;)Thanks for adding them to CC! I was just thinking of this as a memory allocation profiling issue and added the maintainers for it, but should have added slab maintainers as well.
Quoted 19 lines
Quoted 8 lines
mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2107
Quoted 7 lines
mm/slub.c +1
-1@@ -2102,7 +2102,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) slab =virt_to_slab (p);if (!slab_obj_exts (slab) && -WARN (alloc_slab_obj_exts (slab, s, flags, false), +WARN_ONCE (alloc_slab_obj_exts (slab, s, flags, false),"%s, %s: Failed to create slab extension vector!\n" , __func__, s->name))I think this should be
pr_warn_once()?
I'm not sure why this wasWARN()in the first place.Quoted 9 lines
Quoted 4 lines
Isn't
WARN_ONCEthe same aspr_warn_oncebut with needing the condition of the first arg to be true? We only want to warn ifalloc_slab_obj_extsreturns non-zero. SoWARN_ONCEshould be ok?The difference is the impact on
panic_on_warnusers which are mostly testing bots. This warning is not actionable, so I agree with Harry to covert this topr_warn_once().Sounds good! Will change it to below for the next revision. Will wait for the kvmalloc conversation to conclude before sending the next revision.
mm/slub.c +0
-1@@ -2101,11 +2101,13 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)return NULL ; slab =virt_to_slab (p); - if (!slab_obj_exts(slab) &&mm/slub.c prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) · line 2109
Quoted 10 lines
mm/slub.c +6
-4-WARN (alloc_slab_obj_exts (slab, s, flags, false), -"%s, %s: Failed to create slab extension vector!\n" , - __func__, s->name)) - return NULL; +if (!slab_obj_exts (slab)) { +if (alloc_slab_obj_exts (slab, s, flags, false)) +pr_warn_once ("%s, %s: Failed to create slab extension vector!\n" , + __func__, s->name); +else +return NULL ;Returning NULL when
alloc_slab_obj_exts()succeeds doesn't make sense. I think you meant something like this?
Quoted 7 lines
if (!slab_obj_exts(slab) &&
alloc_slab_obj_exts(slab, s, flags, false)) { pr_warn_once("%s, %s: Failed to create slab extension vector!\n", __func__, s->name); return NULL; }
Yes, Thank you!
Quoted 6 lines
Quoted 5 lines
mm/slub.c +1
-0+ }return slab_obj_exts (slab) +obj_to_index (s, slab, p); }
Quoted 18 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 6 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));
And what's the latency going to be on a vmalloc() allocation when we're low on memory?
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?
Would it not be better to get the allocation slighly slower than to not get it at all?
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?
Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Quoted 33 lines · Kent Overstreet
Quoted 32 lines · Usama Arif
Quoted 28 lines · Kent Overstreet
Quoted 18 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 6 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?
Quoted 8 lines
Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Which gfp flags vmalloc is not respecting today?
Quoted 37 lines · Shakeel Butt
Quoted 36 lines · Kent Overstreet
Quoted 34 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Would it not be better to get the allocation slighly slower than to not get it at all?
Quoted 7 lines
Quoted 5 lines
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Which gfp flags vmalloc is not respecting today?
GFP_NOWAIT.
As to why, you'd better ask Michal Hocko...
Quoted 41 lines · Kent Overstreet
Quoted 40 lines · Shakeel Butt
Quoted 39 lines · Kent Overstreet
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Which gfp flags vmalloc is not respecting today?
GFP_NOWAIT.As to why, you'd better ask Michal Hocko...
It is mainly due to pte_alloc_one_kernel(), it uses the GFP_KERNEL
#define GFP_PGTABLE_KERNEL (GFP_KERNEL | __GFP_ZERO)
to get a new pte entry.
I think we can fix it. For example if we populate some region and allocate there for NOWAIT. But there are of course can be other hidden problems.
--
Uladzislau Rezki
Quoted 51 lines · Uladzislau Rezki
Quoted 41 lines · Kent Overstreet
Quoted 40 lines · Shakeel Butt
Quoted 39 lines · Kent Overstreet
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Which gfp flags vmalloc is not respecting today?
GFP_NOWAIT.As to why, you'd better ask Michal Hocko...
Quoted 8 lines
It is mainly due to
pte_alloc_one_kernel(), it uses theGFP_KERNEL#define
GFP_PGTABLE_KERNEL(GFP_KERNEL|__GFP_ZERO)to get a new pte entry.
I think we can fix it. For example if we populate some region and allocate there for NOWAIT. But there are of course can be other hidden problems.
No, PF_MEMALLOC flags allow for passing most of gfp flags for pte allocation.
Quoted 56 lines · Kent Overstreet
Quoted 55 lines · Uladzislau Rezki
Quoted 41 lines · Kent Overstreet
Quoted 40 lines · Shakeel Butt
Quoted 39 lines · Kent Overstreet
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Which gfp flags vmalloc is not respecting today?
GFP_NOWAIT.As to why, you'd better ask Michal Hocko...
It is mainly due to
pte_alloc_one_kernel(), it uses theGFP_KERNEL#define
GFP_PGTABLE_KERNEL(GFP_KERNEL|__GFP_ZERO)
Quoted 8 lines
Quoted 4 lines
to get a new pte entry.
I think we can fix it. For example if we populate some region and allocate there for NOWAIT. But there are of course can be other hidden problems.
No,
PF_MEMALLOCflags allow for passing most of gfp flags for pte allocation.
It is hard-coded:
static inline pte_t *__pte_alloc_one_kernel_noprof(struct mm_struct *mm)
{
struct ptdesc *ptdesc = pagetable_alloc_noprof(GFP_PGTABLE_KERNEL &
~__GFP_HIGHMEM, 0);
if (!ptdesc)
return NULL;
return ptdesc_address(ptdesc);
}--
Uladzislau Rezki
Quoted 68 lines · Uladzislau Rezki
Quoted 56 lines · Kent Overstreet
Quoted 55 lines · Uladzislau Rezki
Quoted 41 lines · Kent Overstreet
Quoted 40 lines · Shakeel Butt
Quoted 39 lines · Kent Overstreet
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Which gfp flags vmalloc is not respecting today?
GFP_NOWAIT.As to why, you'd better ask Michal Hocko...
It is mainly due to
pte_alloc_one_kernel(), it uses theGFP_KERNEL#define
GFP_PGTABLE_KERNEL(GFP_KERNEL|__GFP_ZERO)Quoted 8 lines
Quoted 4 lines
to get a new pte entry.
I think we can fix it. For example if we populate some region and allocate there for NOWAIT. But there are of course can be other hidden problems.
No,
PF_MEMALLOCflags allow for passing most of gfp flags for pte allocation.It is hard-coded:
static inline
pte_t*__pte_alloc_one_kernel_noprof(structmm_struct*mm)
Quoted 8 lines
{
struct ptdesc *ptdesc = pagetable_alloc_noprof(GFP_PGTABLE_KERNEL &
~__GFP_HIGHMEM, 0);
if (!ptdesc)
return NULL;
return ptdesc_address(ptdesc);
}I suggest you read the code around PF_MEMALLOC flags.
Quoted 73 lines · Kent Overstreet
Quoted 72 lines · Uladzislau Rezki
Quoted 56 lines · Kent Overstreet
Quoted 55 lines · Uladzislau Rezki
Quoted 41 lines · Kent Overstreet
Quoted 40 lines · Shakeel Butt
Quoted 39 lines · Kent Overstreet
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Our behaviour when thrashing sucks, we don't want to do anything to make that worse.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There's also the fact that vmalloc doesn't correctly respect gfp flags, so until that gets fixed this doesn't work at all.
Which gfp flags vmalloc is not respecting today?
GFP_NOWAIT.As to why, you'd better ask Michal Hocko...
It is mainly due to
pte_alloc_one_kernel(), it uses theGFP_KERNEL#define
GFP_PGTABLE_KERNEL(GFP_KERNEL|__GFP_ZERO)Quoted 8 lines
Quoted 4 lines
to get a new pte entry.
I think we can fix it. For example if we populate some region and allocate there for NOWAIT. But there are of course can be other hidden problems.
No,
PF_MEMALLOCflags allow for passing most of gfp flags for pte allocation.It is hard-coded:
static inline
pte_t*__pte_alloc_one_kernel_noprof(structmm_struct*mm){ struct ptdesc *ptdesc = pagetable_alloc_noprof(GFP_PGTABLE_KERNEL & ~__GFP_HIGHMEM, 0);
Quoted 7 lines
Quoted 4 lines
if (!ptdesc) return NULL; return ptdesc_address(ptdesc); }I suggest you read the code around
PF_MEMALLOCflags.
To wrap the allocation context by the PF_MEMALLOC to prevent entering into direct reclaim and no sleeping, looks like another approach, i can think about.
One concern is depleting of memory reserves. Populating PTEs would not require this but i tend to say it is ugly approach which i mentioned above.
--
Uladzislau Rezki
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?
Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Also a majority of them are less than 1 page. kvmalloc of less than 1 page falls back to kmalloc. So vmalloc will only be on those greater than 1 page size, which are in the minority (for e.g. zs_handle, request_sock_subflow_v6, request_sock_subflow_v4...).
Quoted 36 lines · Usama Arif
Quoted 32 lines · Usama Arif
Quoted 28 lines · Kent Overstreet
Quoted 18 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 6 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?
Quoted 7 lines
Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Also a majority of them are less than 1 page. kvmalloc of less than 1 page falls back to kmalloc. So vmalloc will only be on those greater than 1 page size, which are in the minority (for e.g.
zs_handle,request_sock_subflow_v6,request_sock_subflow_v4...).
Not just the majority. For all of these kvmalloc allocations kmalloc will be tried first and vmalloc will be used only if the former
failed: https://elixir.bootlin.com/linux/v6.14.7/source/mm/util.c#L665
That's why I think this should not regress normal case when slab has enough space to satisfy the allocation.
Quoted 45 lines · Suren Baghdasaryan
Quoted 36 lines · Usama Arif
Quoted 32 lines · Usama Arif
Quoted 28 lines · Kent Overstreet
Quoted 18 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 6 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 7 lines
Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Also a majority of them are less than 1 page. kvmalloc of less than 1 page falls back to kmalloc. So vmalloc will only be on those greater than 1 page size, which are in the minority (for e.g.
zs_handle,request_sock_subflow_v6,request_sock_subflow_v4...).
Quoted 5 lines
Not just the majority. For all of these kvmalloc allocations kmalloc will be tried first and vmalloc will be used only if the former
failed: https://elixir.bootlin.com/linux/v6.14.7/source/mm/util.c#L665
That's why I think this should not regress normal case when slab has enough space to satisfy the allocation.
And you really should consider just letting the extension vector allocation fail if we're under that much memory pressure.
Failing allocations is an important mechanism for load shedding, otherwise stuff just piles up - it's a big cause of our terrible behaviour when we're thrashing.
It's equivalent to bufferbloat in the networking world.
Quoted 47 lines · Kent Overstreet
Quoted 45 lines · Suren Baghdasaryan
Quoted 43 lines · Usama Arif
Quoted 32 lines · Usama Arif
Quoted 14 lines · Kent Overstreet
Quoted 13 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 11 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Also a majority of them are less than 1 page. kvmalloc of less than 1 page falls back to kmalloc. So vmalloc will only be on those greater than 1 page size, which are in the minority (for e.g.
zs_handle,request_sock_subflow_v6,request_sock_subflow_v4...).
Quoted 8 lines
Quoted 5 lines
Not just the majority. For all of these kvmalloc allocations kmalloc will be tried first and vmalloc will be used only if the former
failed: https://elixir.bootlin.com/linux/v6.14.7/source/mm/util.c#L665
That's why I think this should not regress normal case when slab has enough space to satisfy the allocation.And you really should consider just letting the extension vector allocation fail if we're under that much memory pressure.
I see your point. One case we would want to use vmalloc is if the allocation is sizable (multiple pages), so failing it does not mean critical memory pressure level yet. I don't think today's extension vectors would be large enough to span multiple pages. That would require a rather large obj_per_slab and in most cases I think this change would not affect current behavior, the allocations will be smaller than PAGE_SIZE and kvmalloc will fail anyway.
I guess the question is whether we want to fail if allocation size is higher than PAGE_SIZE but less than PAGE_ALLOC_COSTLY_ORDER. Failing that I think is reasonable and I don't think any extension vector will be large enough to reach PAGE_ALLOC_COSTLY_ORDER. So, I'm ok with dropping this part of the patchset.
Quoted 6 lines
Failing allocations is an important mechanism for load shedding, otherwise stuff just piles up - it's a big cause of our terrible behaviour when we're thrashing.
It's equivalent to bufferbloat in the networking world.
Quoted 6 lines · Suren Baghdasaryan
On Tue, May 20, 2025 at 9:41 AM Kent Overstreet <[email protected]> wrote:
I see your point. One case we would want to use vmalloc is if the allocation is sizable (multiple pages), so failing it does not mean critical memory pressure level yet. I don't think today's extension vectors would be large enough to span multiple pages. That would
Quoted 8 lines
require a rather large
obj_per_slaband in most cases I think this change would not affect current behavior, the allocations will be smaller thanPAGE_SIZEand kvmalloc will fail anyway.
I guess the question is whether we want to fail if allocation size is higher thanPAGE_SIZEbut less thanPAGE_ALLOC_COSTLY_ORDER. Failing that I think is reasonable and I don't think any extension vector will be large enough to reachPAGE_ALLOC_COSTLY_ORDER. So, I'm ok with dropping this part of the patchset.
Johannes raisess more pertinent points, so I think vmalloc allocation is out.
If it turns out that extension vector allocation failures do cause real problems (not for memory allocation profiling, but maybe someone is depending on memcg being precise), I think it would acceptable to dip into reserves for them, since they're a small fraction of the slabs themselves.
With the caveat that we'd need to look at how the reserves are sized, to make sure we're not running them empty and causing new problems elsewhere.
But just failing the allocation should probably be the default approach here.
Quoted 45 lines · Suren Baghdasaryan
Quoted 36 lines · Usama Arif
Quoted 32 lines · Usama Arif
Quoted 28 lines · Kent Overstreet
Quoted 18 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1993
Quoted 6 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));And what's the latency going to be on a
vmalloc()allocation when we're low on memory?Quoted 7 lines
Quoted 2 lines
Would it not be better to get the allocation slighly slower than to not get it at all?
Also a majority of them are less than 1 page. kvmalloc of less than 1 page falls back to kmalloc. So vmalloc will only be on those greater than 1 page size, which are in the minority (for e.g.
zs_handle,request_sock_subflow_v6,request_sock_subflow_v4...).
Quoted 5 lines
Not just the majority. For all of these kvmalloc allocations kmalloc will be tried first and vmalloc will be used only if the former
failed: https://elixir.bootlin.com/linux/v6.14.7/source/mm/util.c#L665
That's why I think this should not regress normal case when slab has enough space to satisfy the allocation.
Alexei raised a good point offline that having slab enter vmalloc messes with the whole slab re-entrancy and nmi safety he has been pursuing for bpf/probing.
Add that to the other concerns around vmalloc, and I think we should just drop that part.
IMO, the more important takeaway is that we accept that this allocation is optimistic, and can and does fail in practice, even if the slab allocation itself succeeded.
So it probably makes sense to 1) ax the warning entirely - since it's not indicative of a bug. And 2) accept that the numbers can have a fudge factor in practice, and mark line items in the report correspondingly when they do.
Quoted 18 lines · Usama Arif
When memory allocation profiling is running on memory bound services, allocations greater than order 0 for slab object extensions can fail, for e.g.
zs_handlezswap slab which will be 512 objsperslab x 16 bytes perslabobj_ext(order 1 allocation). Use kvcalloc to improve chances of the allocation being successful.Signed-off-by Usama Arif <[email protected]>Reported-by Vlad Poenaru <[email protected]>--- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slub.c +0
-0
mm/slub.c int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, · line 1995
Quoted 8 lines
mm/slub.c +1
-1@@ -1989,7 +1989,7 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp &= ~OBJCGS_CLEAR_MASK ;/* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; - vec =kcalloc_node (objects,sizeof (struct slabobj_ext ), gfp, + vec =kvcalloc_node (objects,sizeof (struct slabobj_ext ), gfp,slab_nid (slab));if (!vec) {/* Mark vectors which failed to allocate */
I forgot the freeing part, This will need the below fixlet as well. I will add it to the next revision if there is another one, otherwise it can be folded into this one. Thanks!
commit fa48eab7faddfdb94faa80a1575ac1840919071e (HEAD -> prctl_huge_v3)
Author: Usama Arif <[email protected]> Date: Tue May 20 14:58:10 2025 +0100
mm: slub: change slab_obj_exts freeing to kvfree
This is to match the kvmalloc.
mm/slub.c +1 -1
@@ -2045,7 +2045,7 @@ static noinline void free_slab_obj_exts(struct slab *slab)* the extension for obj_exts is expected to be NULL. */ mark_objexts_empty (obj_exts); -kfree (obj_exts); +kvfree (obj_exts); slab->obj_exts =0 ; }