mm/slab_common: use SLAB_NO_MERGE instead of negative refcount
authorVlastimil Babka <vbabka@suse.cz>
Tue, 13 Jun 2023 10:28:21 +0000 (12:28 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Fri, 16 Jun 2023 09:04:29 +0000 (11:04 +0200)
When CONFIG_MEMCG_KMEM is enabled, we disable cache merging for
KMALLOC_NORMAL caches so they don't end up merged with a cache that uses
ad-hoc __GFP_ACCOUNT when allocating. This was implemented by setting
the refcount to -1, but now we have a proper SLAB_NO_MERGE flag, so use
that instead.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: David Rientjes <rientjes@google.com>
mm/slab_common.c

index 0e0a617eae7d33fda7a0787b1a2d23d244ecf45e..67caf0bc31943d6f91d2ae562e7902f936424c14 100644 (file)
@@ -878,17 +878,17 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags)
                flags |= SLAB_CACHE_DMA;
        }
 
-       kmalloc_caches[type][idx] = create_kmalloc_cache(
-                                       kmalloc_info[idx].name[type],
-                                       kmalloc_info[idx].size, flags, 0,
-                                       kmalloc_info[idx].size);
-
        /*
         * If CONFIG_MEMCG_KMEM is enabled, disable cache merging for
         * KMALLOC_NORMAL caches.
         */
        if (IS_ENABLED(CONFIG_MEMCG_KMEM) && (type == KMALLOC_NORMAL))
-               kmalloc_caches[type][idx]->refcount = -1;
+               flags |= SLAB_NO_MERGE;
+
+       kmalloc_caches[type][idx] = create_kmalloc_cache(
+                                       kmalloc_info[idx].name[type],
+                                       kmalloc_info[idx].size, flags, 0,
+                                       kmalloc_info[idx].size);
 }
 
 /*