From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.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 D868E279907 for ; Wed, 27 May 2026 06:09:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779862150; cv=none; b=hvNNivv7xHIuQjkniwF9g94RTmNpfWTgVogC7qebLmimYW1M1MFb0BUx4ze5gKdPcF3P+FRkkiFf6+p+Uxk6wvGAPBgEaFjHU1pLS3ODcYEhrnOBDjxFSTVeT8kRtIjjrbJXxKy5tsctuc9m7kvpy8eQAPgVaydJ1vxT0Dw+ZOE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779862150; c=relaxed/simple; bh=tK2IQgErRvlmeS/MCYL3KCFRvcF/KDq+zgf0iArkUaU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fLQFWFptINAdNSycmd26Zc+I/ZWEHfsOdcS4bKwBpMQDX++M4xidqzv5dWg5Ch8dy1f06fF5hf0QMqf9PRLxkb3gCkTvV/CPU+wgdSC/WoNwKTA3PQrW3WI30P34x1qzJbigKN3hRHsmRVdLx+TrDtXQB91HY4aLdDdoXBQivyM= 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=bjoTrTst; arc=none smtp.client-ip=95.215.58.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="bjoTrTst" Date: Wed, 27 May 2026 14:08:34 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779862146; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R9ewrIz+SyMPsubDHWfrfvKm49lh08EEH8A/DxxOjuQ=; b=bjoTrTstgSAFpYNDYakxqudYv7fkxNsj20YqYlt/l3g8PG8mMzS3vmdnqGi9Oa2JhH2vrz fUSI9lkShp7h114JwjbSgyqdT98eoAW63R7A8no0pjzrWn7zGuJc7z/X4A+aH0+9zmFvLG EuW7v1pN+USZOWm3EmmyiBcanykQ6xc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Li To: "Vlastimil Babka (SUSE)" , Harry Yoo Cc: 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: batch-detach node partial slabs Message-ID: References: <20260525032233.10847-1-hao.li@linux.dev> <3bfbb8cd-6291-43e8-9f0e-b8b0b3c568d1@kernel.org> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3bfbb8cd-6291-43e8-9f0e-b8b0b3c568d1@kernel.org> X-Migadu-Flow: FLOW_OUT On Tue, May 26, 2026 at 03:41:55PM +0200, Vlastimil Babka (SUSE) wrote: > On 5/26/26 9:37 AM, Harry Yoo wrote: > > > > > > On 5/25/26 12:22 PM, Hao Li wrote: > >> get_partial_node_bulk() used to move each selected slab from the node > >> partial list to the local pc->slabs list using a remove_partial() and > >> list_add() pair. In practice, the loop often detaches several adjacent > >> slabs, so this repeatedly manipulates list pointers while holding > >> n->list_lock, which causes unnecessary churn. > >> > >> Instead, track contiguous runs of matching slabs and move each run with > >> list_bulk_move_tail() in one operation. > > > > TIL list_bulk_move_tail() :D > > > >> This reduces list pointer churn> inside the lock critical section. > > Nice! > > > Similar to this, can we return all slabs in pc->slabs at once when > > returning those slabs to the list? ... I see Vlastimil removed 'nr of > > empty slabs' check in the other series already. > > > > Now that it inserts slabs to the tail with Vlastimil's patchset, let's > > do a list_splice_tail() instead? > > Why not, although it should be rare to return more than one slab in that > path. Yeah, it's definitely still worth doing. > So in case this change gets tricky for some reason, we can leave it. sure, I will try and test. > > BTW, if you also get the same idea as I had and try to replace the > current "remove from pc.slabs initially, reinsert to pc.slabs if it was > a partial refill" with a "keep in pc.slabs and only remove if the refill > was full" to reduce pointer churn, don't try that, it crashes rather > quickly :D Ah, fair enough. But honestly, it did seem like a good idea initially. > > >> The mmap2 testcase shows a 5% improvement after applying this patch. > >> > >> Signed-off-by: Hao Li > >> --- > >>   mm/slub.c | 22 ++++++++++++++++++---- > >>   1 file changed, 18 insertions(+), 4 deletions(-) > >> > >> diff --git a/mm/slub.c b/mm/slub.c > >> index 04692a6f9128..180973a4a3d2 100644 > >> --- a/mm/slub.c > >> +++ b/mm/slub.c > >> @@ -3775,15 +3783,21 @@ static bool get_partial_node_bulk(struct > >> kmem_cache *s, > >>               && total_free + slab_free > pc->max_objects) > >>               break; > >>   -        remove_partial(n, slab); > >> - > >> -        list_add(&slab->slab_list, &pc->slabs); > >> +        if (!first) > >> +            first = slab; > >> +        last = slab; > > > >> +        slab_clear_node_partial(slab); > >> +        n->nr_partial--; > > > > Perhaps factor out those two statements into to a common function and > > call it in get_partial_node_bulk() and remove_partial()? > >>           total_free += slab_free; > >>           if (total_free >= pc->max_objects) > >>               break; > >>       } > >>   +    if (first) > >> +        list_bulk_move_tail(&pc->slabs, &first->slab_list, > >> +                    &last->slab_list); > >> + > >>       spin_unlock_irqrestore(&n->list_lock, flags); > >>       return total_free > 0; > >>   } > > > -- Thanks, Hao