Skip to contentSkip to conversation

mm/slub: create kmalloc 96 and 192 caches regardless cache size order

PATCH Superseded Hyunmin Lee 1 participant 1 message Apr 22, 2024

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---

David Rientjes suggested moving the check for NULL kmalloc_caches to new_kmalloc_cache(). It looks like a good idea. So there will be another patch for it.

 mm/slab_common.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
mm/slab_common.c +6 -12
index 3179a6aeffc5..1c2aee01a799 100644
@@ -919,19 +919,13 @@ void __init create_kmalloc_caches(void)
 		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);
 		}
+
+		/* 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);
 	}
 #ifdef CONFIG_RANDOM_KMALLOC_CACHES
 	random_kmalloc_seed = get_random_u64();
Signature · 1 line
2.34.1