From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC2A51A682A for ; Fri, 19 Jun 2026 08:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781856593; cv=none; b=Lh1DU0/s1BNSnvyxsOXr74UEgpnyX/zA9iTyFIq66TG39x/zyyvRyhWB7lZNWvTBTrk/6ziFXCMbMMPJcDqSBOP0XQKSC5D7zTRuy0oNkFol+N787XrJHycXPwOyoTdVSV14PZk5UT8/Rll4zEW9ak0mrF0mQv07dnWXh7NCmQk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781856593; c=relaxed/simple; bh=VzN3aiIJnO1SF+1z1SCntPVB3dMgLgoDdhCbYJaMY4E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tOrwUQ3ENsBgbvZbEu6LK1HIVFSfpP0yfFzvSFf4c86Bb4Ov+e6eyWpVHoOl7iWMdfjfyVublMYrL2oKdEYD9GyGHAr4EzO6e+1T7o84lVg5Qpd5wB+udnSrzThvjbVKcwUMm1f4zcxJ8h37PmTotxTrOKkv95PvLIEyPeG/EPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XpFYsiGQ; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XpFYsiGQ" Date: Fri, 19 Jun 2026 16:09:35 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781856589; 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=yVvrfHdKVlkWU88SLenudF1VwsMgMs2vGchEywPlSls=; b=XpFYsiGQv2pL5zw6fLTyYK00qQzKYChVCUvwpw8EmY7yk9ZZWVfUWrvCpDK5syPLL/nhR9 cSfllERlD584EVpnpU4p6RPrtDFFmSZpbqmdgK0ISmXykmeQGb35Mo5C4ZxtGSQ8bGMZ28 hmFY3IaRnCY3sdPC7V8GioGl7xo8et4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Li To: Harry Yoo Cc: vbabka@kernel.org, akpm@linux-foundation.org, cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/slub: deduplicate NUMA policy calculation in allocation paths Message-ID: References: <20260618100913.346636-1-hao.li@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Fri, Jun 19, 2026 at 02:50:04PM +0900, Harry Yoo wrote: > > > On 6/18/26 7:08 PM, Hao Li wrote: > > Currently, alloc_from_pcs() and __slab_alloc_node() both calculate the > > NUMA policy independently. Since they are called consecutively in paths > > like __kmalloc_nolock_noprof() and slab_alloc_node(), this leads to > > redundant computations. > > It uses a static key, so probably just slightly larger code when disabled. Yeah, make sense. The performance impact in this case should be negligible. > > By inlining both __slab_alloc_node and alloc_from_pcs(), I assume the > compiler would have deduplicated it, but there is a patch in > slab/for-next that makes it not inlined anymore :) Thanks, I hadn't thought about it from that angle before, and that's a interesting point. Building on that, I thought about it a bit more. While in theory the compiler might be able to help us here, some of the information inside mempolicy_slab_node() seems only could be determined at runtime. So I suspect the compiler might not be able to infer that the two code blocks are equivalent and deduplicate it. > > > Introduce a helper function to resolve the NUMA policy once, eliminating > > the duplicated code and reducing execution overhead. > > Nice! I think there's no reason why we shouldn't do this. Thanks! > > > Signed-off-by: Hao Li > > --- > > mm/slub.c | 72 ++++++++++++++++++++++--------------------------------- > > 1 file changed, 29 insertions(+), 43 deletions(-) > > > > diff --git a/mm/slub.c b/mm/slub.c > > index 62e9cd46916f..45e9f379b7da 100644 > > --- a/mm/slub.c > > +++ b/mm/slub.c > > @@ -4523,32 +4523,36 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, > > return object; > > } > > > > +static __always_inline int apply_numa_policy(int node) > > apply_numa_policy() is bit confusing because we usually don't apply > mempolicy for each object (unless strict_numa is set), but rather when > grabbing new slabs. Yes, this make sense. it's only for strict numa mode. > > perhaps apply_strict_numa[_policy]() will be a better name? Agree, apply_strict_numa_policy is indeed a better name! -- Thanks, Hao