From nobody Sun Feb 8 14:22:42 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4B7D1D8E12 for ; Fri, 17 Jan 2025 11:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737113556; cv=none; b=NvjmKJRmJ9TkIwavzMX/PUDSRhfj4r6ZZjNeCWDwM0v4T9ffg4eqtXAPZYElWdalz9pXBVVrBAE20RKq3vQUZSmthuBKj3EIxW97442mEum9ro/OjEJU6k6MU32CBoVUFehf8205EK+2LasRdFyhf9ytjSEHEuSUN+/XmjiRFm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737113556; c=relaxed/simple; bh=gnCCSby9I37MxcMT4KjihB1LZFXwvezelwdsZT0EVOM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WHF/zXYyg3URBs1FC19T+vBu8Yu53lZrTErhABTP9HE/PE5wvOvQJ01gZyMsOlIP1nxbp6fagEqqAFC8BG8HyxrQeTcjBRMHgFw2DX9Ehg8n+TimoHIXoKcfCtvMG5DIYsTrNSDwYJlXwmCzuki1RO+n8H+M7v/GvpMwUm+qhCI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 059F81476; Fri, 17 Jan 2025 03:33:01 -0800 (PST) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F1BF73F73F; Fri, 17 Jan 2025 03:32:30 -0800 (PST) From: Kevin Brodsky To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH] mm/slab: simplify SLAB_* flag handling Date: Fri, 17 Jan 2025 11:32:26 +0000 Message-ID: <20250117113226.3484784-1-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SLUB is the only remaining allocator. We can therefore get rid of the logic for allocator-specific flags: * Merge SLAB_CACHE_FLAGS into SLAB_CORE_FLAGS. * Remove SLAB_FLAGS_PERMITTED (effectively the same as CACHE_CREATE_MASK aside from debug flags being unconditionally included). While at it also remove misleading comments that suggest that multiple allocators are available. Signed-off-by: Kevin Brodsky --- Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Andrew Morton Cc: Vlastimil Babka Cc: Roman Gushchin Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slab.h | 28 +++++----------------------- mm/slab_common.c | 12 ------------ 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/mm/slab.h b/mm/slab.h index 632fedd71fea..392f4763dee8 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -457,10 +457,12 @@ static inline bool is_kmalloc_normal(struct kmem_cach= e *s) return !(s->flags & (SLAB_CACHE_DMA|SLAB_ACCOUNT|SLAB_RECLAIM_ACCOUNT)); } =20 -/* Legal flag mask for kmem_cache_create(), for various configurations */ #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_PANIC | \ - SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS ) + SLAB_TYPESAFE_BY_RCU | SLAB_DEBUG_OBJECTS | \ + SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \ + SLAB_TEMPORARY | SLAB_ACCOUNT | \ + SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE) =20 #ifdef CONFIG_SLUB_DEBUG #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ @@ -469,27 +471,7 @@ static inline bool is_kmalloc_normal(struct kmem_cache= *s) #define SLAB_DEBUG_FLAGS (0) #endif =20 -#define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \ - SLAB_TEMPORARY | SLAB_ACCOUNT | \ - SLAB_NO_USER_FLAGS | SLAB_KMALLOC | SLAB_NO_MERGE) - -/* Common flags available with current configuration */ -#define CACHE_CREATE_MASK (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS | SLAB_CACHE= _FLAGS) - -/* Common flags permitted for kmem_cache_create */ -#define SLAB_FLAGS_PERMITTED (SLAB_CORE_FLAGS | \ - SLAB_RED_ZONE | \ - SLAB_POISON | \ - SLAB_STORE_USER | \ - SLAB_TRACE | \ - SLAB_CONSISTENCY_CHECKS | \ - SLAB_NOLEAKTRACE | \ - SLAB_RECLAIM_ACCOUNT | \ - SLAB_TEMPORARY | \ - SLAB_ACCOUNT | \ - SLAB_KMALLOC | \ - SLAB_NO_MERGE | \ - SLAB_NO_USER_FLAGS) +#define CACHE_CREATE_MASK (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS) =20 bool __kmem_cache_empty(struct kmem_cache *); int __kmem_cache_shutdown(struct kmem_cache *); diff --git a/mm/slab_common.c b/mm/slab_common.c index a29457bef626..3b07cdaac3ae 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -305,18 +305,6 @@ struct kmem_cache *__kmem_cache_create_args(const char= *name, goto out_unlock; } =20 - /* Refuse requests with allocator specific flags */ - if (flags & ~SLAB_FLAGS_PERMITTED) { - err =3D -EINVAL; - goto out_unlock; - } - - /* - * Some allocators will constraint the set of valid flags to a subset - * of all flags. We expect them to define CACHE_CREATE_MASK in this - * case, and we'll just provide them with a sanitized version of the - * passed flags. - */ flags &=3D CACHE_CREATE_MASK; =20 /* Fail closed on bad usersize of useroffset values. */ base-commit: 9bffa1ad25b8b3b95d8f463e5c24dabe3c87d54d --=20 2.47.0