Skip to content

Commit 3364778

Browse files
owen-kwontehcaster
authored andcommitted
mm/slab_common: move dma-kmalloc caches creation into new_kmalloc_cache()
There are four types of kmalloc_caches: KMALLOC_NORMAL, KMALLOC_CGROUP, KMALLOC_RECLAIM, and KMALLOC_DMA. While the first three types are created using new_kmalloc_cache(), KMALLOC_DMA caches are created in a separate logic. Let KMALLOC_DMA caches be also created using new_kmalloc_cache(), to enhance readability. Historically, there were only KMALLOC_NORMAL caches and KMALLOC_DMA caches in the first place, and they were initialized in two separate logics. However, when KMALLOC_RECLAIM was introduced in v4.20 via commit 1291523 ("mm, slab/slub: introduce kmalloc-reclaimable caches") and KMALLOC_CGROUP was introduced in v5.14 via commit 494c1df ("mm: memcg/slab: create a new set of kmalloc-cg-<n> caches"), their creations were merged with KMALLOC_NORMAL's only. KMALLOC_DMA creation logic should be merged with them, too. By merging KMALLOC_DMA initialization with other types, the following two changes might occur: 1. The order dma-kmalloc-<n> caches added in slab_cache list may be sorted by size. i.e. the order they appear in /proc/slabinfo may change as well. 2. slab_state will be set to UP after KMALLOC_DMA is created. In case of slub, freelist randomization is dependent on slab_state>=UP, and therefore KMALLOC_DMA cache's freelist will not be randomized in creation, but will be deferred to init_freelist_randomization(). Co-developed-by: JaeSang Yoo <[email protected]> Signed-off-by: JaeSang Yoo <[email protected]> Signed-off-by: Ohhoon Kwon <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Acked-by: David Rientjes <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3123109 commit 3364778

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

mm/slab_common.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,8 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags)
849849
return;
850850
}
851851
flags |= SLAB_ACCOUNT;
852+
} else if (IS_ENABLED(CONFIG_ZONE_DMA) && (type == KMALLOC_DMA)) {
853+
flags |= SLAB_CACHE_DMA;
852854
}
853855

854856
kmalloc_caches[type][idx] = create_kmalloc_cache(
@@ -877,7 +879,7 @@ void __init create_kmalloc_caches(slab_flags_t flags)
877879
/*
878880
* Including KMALLOC_CGROUP if CONFIG_MEMCG_KMEM defined
879881
*/
880-
for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) {
882+
for (type = KMALLOC_NORMAL; type < NR_KMALLOC_TYPES; type++) {
881883
for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
882884
if (!kmalloc_caches[type][i])
883885
new_kmalloc_cache(i, type, flags);
@@ -898,20 +900,6 @@ void __init create_kmalloc_caches(slab_flags_t flags)
898900

899901
/* Kmalloc array is now usable */
900902
slab_state = UP;
901-
902-
#ifdef CONFIG_ZONE_DMA
903-
for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
904-
struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
905-
906-
if (s) {
907-
kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(
908-
kmalloc_info[i].name[KMALLOC_DMA],
909-
kmalloc_info[i].size,
910-
SLAB_CACHE_DMA | flags, 0,
911-
kmalloc_info[i].size);
912-
}
913-
}
914-
#endif
915903
}
916904
#endif /* !CONFIG_SLOB */
917905

0 commit comments

Comments
 (0)