From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 5E018356745 for ; Tue, 26 May 2026 09:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779786565; cv=none; b=oBha0Qf7EBRqvKgphYw9Fjlx3k8bce3wywTo8jWMQRWum4WjXe6e4HBDpdBb/jW60gVf6NiarshEdkL4WkfLgVuO8sf1/A+qRKTUI4Bgeqz3Ad0cFMOBhT37yR/vX8XCHsPeePuJPJKKgBOJTWFuCS0fE3HkkBdgOMufCbErlus= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779786565; c=relaxed/simple; bh=N/l+dyFFS+2QlrmV33MGc6eCPbzNKHuSH6TdMb/I7rk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LdGZzCDEtxxa82VSeMLzM6LI1Wf/UvDOczJ4CFAiqX5QHJhyT7ZLi/4ib8uzKhvEvlePld16Tcey1yOkpauukKy1xF1bGbUrgztddLfA5AOJgbiUqF+tu4WUOrhzVedsfArdRkG1oPbwA925jlXzrjN4vif6Wh+NsOD95TA4990= 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=p9IWdmdq; arc=none smtp.client-ip=95.215.58.170 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="p9IWdmdq" Date: Tue, 26 May 2026 17:08:54 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779786561; 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=1Av4VS/wv4E9mLXQbLY6JNstbYHwbHdBV3kDnr83jr8=; b=p9IWdmdqX6SNOxH1IJtOP7k2EBJNTZILa1m9fOH9nDQ64YliorTOHexSpztjQCZMPfyLQr Q8Gbu9JDjOHg2Clc1m2RYOZBvxm69U2+18cmRmuxodqF0fyXnkGgRf/G615I1sohrib4EA FvmjF1UeOvwvM6cvYQwc6Gohg0Sem9c= 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: batch-detach node partial slabs Message-ID: References: <20260525032233.10847-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 Tue, May 26, 2026 at 04:37:46PM +0900, 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 I had to dig through list.h for ages just to find it :P > > > This reduces list pointer churn> inside the lock critical section. > > 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? Great idea! then both get and put operations will be highly efficient. > > > 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()? Agreed, this is very reasonable. > > 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 for the review! -- Thanks, Hao