Skip to contentSkip to conversation

mm: slub: allocate slab object extensions non-contiguously

PATCH In review Usama Arif 7 participants 26 messages May 20, 2025 – May 22, 2025

Subsystems (2)
lore
Share & tools
lore

Usama Arif

author
#0 lore raw

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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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
author
#1 lore raw

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
index bf43c403ead2..97cb3d9e8d00 100644
@@ -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
#2 lore raw

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.

---

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
index bf43c403ead2..97cb3d9e8d00 100644

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
author
#3 lore raw

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.

---

Quoted 5 lines

Hi,

Please Cc SLAB ALLOCATOR folks in MAINTAINERS on 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
index bf43c403ead2..97cb3d9e8d00 100644
@@ -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 -1
 	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.

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_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
#4 lore raw

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.

---

Quoted 5 lines

Hi,

Please Cc SLAB ALLOCATOR folks in MAINTAINERS on 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
index bf43c403ead2..97cb3d9e8d00 100644
@@ -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 -1
 	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.

Quoted 4 lines

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?

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_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
#5 lore raw

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.

---

Quoted 5 lines

Hi,

Please Cc SLAB ALLOCATOR folks in MAINTAINERS on 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 -0
index bf43c403ead2..97cb3d9e8d00 100644

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.

Quoted 7 lines
Quoted 4 lines

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?

The difference is the impact on panic_on_warn users 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_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;

--
2.47.1

author
#6 lore raw

Re: [PATCH 2/2] mm: slub: only warn once when allocating slab obj extensions fails

In reply to Shakeel Butt
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.

---

Quoted 5 lines

Hi,

Please Cc SLAB ALLOCATOR folks in MAINTAINERS on 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 -0
index bf43c403ead2..97cb3d9e8d00 100644

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.

Quoted 9 lines
Quoted 4 lines

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?

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().

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
index 08804d2f2ead..ab0b7ee87159 100644
@@ -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);
 }
#7 lore raw

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.

---

Quoted 5 lines

Hi,

Please Cc SLAB ALLOCATOR folks in MAINTAINERS on 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 -0
index bf43c403ead2..97cb3d9e8d00 100644

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.

Quoted 9 lines
Quoted 4 lines

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?

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().

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
index 08804d2f2ead..ab0b7ee87159 100644
@@ -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
author
#8 lore raw

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.

---

Quoted 5 lines

Hi,

Please Cc SLAB ALLOCATOR folks in MAINTAINERS on 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 -0
index bf43c403ead2..97cb3d9e8d00 100644

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.

Quoted 9 lines
Quoted 4 lines

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?

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().

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
index 08804d2f2ead..ab0b7ee87159 100644
@@ -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);
 }
#9 lore raw
In reply to Usama Arif
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_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 +0 -0
index dc9e729e1d26..bf43c403ead2 100644

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?

author
#10 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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?

#11 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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.

#12 lore raw
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_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 +0 -0
index dc9e729e1d26..bf43c403ead2 100644

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 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?

#13 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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...

#14 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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

#15 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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 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.

No, PF_MEMALLOC flags allow for passing most of gfp flags for pte allocation.

#16 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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)

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_MEMALLOC flags 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

#17 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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)

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_MEMALLOC flags 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)

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.

#18 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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)

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_MEMALLOC flags 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);
Quoted 7 lines
Quoted 4 lines
	if (!ptdesc)
		return NULL;
	return ptdesc_address(ptdesc);
}

I suggest you read the code around PF_MEMALLOC flags.

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

author
#19 lore raw
In reply to 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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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...).

#20 lore raw
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_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 +0 -0
index dc9e729e1d26..bf43c403ead2 100644

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 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.

#21 lore raw
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_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 +0 -0
index dc9e729e1d26..bf43c403ead2 100644

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 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.

#22 lore raw
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_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(-)
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
index dc9e729e1d26..bf43c403ead2 100644
@@ -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.

#23 lore raw
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_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.

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.

#24 lore raw
In reply to Suren Baghdasaryan
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_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 +0 -0
index dc9e729e1d26..bf43c403ead2 100644

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 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.

author
#25 lore raw
In reply to Usama Arif
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_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 +0 -0
index dc9e729e1d26..bf43c403ead2 100644

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
index 97cb3d9e8d00..2245e8d8fffb 100644
@@ -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;
 }