Skip to contentSkip to conversation

clean-up for create_kmalloc_caches()

PATCH Applied Hyunmin Lee 5 participants 8 messages Apr 24, 2024 – May 2, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover clean-up for create_kmalloc_caches()

Hi pals,

I am cleanning up unnecessary code in create_kmalloc_caches(). I added one more commit to remove the check for NULL kmalloc_cachee according to the review comments like below.

- David Rientjes suggested moving the check for NULL kmalloc_caches to new_kmalloc_cache().
- Christoph Lameter suggested skipping the check for the kmalloc caches already being present.

Thanks,
Hyunmin

Hyunmin Lee (2):
mm/slub: create kmalloc 96 and 192 caches regardless cache size order mm/slub: remove the check for NULL kmalloc_caches

 mm/slab_common.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/2 mm/slub: create kmalloc 96 and 192 caches regardless cache size order

For SLAB the kmalloc caches needed to be created in ascending sizes in order. However, the constraint is not necessary anymore because SLAB has been removed and SLUB doesn't need to comply with the constraint. Thus, kmalloc 96 and 192 caches can be created after the other size kmalloc caches are created instead of checking every time to find their order to be created. Also, this change could prevent engineers from being confused by the removed constraint.

---
 mm/slab_common.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
mm/slab_common.c +7 -12
index 3179a6aeffc5..ed7b8592b62c 100644
@@ -916,21 +916,16 @@ void __init create_kmalloc_caches(void)
 	 * Including KMALLOC_CGROUP if CONFIG_MEMCG_KMEM defined
 	 */
 	for (type = KMALLOC_NORMAL; type < NR_KMALLOC_TYPES; type++) {
+		/* Caches that are NOT of the two-to-the-power-of size. */
+		if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[type][1])
+			new_kmalloc_cache(1, type);
+		if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[type][2])
+			new_kmalloc_cache(2, type);
+
+		/* Caches that are of the two-to-the-power-of size. */
 		for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
 			if (!kmalloc_caches[type][i])
 				new_kmalloc_cache(i, type);
-
-			/*
-			 * Caches that are not of the two-to-the-power-of size.
-			 * These have to be created immediately after the
-			 * earlier power of two caches
-			 */
-			if (KMALLOC_MIN_SIZE <= 32 && i == 6 &&
-					!kmalloc_caches[type][1])
-				new_kmalloc_cache(1, type);
-			if (KMALLOC_MIN_SIZE <= 64 && i == 7 &&
-					!kmalloc_caches[type][2])
-				new_kmalloc_cache(2, type);
 		}
 	}
 #ifdef CONFIG_RANDOM_KMALLOC_CACHES
Signature · 1 line
2.34.1
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] mm/slub: create kmalloc 96 and 192 caches regardless cache size order

Quoted 7 lines · Hyunmin Lee

For SLAB the kmalloc caches needed to be created in ascending sizes in order. However, the constraint is not necessary anymore because SLAB has been removed and SLUB doesn't need to comply with the constraint. Thus, kmalloc 96 and 192 caches can be created after the other size kmalloc caches are created instead of checking every time to find their order to be created. Also, this change could prevent engineers from being confused by the removed constraint.

reviewer Acked-by on v3 1/2
#3 lore raw

Re: [PATCH v3 1/2] mm/slub: create kmalloc 96 and 192 caches regardless cache size order

In reply to Hyunmin Lee
Quoted 8 lines · Hyunmin Lee

For SLAB the kmalloc caches needed to be created in ascending sizes in order. However, the constraint is not necessary anymore because SLAB has been removed and SLUB doesn't need to comply with the constraint. Thus, kmalloc 96 and 192 caches can be created after the other size kmalloc caches are created instead of checking every time to find their order to be created. Also, this change could prevent engineers from being confused by the removed constraint.

Quoted 7 lines
#4 lore raw

PATCH v3 2/2 mm/slub: remove the check for NULL kmalloc_caches

In reply to Hyunmin Lee

If the same size kmalloc cache already exists, it should not be created again. So there is the check for NULL kmalloc_caches before calling the kmalloc creation function. However, new_kmalloc_cache() itself checks NULL kmalloc_cahces before cache creation. Therefore, the NULL check is not necessary in this function.

---
 mm/slab_common.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
mm/slab_common.c +4 -6
index ed7b8592b62c..0f2675f421e9 100644
@@ -917,16 +917,14 @@ void __init create_kmalloc_caches(void)
 	 */
 	for (type = KMALLOC_NORMAL; type < NR_KMALLOC_TYPES; type++) {
 		/* Caches that are NOT of the two-to-the-power-of size. */
-		if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[type][1])
+		if (KMALLOC_MIN_SIZE <= 32)
 			new_kmalloc_cache(1, type);
-		if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[type][2])
+		if (KMALLOC_MIN_SIZE <= 64)
 			new_kmalloc_cache(2, type);
 
 		/* Caches that are of the two-to-the-power-of size. */
-		for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
-			if (!kmalloc_caches[type][i])
-				new_kmalloc_cache(i, type);
-		}
+		for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++)
+			new_kmalloc_cache(i, type);
 	}
 #ifdef CONFIG_RANDOM_KMALLOC_CACHES
 	random_kmalloc_seed = get_random_u64();
Signature · 1 line
2.34.1
reviewer Reviewed-by Christoph Lameter on v3 2/2
#5 lore raw

Re: [PATCH v3 2/2] mm/slub: remove the check for NULL kmalloc_caches

Quoted 5 lines · Hyunmin Lee

If the same size kmalloc cache already exists, it should not be created again. So there is the check for NULL kmalloc_caches before calling the kmalloc creation function. However, new_kmalloc_cache() itself checks NULL kmalloc_cahces before cache creation. Therefore, the NULL check is not necessary in this function.

reviewer Acked-by on v3 2/2
#6 lore raw

Re: [PATCH v3 2/2] mm/slub: remove the check for NULL kmalloc_caches

In reply to Hyunmin Lee
Quoted 6 lines · Hyunmin Lee

If the same size kmalloc cache already exists, it should not be created again. So there is the check for NULL kmalloc_caches before calling the kmalloc creation function. However, new_kmalloc_cache() itself checks NULL kmalloc_cahces before cache creation. Therefore, the NULL check is not necessary in this function.

Quoted 7 lines
#7 lore raw
In reply to Hyunmin Lee
Quoted 6 lines · Hyunmin Lee

Hi pals,

I am cleanning up unnecessary code in create_kmalloc_caches(). I added one more commit to remove the check for NULL kmalloc_cachee according to the review comments like below.

Quoted 7 lines

- David Rientjes suggested moving the check for NULL kmalloc_caches to new_kmalloc_cache().
- Christoph Lameter suggested skipping the check for the kmalloc caches already being present.

Thanks,
Hyunmin

Thanks, applied to slab/for-6.10

Quoted 7 lines

Hyunmin Lee (2):
mm/slub: create kmalloc 96 and 192 caches regardless cache size order mm/slub: remove the check for NULL kmalloc_caches

 mm/slab_common.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)