Skip to contentSkip to conversation

mm: SLAB freelist randomization

PATCH Superseded Thomas Garnier 4 participants 7 messages Apr 26, 2016 – Apr 29, 2016 Memory management

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 mm: SLAB freelist randomization

Provides an optional config (CONFIG_FREELIST_RANDOM) to randomize the SLAB freelist. The list is randomized during initialization of a new set of pages. The order on different freelist sizes is pre-computed at boot for performance. Each kmem_cache has its own randomized freelist. Before pre-computed lists are available freelists are generated dynamically. This security feature reduces the predictability of the kernel SLAB allocator against heap overflows rendering attacks much less stable.

For example this attack against SLUB (also applicable against SLAB) would be affected:
https://jon.oberheide.org/blog/2010/09/10/linux-kernel-can-slub-overflow/

Also, since v4.6 the freelist was moved at the end of the SLAB. It means a controllable heap is opened to new attacks not yet publicly discussed. A kernel heap overflow can be transformed to multiple use-after-free. This feature makes this type of attack harder too.

To generate entropy, we use get_random_bytes_arch because 0 bits of entropy is available in the boot stage. In the worse case this function will fallback to the get_random_bytes sub API. We also generate a shift random number to shift pre-computed freelist for each new set of pages.

The config option name is not specific to the SLAB as this approach will be extended to other allocators like SLUB.

Performance results highlighted no major changes:

Hackbench (running 90 10 times):

Before average: 0.0698
After average: 0.0663 (-5.01%)

slab_test 1 run on boot. Difference only seen on the 2048 size test being the worse case scenario covered by freelist randomization. New slab pages are constantly being created on the 10000 allocations. Variance should be mainly due to getting new pages every few allocations.

Before:

Single thread testing
=====================
1. Kmalloc: Repeatedly allocate then free test 10000 times kmalloc(8) -> 99 cycles kfree -> 112 cycles 10000 times kmalloc(16) -> 109 cycles kfree -> 140 cycles 10000 times kmalloc(32) -> 129 cycles kfree -> 137 cycles 10000 times kmalloc(64) -> 141 cycles kfree -> 141 cycles 10000 times kmalloc(128) -> 152 cycles kfree -> 148 cycles 10000 times kmalloc(256) -> 195 cycles kfree -> 167 cycles 10000 times kmalloc(512) -> 257 cycles kfree -> 199 cycles 10000 times kmalloc(1024) -> 393 cycles kfree -> 251 cycles 10000 times kmalloc(2048) -> 649 cycles kfree -> 228 cycles 10000 times kmalloc(4096) -> 806 cycles kfree -> 370 cycles 10000 times kmalloc(8192) -> 814 cycles kfree -> 411 cycles 10000 times kmalloc(16384) -> 892 cycles kfree -> 455 cycles
2. Kmalloc: alloc/free test
10000 times kmalloc(8)/kfree -> 121 cycles
10000 times kmalloc(16)/kfree -> 121 cycles
10000 times kmalloc(32)/kfree -> 121 cycles
10000 times kmalloc(64)/kfree -> 121 cycles
10000 times kmalloc(128)/kfree -> 121 cycles
10000 times kmalloc(256)/kfree -> 119 cycles
10000 times kmalloc(512)/kfree -> 119 cycles
10000 times kmalloc(1024)/kfree -> 119 cycles 10000 times kmalloc(2048)/kfree -> 119 cycles 10000 times kmalloc(4096)/kfree -> 121 cycles 10000 times kmalloc(8192)/kfree -> 119 cycles 10000 times kmalloc(16384)/kfree -> 119 cycles

After:

Single thread testing
=====================
1. Kmalloc: Repeatedly allocate then free test 10000 times kmalloc(8) -> 130 cycles kfree -> 86 cycles 10000 times kmalloc(16) -> 118 cycles kfree -> 86 cycles 10000 times kmalloc(32) -> 121 cycles kfree -> 85 cycles 10000 times kmalloc(64) -> 176 cycles kfree -> 102 cycles 10000 times kmalloc(128) -> 178 cycles kfree -> 100 cycles 10000 times kmalloc(256) -> 205 cycles kfree -> 109 cycles 10000 times kmalloc(512) -> 262 cycles kfree -> 136 cycles 10000 times kmalloc(1024) -> 342 cycles kfree -> 157 cycles 10000 times kmalloc(2048) -> 701 cycles kfree -> 238 cycles 10000 times kmalloc(4096) -> 803 cycles kfree -> 364 cycles 10000 times kmalloc(8192) -> 835 cycles kfree -> 404 cycles 10000 times kmalloc(16384) -> 896 cycles kfree -> 441 cycles
2. Kmalloc: alloc/free test
10000 times kmalloc(8)/kfree -> 121 cycles
10000 times kmalloc(16)/kfree -> 121 cycles
10000 times kmalloc(32)/kfree -> 123 cycles
10000 times kmalloc(64)/kfree -> 142 cycles
10000 times kmalloc(128)/kfree -> 121 cycles
10000 times kmalloc(256)/kfree -> 119 cycles
10000 times kmalloc(512)/kfree -> 119 cycles
10000 times kmalloc(1024)/kfree -> 119 cycles 10000 times kmalloc(2048)/kfree -> 119 cycles 10000 times kmalloc(4096)/kfree -> 119 cycles 10000 times kmalloc(8192)/kfree -> 119 cycles 10000 times kmalloc(16384)/kfree -> 119 cycles

---
Based on next-20160422

---
 include/linux/slab_def.h |   4 ++
 init/Kconfig             |   9 +++
 mm/slab.c                | 167 ++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 178 insertions(+), 2 deletions(-)
include/linux/slab_def.h +4 -0
index 9edbbf3..182ec26 100644
@@ -80,6 +80,10 @@ struct kmem_cache {
 	struct kasan_cache kasan_info;
 #endif
 
+#ifdef CONFIG_FREELIST_RANDOM
+	void *random_seq;
+#endif
+
 	struct kmem_cache_node *node[MAX_NUMNODES];
 };
 
init/Kconfig +9 -0
index 0c66640..73453d0 100644
@@ -1742,6 +1742,15 @@ config SLOB
 
 endchoice
 
+config FREELIST_RANDOM
+	default n
+	depends on SLAB
+	bool "SLAB freelist randomization"
+	help
+	  Randomizes the freelist order used on creating new SLABs. This
+	  security feature reduces the predictability of the kernel slab
+	  allocator against heap overflows.
+
 config SLUB_CPU_PARTIAL
 	default y
 	depends on SLUB && SMP
mm/slab.c +165 -2

211 lines not on this page · raw message

Signature · 1 line
2.8.0.rc3.226.g39d4020
maintainer
#1 lore raw
Quoted 60 lines · On Tue, 26 Apr 2016 09:21:10 -0700 Thomas Garnier <[email protected]> wrote:

Provides an optional config (CONFIG_FREELIST_RANDOM) to randomize the SLAB freelist. The list is randomized during initialization of a new set of pages. The order on different freelist sizes is pre-computed at boot for performance. Each kmem_cache has its own randomized freelist. Before pre-computed lists are available freelists are generated dynamically. This security feature reduces the predictability of the kernel SLAB allocator against heap overflows rendering attacks much less stable.

For example this attack against SLUB (also applicable against SLAB) would be affected:
https://jon.oberheide.org/blog/2010/09/10/linux-kernel-can-slub-overflow/

Also, since v4.6 the freelist was moved at the end of the SLAB. It means a controllable heap is opened to new attacks not yet publicly discussed. A kernel heap overflow can be transformed to multiple use-after-free. This feature makes this type of attack harder too.

To generate entropy, we use get_random_bytes_arch because 0 bits of entropy is available in the boot stage. In the worse case this function will fallback to the get_random_bytes sub API. We also generate a shift random number to shift pre-computed freelist for each new set of pages.

The config option name is not specific to the SLAB as this approach will be extended to other allocators like SLUB.

Performance results highlighted no major changes:

Hackbench (running 90 10 times):

Before average: 0.0698
After average: 0.0663 (-5.01%)

slab_test 1 run on boot. Difference only seen on the 2048 size test being the worse case scenario covered by freelist randomization. New slab pages are constantly being created on the 10000 allocations. Variance should be mainly due to getting new pages every few allocations.

...

include/linux/slab_def.h +4 -0
@@ -80,6 +80,10 @@ struct kmem_cache {
 	struct kasan_cache kasan_info;
 #endif
 
+#ifdef CONFIG_FREELIST_RANDOM
+	void *random_seq;
+#endif
+
 	struct kmem_cache_node *node[MAX_NUMNODES];
 };
 
init/Kconfig +0 -0
index 0c66640..73453d0 100644
@@ -1742,6 +1742,15 @@ config SLOB
 

init/Kconfig config SLOB · line 1752

Quoted 10 lines
init/Kconfig +8 -0
 endchoice
 
+config FREELIST_RANDOM
+	default n
+	depends on SLAB
+	bool "SLAB freelist randomization"
+	help
+	  Randomizes the freelist order used on creating new SLABs. This
+	  security feature reduces the predictability of the kernel slab
+	  allocator against heap overflows.

Against the v2 patch I didst observe:

: CONFIG_FREELIST_RANDOM bugs me a bit - "freelist" is so vague. : CONFIG_SLAB_FREELIST_RANDOM would be better. I mean, what Kconfig : identifier could be used for implementing randomisation in : slub/slob/etc once CONFIG_FREELIST_RANDOM is used up?

but this pearl appeared to pass unnoticed.

Quoted 32 lines
init/Kconfig +0 -0
 config SLUB_CPU_PARTIAL
 	default y
 	depends on SLUB && SMP
mm/slab.c +21 -0
index b82ee6b..0ed728a 100644
@@ -1230,6 +1230,61 @@ static void __init set_up_node(struct kmem_cache *cachep, int index)
 	}
 }
 
+#ifdef CONFIG_FREELIST_RANDOM
+static void freelist_randomize(struct rnd_state *state, freelist_idx_t *list,
+			size_t count)
+{
+	size_t i;
+	unsigned int rand;
+
+	for (i = 0; i < count; i++)
+		list[i] = i;
+
+	/* Fisher-Yates shuffle */
+	for (i = count - 1; i > 0; i--) {
+		rand = prandom_u32_state(state);
+		rand %= (i + 1);
+		swap(list[i], list[rand]);
+	}
+}
+
+/* Create a random sequence per cache */
+static int cache_random_seq_create(struct kmem_cache *cachep)
+{

mm/slab.c static void __init set_up_node(struct kmem_cache *cachep, int index) · line 1263

Quoted 10 lines
mm/slab.c +10 -0
+	unsigned int seed, count = cachep->num;
+	struct rnd_state state;
+
+	if (count < 2)
+		return 0;
+
+	/* If it fails, we will just use the global lists */
+	cachep->random_seq = kcalloc(count, sizeof(freelist_idx_t), GFP_KERNEL);
+	if (!cachep->random_seq)
+		return -ENOMEM;

OK, no BUG. If this happens, kmem_cache_init_late() will go BUG instead ;)

Questions for slab maintainers:

What's going on with the gfp_flags in there? kmem_cache_init_late() passes GFP_NOWAIT into enable_cpucache().

a) why the heck does it do that? It's __init code!

b) if there's a legit reason then your new cache_random_seq_create() should be getting its gfp_t from its caller, rather than blindly assuming GFP_KERNEL.

c) kmem_cache_init_late() goes BUG on ENOMEM. Generally that's OK in __init code: we assume infinite memory during bootup. But it's really quite weird to use GFP_NOWAIT and then to go BUG if GFP_NOWAIT had its predictable outcome (ie: failure).

Finally, all callers of enable_cpucache() (and hence of cache_random_seq_create()) are __init, so we're unnecessarily bloating up vmlinux. Could someone please take a look at this as a separate thing?

Quoted 11 lines
mm/slab.c +8 -0
+	/* Get best entropy at this stage */
+	get_random_bytes_arch(&seed, sizeof(seed));
+	prandom_seed_state(&state, seed);
+
+	freelist_randomize(&state, cachep->random_seq, count);
+	return 0;
+}
+
 
...
#2 lore raw
Quoted 75 lines · Andrew Morton
Quoted 60 lines · On Tue, 26 Apr 2016 09:21:10 -0700 Thomas Garnier <[email protected]> wrote:

Provides an optional config (CONFIG_FREELIST_RANDOM) to randomize the SLAB freelist. The list is randomized during initialization of a new set of pages. The order on different freelist sizes is pre-computed at boot for performance. Each kmem_cache has its own randomized freelist. Before pre-computed lists are available freelists are generated dynamically. This security feature reduces the predictability of the kernel SLAB allocator against heap overflows rendering attacks much less stable.

For example this attack against SLUB (also applicable against SLAB) would be affected:
https://jon.oberheide.org/blog/2010/09/10/linux-kernel-can-slub-overflow/

Also, since v4.6 the freelist was moved at the end of the SLAB. It means a controllable heap is opened to new attacks not yet publicly discussed. A kernel heap overflow can be transformed to multiple use-after-free. This feature makes this type of attack harder too.

To generate entropy, we use get_random_bytes_arch because 0 bits of entropy is available in the boot stage. In the worse case this function will fallback to the get_random_bytes sub API. We also generate a shift random number to shift pre-computed freelist for each new set of pages.

The config option name is not specific to the SLAB as this approach will be extended to other allocators like SLUB.

Performance results highlighted no major changes:

Hackbench (running 90 10 times):

Before average: 0.0698
After average: 0.0663 (-5.01%)

slab_test 1 run on boot. Difference only seen on the 2048 size test being the worse case scenario covered by freelist randomization. New slab pages are constantly being created on the 10000 allocations. Variance should be mainly due to getting new pages every few allocations.

...

include/linux/slab_def.h +4 -0
@@ -80,6 +80,10 @@ struct kmem_cache {
      struct kasan_cache kasan_info;
 #endif
 
+#ifdef CONFIG_FREELIST_RANDOM
+     void *random_seq;
+#endif
+
      struct kmem_cache_node *node[MAX_NUMNODES];
 };
 
init/Kconfig +0 -0
index 0c66640..73453d0 100644
@@ -1742,6 +1742,15 @@ config SLOB
 

init/Kconfig config SLOB · line 1752

Quoted 10 lines
init/Kconfig +8 -0
 endchoice
 
+config FREELIST_RANDOM
+     default n
+     depends on SLAB
+     bool "SLAB freelist randomization"
+     help
+       Randomizes the freelist order used on creating new SLABs. This
+       security feature reduces the predictability of the kernel slab
+       allocator against heap overflows.

Against the v2 patch I didst observe:

Quoted 7 lines

: CONFIG_FREELIST_RANDOM bugs me a bit - "freelist" is so vague. : CONFIG_SLAB_FREELIST_RANDOM would be better. I mean, what Kconfig : identifier could be used for implementing randomisation in : slub/slob/etc once CONFIG_FREELIST_RANDOM is used up?

but this pearl appeared to pass unnoticed.

It was discussed a bit before. The intent is to have a similar feature for other kernel heap (I know it is possible for SLUB). That's why I think it make sense to have a similar config name used for all allocators.

Quoted 37 lines
Quoted 37 lines
init/Kconfig +0 -0
 config SLUB_CPU_PARTIAL
      default y
      depends on SLUB && SMP
mm/slab.c +26 -0
index b82ee6b..0ed728a 100644
@@ -1230,6 +1230,61 @@ static void __init set_up_node(struct kmem_cache *cachep, int index)
      }
 }
 
+#ifdef CONFIG_FREELIST_RANDOM
+static void freelist_randomize(struct rnd_state *state, freelist_idx_t *list,
+                     size_t count)
+{
+     size_t i;
+     unsigned int rand;
+
+     for (i = 0; i < count; i++)
+             list[i] = i;
+
+     /* Fisher-Yates shuffle */
+     for (i = count - 1; i > 0; i--) {
+             rand = prandom_u32_state(state);
+             rand %= (i + 1);
+             swap(list[i], list[rand]);
+     }
+}
+
+/* Create a random sequence per cache */
+static int cache_random_seq_create(struct kmem_cache *cachep)
+{
+     unsigned int seed, count = cachep->num;
+     struct rnd_state state;
+
+     if (count < 2)
+             return 0;
Quoted 9 lines

mm/slab.c static void __init set_up_node(struct kmem_cache *cachep, int index) · line 1263

Quoted 5 lines
mm/slab.c +5 -0
+
+     /* If it fails, we will just use the global lists */
+     cachep->random_seq = kcalloc(count, sizeof(freelist_idx_t), GFP_KERNEL);
+     if (!cachep->random_seq)
+             return -ENOMEM;

OK, no BUG. If this happens, kmem_cache_init_late() will go BUG instead ;)

Yes, as Christophe asked.

Quoted 32 lines

Questions for slab maintainers:

What's going on with the gfp_flags in there? kmem_cache_init_late() passes GFP_NOWAIT into enable_cpucache().

a) why the heck does it do that? It's __init code!

b) if there's a legit reason then your new cache_random_seq_create() should be getting its gfp_t from its caller, rather than blindly assuming GFP_KERNEL.

c) kmem_cache_init_late() goes BUG on ENOMEM. Generally that's OK in __init code: we assume infinite memory during bootup. But it's really quite weird to use GFP_NOWAIT and then to go BUG if GFP_NOWAIT had its predictable outcome (ie: failure).

Finally, all callers of enable_cpucache() (and hence of cache_random_seq_create()) are __init, so we're unnecessarily bloating up vmlinux. Could someone please take a look at this as a separate thing?

Quoted 11 lines
mm/slab.c +8 -0
+     /* Get best entropy at this stage */
+     get_random_bytes_arch(&seed, sizeof(seed));
+     prandom_seed_state(&state, seed);
+
+     freelist_randomize(&state, cachep->random_seq, count);
+     return 0;
+}
+
 
...
#4 lore raw
In reply to Andrew Morton
Quoted 128 lines · Andrew Morton
Quoted 60 lines · On Tue, 26 Apr 2016 09:21:10 -0700 Thomas Garnier <[email protected]> wrote:

Provides an optional config (CONFIG_FREELIST_RANDOM) to randomize the SLAB freelist. The list is randomized during initialization of a new set of pages. The order on different freelist sizes is pre-computed at boot for performance. Each kmem_cache has its own randomized freelist. Before pre-computed lists are available freelists are generated dynamically. This security feature reduces the predictability of the kernel SLAB allocator against heap overflows rendering attacks much less stable.

For example this attack against SLUB (also applicable against SLAB) would be affected:
https://jon.oberheide.org/blog/2010/09/10/linux-kernel-can-slub-overflow/

Also, since v4.6 the freelist was moved at the end of the SLAB. It means a controllable heap is opened to new attacks not yet publicly discussed. A kernel heap overflow can be transformed to multiple use-after-free. This feature makes this type of attack harder too.

To generate entropy, we use get_random_bytes_arch because 0 bits of entropy is available in the boot stage. In the worse case this function will fallback to the get_random_bytes sub API. We also generate a shift random number to shift pre-computed freelist for each new set of pages.

The config option name is not specific to the SLAB as this approach will be extended to other allocators like SLUB.

Performance results highlighted no major changes:

Hackbench (running 90 10 times):

Before average: 0.0698
After average: 0.0663 (-5.01%)

slab_test 1 run on boot. Difference only seen on the 2048 size test being the worse case scenario covered by freelist randomization. New slab pages are constantly being created on the 10000 allocations. Variance should be mainly due to getting new pages every few allocations.

...

include/linux/slab_def.h +4 -0
@@ -80,6 +80,10 @@ struct kmem_cache {
 	struct kasan_cache kasan_info;
 #endif
 
+#ifdef CONFIG_FREELIST_RANDOM
+	void *random_seq;
+#endif
+
 	struct kmem_cache_node *node[MAX_NUMNODES];
 };
 
init/Kconfig +0 -0
index 0c66640..73453d0 100644
@@ -1742,6 +1742,15 @@ config SLOB
 

init/Kconfig config SLOB · line 1752

Quoted 10 lines
init/Kconfig +8 -0
 endchoice
 
+config FREELIST_RANDOM
+	default n
+	depends on SLAB
+	bool "SLAB freelist randomization"
+	help
+	  Randomizes the freelist order used on creating new SLABs. This
+	  security feature reduces the predictability of the kernel slab
+	  allocator against heap overflows.

Against the v2 patch I didst observe:

: CONFIG_FREELIST_RANDOM bugs me a bit - "freelist" is so vague. : CONFIG_SLAB_FREELIST_RANDOM would be better. I mean, what Kconfig : identifier could be used for implementing randomisation in : slub/slob/etc once CONFIG_FREELIST_RANDOM is used up?

but this pearl appeared to pass unnoticed.

Quoted 32 lines
init/Kconfig +0 -0
 config SLUB_CPU_PARTIAL
 	default y
 	depends on SLUB && SMP
mm/slab.c +21 -0
index b82ee6b..0ed728a 100644
@@ -1230,6 +1230,61 @@ static void __init set_up_node(struct kmem_cache *cachep, int index)
 	}
 }
 
+#ifdef CONFIG_FREELIST_RANDOM
+static void freelist_randomize(struct rnd_state *state, freelist_idx_t *list,
+			size_t count)
+{
+	size_t i;
+	unsigned int rand;
+
+	for (i = 0; i < count; i++)
+		list[i] = i;
+
+	/* Fisher-Yates shuffle */
+	for (i = count - 1; i > 0; i--) {
+		rand = prandom_u32_state(state);
+		rand %= (i + 1);
+		swap(list[i], list[rand]);
+	}
+}
+
+/* Create a random sequence per cache */
+static int cache_random_seq_create(struct kmem_cache *cachep)
+{

mm/slab.c static void __init set_up_node(struct kmem_cache *cachep, int index) · line 1263

Quoted 10 lines
mm/slab.c +10 -0
+	unsigned int seed, count = cachep->num;
+	struct rnd_state state;
+
+	if (count < 2)
+		return 0;
+
+	/* If it fails, we will just use the global lists */
+	cachep->random_seq = kcalloc(count, sizeof(freelist_idx_t), GFP_KERNEL);
+	if (!cachep->random_seq)
+		return -ENOMEM;

OK, no BUG. If this happens, kmem_cache_init_late() will go BUG instead ;)

Quoted 6 lines

Questions for slab maintainers:

What's going on with the gfp_flags in there? kmem_cache_init_late() passes GFP_NOWAIT into enable_cpucache().

a) why the heck does it do that? It's __init code!

Until some boot-up point, we should not enable interrupt. In slab subsystem, If we use __GFP_DIRECT_RECLAIM, it will cause to enable interrupt when allocating new slab page. GFP_NOWAIT is to prevent that situation.

Anyway, I audit the code and kmem_cache_init_late() could use __GFP_DIRECT_RECLAIM because it is called after interrupt is enabled which means that that's safe time to manipulate interrupt. (See kmem_cache_init_late() in start_kernel()).

Quoted 4 lines

b) if there's a legit reason then your new cache_random_seq_create() should be getting its gfp_t from its caller, rather than blindly assuming GFP_KERNEL.

In any case, ignoring provided gfp argument isn't good practice.

Quoted 4 lines

c) kmem_cache_init_late() goes BUG on ENOMEM. Generally that's OK in __init code: we assume infinite memory during bootup. But it's really quite weird to use GFP_NOWAIT and then to go BUG if GFP_NOWAIT had its predictable outcome (ie: failure).

I don't think BUG() here is weird code. It just means that if we can't initialize slab subsystem properly, machine cannot run properly so BUG().

Quoted 4 lines

Finally, all callers of enable_cpucache() (and hence of cache_random_seq_create()) are __init, so we're unnecessarily bloating up vmlinux. Could someone please take a look at this as a separate thing?

That's not true. It is called whenever new kmem_cache is created. I don't know concrete reason why setup_cpu_cache() is defined with __init_refok tag but looks like it needs to be fixed.

I will look at it soon.

Thanks.

#5 lore raw
In reply to Andrew Morton
Quoted 6 lines · Andrew Morton

: CONFIG_FREELIST_RANDOM bugs me a bit - "freelist" is so vague. : CONFIG_SLAB_FREELIST_RANDOM would be better. I mean, what Kconfig : identifier could be used for implementing randomisation in : slub/slob/etc once CONFIG_FREELIST_RANDOM is used up?

but this pearl appeared to pass unnoticed.

Ok. lets add SLAB here and then use this option for the other allocators as well.

Quoted 8 lines

mm/slab.c static void __init set_up_node(struct kmem_cache *cachep, int index) · line 1263

Quoted 4 lines
mm/slab.c +4 -0
+	/* If it fails, we will just use the global lists */
+	cachep->random_seq = kcalloc(count, sizeof(freelist_idx_t), GFP_KERNEL);
+	if (!cachep->random_seq)
+		return -ENOMEM;

OK, no BUG. If this happens, kmem_cache_init_late() will go BUG instead ;)

Quoted 6 lines

Questions for slab maintainers:

What's going on with the gfp_flags in there? kmem_cache_init_late() passes GFP_NOWAIT into enable_cpucache().

a) why the heck does it do that? It's __init code!

enable_cpucache() was called when a slab cache was reconfigured by writing to /proc/slabinfo. That was changed awhile back when the memcg changes were made ot slab. So
now its ok to be made init code.

Quoted 4 lines

Finally, all callers of enable_cpucache() (and hence of cache_random_seq_create()) are __init, so we're unnecessarily bloating up vmlinux. Could someone please take a look at this as a separate thing?

Hmmm. Well if that is the case then lots of stuff could be straightened out. Joonsoo?

#3 lore raw
In reply to Thomas Garnier
Quoted 4 lines · Thomas Garnier

It was discussed a bit before. The intent is to have a similar feature for other kernel heap (I know it is possible for SLUB). That's why I think it make sense to have a similar config name used for all allocators.

Please use CONFIG_SLAB_FREELIST_RANDOM to signify that it is for all slab allocators. Not SLAB specific.

#6 lore raw
In reply to Christoph Lameter
Quoted 31 lines · Christoph Lameter
Quoted 6 lines · Andrew Morton

: CONFIG_FREELIST_RANDOM bugs me a bit - "freelist" is so vague. : CONFIG_SLAB_FREELIST_RANDOM would be better. I mean, what Kconfig : identifier could be used for implementing randomisation in : slub/slob/etc once CONFIG_FREELIST_RANDOM is used up?

but this pearl appeared to pass unnoticed.

Ok. lets add SLAB here and then use this option for the other allocators as well.

Quoted 8 lines

mm/slab.c static void __init set_up_node(struct kmem_cache *cachep, int index) · line 1263

Quoted 4 lines
mm/slab.c +4 -0
+	/* If it fails, we will just use the global lists */
+	cachep->random_seq = kcalloc(count, sizeof(freelist_idx_t), GFP_KERNEL);
+	if (!cachep->random_seq)
+		return -ENOMEM;

OK, no BUG. If this happens, kmem_cache_init_late() will go BUG instead ;)

Quoted 6 lines

Questions for slab maintainers:

What's going on with the gfp_flags in there? kmem_cache_init_late() passes GFP_NOWAIT into enable_cpucache().

a) why the heck does it do that? It's __init code!

enable_cpucache() was called when a slab cache was reconfigured by writing to /proc/slabinfo. That was changed awhile back when the memcg changes were made ot slab. So
now its ok to be made init code.

Quoted 8 lines
Quoted 4 lines

Finally, all callers of enable_cpucache() (and hence of cache_random_seq_create()) are __init, so we're unnecessarily bloating up vmlinux. Could someone please take a look at this as a separate thing?

Hmmm. Well if that is the case then lots of stuff could be straightened out. Joonsoo?

As I mentioned in other thread, enable_cpucache() can be called whenever kmem_cache is created. It should not be __init.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>