From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B3E7C531C7 for ; Thu, 23 Jul 2026 09:57:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22B226B00DE; Thu, 23 Jul 2026 05:57:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2026E6B0166; Thu, 23 Jul 2026 05:57:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13FFE6B0167; Thu, 23 Jul 2026 05:57:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D41F96B00DE for ; Thu, 23 Jul 2026 05:57:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1DF1A1A0431 for ; Thu, 23 Jul 2026 09:57:09 +0000 (UTC) X-FDA: 85019588178.27.29C16BB Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by imf08.hostedemail.com (Postfix) with ESMTP id 9E846160006 for ; Thu, 23 Jul 2026 09:57:05 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gNalcYo6; spf=pass (imf08.hostedemail.com: domain of hao.li@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=hao.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1784800627; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n5Va5xqbBf3fhekckmlcg2X0hrc0i9E9Xp9SI7nV9WM=; b=4YBcyqNmBEgvzXSFqkTZdw3TDq2sxwAdx+lWNlyY3HZlYMXW2nU96HaafVYpKQE9l98FnF tEQMlkCW4d+OP/BJckm6i0MewERMbuQl/12bdfQcOIKeO/foUtpRJZ3jv6XGu88wcEtd7C p6hlCiyuEM8zCz4hGb4SiGO016tFFbo= ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1784800627; b=4oSF1FHZZ1CkN5jd5wf/DMaDrTyPaFHcF6gNj2ntGQG/MxIuFgdqZfb9bBX0x9FxGn7p6n 0XF2A91p86z2HwoEQtPy1JL5qCJnxIj8nlK9x4Xtz9T5XQYbXU5xbQzcqORKOw45U+gQdH bYFhkZ5QlCG9QMKsrUG1x0pQ3koQ8zc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gNalcYo6; spf=pass (imf08.hostedemail.com: domain of hao.li@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=hao.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Thu, 23 Jul 2026 17:56:56 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784800623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n5Va5xqbBf3fhekckmlcg2X0hrc0i9E9Xp9SI7nV9WM=; b=gNalcYo6YMM9tSoRfU0ofQa40+wtblPqWAaxiKhOjK7x0Iw5UmBpQIa+Ye7cxVkj0Uy1AY K8HBT+TUYv/ZuBNMD5oqNdRNgzbaPIpIpKgviQ+8wsbpbRtPTAbkQNVb6QPRn19tNCTtLx TkfB7nEHflrI0sX2dTbbcAKderUB5iU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Li To: Harry Yoo Cc: "Vlastimil Babka (SUSE)" , Suren Baghdasaryan , Shakeel Butt , Alexander Potapenko , Marco Elver , Andrew Morton , Christoph Lameter , David Rientjes , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Subject: Re: [PATCH v2 09/13] mm/slab: change struct slabobj_ext to a union Message-ID: References: <20260720-b4-objext_split-v2-0-2fa7c6f60dbe@kernel.org> <20260720-b4-objext_split-v2-9-2fa7c6f60dbe@kernel.org> <9b2dadb7-8e3d-4b9b-a870-969be9a7a432@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9b2dadb7-8e3d-4b9b-a870-969be9a7a432@kernel.org> X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9E846160006 X-Stat-Signature: jsjk65d6srffoaypy1pw3xqrdq3p5d51 X-Rspam-User: X-HE-Tag: 1784800625-49407 X-HE-Meta: U2FsdGVkX1/m9xfUtPO7LXGPhrj4rta0ZGNA2o9m83TS1AIZ+9lhuLoC6u4thD33MgsoTflOCmVl4aoGPrmshEvgrYaOv65CJ6t2ZNQBZhveRxltpPPI6XZ1E5Pue973gVFTLfii85Xgh5A6jMYrfNf1kG2FBgJyareFAdixpBhQi/kRxIwBE3ai0sbDI4OPkg83YX3DeODbLBu0QOEerwRA3wZ4YHgMfnp8/BdnCfioJZq3n1iEVYA2k52MZ9V22D2Kyw20CE34eoZkDL3K20Msg76qrlq3NLnys4ernAB5nNGy0UHkM/uzyHgI67xtkYgHidRNeRSAQOzp27GggU2ADUeNVEYPs0pl/V1sI+IkqdU+Bl9lxdcXaJYFakcWdtBNGrvZAtQWQCLg2f9O4O5XQ5t8JCOznwrtd0GSQyQHNekZcXVb1fAKCSSvp2mKFYLiQpjWlAgocIu6WlDvwfOab8k0esjdN/M495E2Kvs+XzaflyM73oqoaYtuUIGdunx/HmotsNlPNW6s2jm9TOn9QVQ8zCnsfjJ4kdvzyMtoDd8s4MDy84+Ba8SIdqwR0VKqvVKlu6+99X2XUioLJSYL5C/OaureamKDrBcmMl4dkJeKKLzYA/RWi/FCbUDz8CeLNyHBDOXSksOnCm37ZLsbW61+sXBAOvSH6to92WupZDT8u4vznDU1vvxI0S2twjyG7m9d89fuvV8y+oyE04+BKj3J6nuox83aEmUHwx29Zz3vG2olquoVXyp6SnS0JbR9isFhBLvrXsdTOCNJz77LHE+3Ta65C6WzJQxsvL7Pv2NxtbpGkG9BbuBsaAhBGlrle5yPZM4vgrL8AG2xnXrLIiBsueJNDKQbUkeBDMiIuyL/hrmlWzwOQL6O/AItI2MCuaNAF0bCkrhnMXUCmoikn6AwKjsDDIFiglM7Rx+G0shd4NrVvdsYE3+yb1ZPUVqv293m18brJAJLtPA DCCKBN6C 2QhEJatxpL1hN/7ggsFGsud+DJgR0iRD6g7auR063YZLLh6DCm/MStz1FawmGo9vNC3nV2wYen3PC337U+2jkUdP2j9Wg7+CmaJmpPJ3U2Zz0btscRCXW8VDOpDzlDnVzpsJWEVjngbdvyatLV9/J8FhSHG4pvx+H9lYVOe1696+Axd98ONU1QxBUSYLD9dy5uVCW8lFGNyr2QsctK5hak6sX5dXuJ1FM5BN+BfRkuiCgO3cBe2kK+afsHtipX/0tVJTV9PgCCzb3HdTUIHGcxWIW+oYS+l+ThExr3FWT9Co0y8E= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jul 23, 2026 at 03:27:51PM +0900, Harry Yoo wrote: > > > On 7/23/26 12:05 PM, Hao Li wrote: > > On Mon, Jul 20, 2026 at 04:16:23PM +0200, Vlastimil Babka (SUSE) wrote: > >> Currently, struct slabobj_ext can hold both objcg pointer and > >> codetag_ref (when both are compile-enabled) and there is an array of as > >> many slabobj_ext instances as there are objects in a slab. > >> > >> This makes the layout fixed so even if codetag_ref is unused (because > >> memory allocation profiling is disabled), the space for them is > >> allocated and wasted. Similarly, some caches (currently kmalloc_normal) > >> do not ever need objcg pointers, leading to wasted memory with memory > >> allocation profiling enabled. > >> > >> To make this more flexible, change the layout so that struct slabobj_ext > >> becomes a union of objcg pointer and codetag_ref (to ensure uniform > >> size; in practice both are the same size anyway). The slabobj_ext array > >> then can have twice as many elements as before. For cache locality > >> purposes, the effective memory layout is unchanged, so objcg and codetag > >> ref for a given object are still adjacent. > >> > >> cache_obj_ext_size() returns the effective size of (0-2) struct > >> slabobj_ext's for a cache, slab_obj_ext_size() for a slab. Currently > >> both return a constant value derived from the config options, but will > >> be made dynamic later. Replace all sizeof(slabobj_ext) usage with these. > >> > >> No functional change intended, the layout is still effectively static. > >> > >> Reviewed-by: Suren Baghdasaryan > >> Signed-off-by: Vlastimil Babka (SUSE) > >> --- > >> mm/slab.h | 49 +++++++++++++++++++++++++++++++++++++++---------- > >> mm/slub.c | 19 +++++++++++-------- > >> 2 files changed, 50 insertions(+), 18 deletions(-) > >> > >> diff --git a/mm/slab.h b/mm/slab.h > >> index e586798e4f16..f8446167e175 100644 > >> --- a/mm/slab.h > >> +++ b/mm/slab.h > >> @@ -550,18 +550,42 @@ static inline bool need_kmalloc_no_objext(void) > >> } > >> > >> /* > >> - * Extended information for slab objects stored as an array in page->memcg_data > >> - * if MEMCG_DATA_OBJEXTS is set. > >> + * Extended information for slab objects stored as a pointer to an array in > >> + * slab->obj_exts (aliasing page->memcg_data) if MEMCG_DATA_OBJEXTS is set. > >> */ > >> struct slabobj_ext { > >> + /* > >> + * All elements of the union should be pointer-sized to avoid memory > >> + * waste > >> + */ > >> + union { > >> #ifdef CONFIG_MEMCG > >> - struct obj_cgroup *_objcg; > >> + struct obj_cgroup *_objcg; > >> #endif > >> #ifdef CONFIG_MEM_ALLOC_PROFILING > >> - union codetag_ref _ctref; > >> + union codetag_ref _ctref; > >> #endif > >> + }; > >> } __aligned(8); > > > > slabobj_ext is now acting as a generic struct, serving as either _objcg or > > _ctref. However, because it's set to __aligned(8), I'm wondering if this might > > waste half the memory on 32-bit? > > We could loosen the alignment to > max(__NR_OBJEXTS_FLAGS, alignof(void *)) > > and drop OBJEXT_FLAG_UNUSED. Yes, this idea is insightful and I think it may need a standalone patch without blocking current patchset. > > ...not sure how much we care about this on 32bit though. Yeah, 32bit is a rare arch today :) -- Thanks, Hao