From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5D1B31F980 for ; Fri, 10 Jul 2026 12:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783685842; cv=none; b=XG2HNRHGuDxU6rhFN0e8RgUP6b2zOFwrjKJYIk+w+Vw3oSlKyH5I8t+QpiLgQq3NBhjFxpN8PGSR1qHZVNYf63hHKKgC9eGUTeLrWlNXZ60wA9vjwcf5vWvlvUgYapQT7nZcSfW0z34q4jXGSq0UbyiE5en8HhabAQZnJ2bfoX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783685842; c=relaxed/simple; bh=0/QUj557lGZL6ow8Qe/K0A/st2VIPtcwvntKZBszrMw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YKX2ND2FPlzJdyuqLQMXiw8f0bXpQBE6bEYqeVeT+ESnw8tbXe7J/LNcE0bKfAa+ajnKxd4tuFsTSV7K+U0rB7DwPIIGlww+/l+qP3EyC6kwKy2BQwafX9jNl6GnJErFKKozp1Gy5mQoXj1D8qQ6kL4n4LVlDJJhWixUpGNZjfQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=uPxhxBfJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bojB2edu; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=uPxhxBfJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=bojB2edu; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="uPxhxBfJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bojB2edu"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="uPxhxBfJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="bojB2edu" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1A48375BC3; Fri, 10 Jul 2026 12:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1783685839; h=from:from:reply-to: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=RBwrVz2fgaureVqk8n3H3VymA2WLTvgQYFJq8nXiOwA=; b=uPxhxBfJzjYJtVdWkN80jYm7LAxyLfMne8/+hcHSP0iPISThH4ZNXnA7aEsmUAJlFN5qYX HHbKxBZ2ybiSuIDX/zpvxeiANW6Jr/TuVOeemZY+O25K8infjCKSjWvSpoSUjjpw0QzVUX BpftPqD1O7lKZId2g+qhBVFtvcdUcGQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1783685839; h=from:from:reply-to: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=RBwrVz2fgaureVqk8n3H3VymA2WLTvgQYFJq8nXiOwA=; b=bojB2eduFQUP+QTcwHK6P5QLmZ9aW0yhJDb8k8VL8U77TsH1ugjB22zINIy/zD2aKSYs08 EyEQY/IeReiNi8Cg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1783685839; h=from:from:reply-to: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=RBwrVz2fgaureVqk8n3H3VymA2WLTvgQYFJq8nXiOwA=; b=uPxhxBfJzjYJtVdWkN80jYm7LAxyLfMne8/+hcHSP0iPISThH4ZNXnA7aEsmUAJlFN5qYX HHbKxBZ2ybiSuIDX/zpvxeiANW6Jr/TuVOeemZY+O25K8infjCKSjWvSpoSUjjpw0QzVUX BpftPqD1O7lKZId2g+qhBVFtvcdUcGQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1783685839; h=from:from:reply-to: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=RBwrVz2fgaureVqk8n3H3VymA2WLTvgQYFJq8nXiOwA=; b=bojB2eduFQUP+QTcwHK6P5QLmZ9aW0yhJDb8k8VL8U77TsH1ugjB22zINIy/zD2aKSYs08 EyEQY/IeReiNi8Cg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 63F9E779BE; Fri, 10 Jul 2026 12:17:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id V4X1FM7iUGryRAAAD6G6ig (envelope-from ); Fri, 10 Jul 2026 12:17:18 +0000 Date: Fri, 10 Jul 2026 13:17:16 +0100 From: Pedro Falcato To: "Vlastimil Babka (SUSE)" Cc: Harry Yoo , Andrew Morton , Hao Li , Shengming Hu , Christoph Lameter , David Rientjes , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH slab/for-next] mm/slab: simplify freeing remote objects in free_to_pcs_bulk() Message-ID: References: <20260710-bulk_free_remote-v1-1-a878d6dc52d5@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=us-ascii Content-Disposition: inline In-Reply-To: <20260710-bulk_free_remote-v1-1-a878d6dc52d5@kernel.org> X-Spam-Flag: NO X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_SEVEN(0.00)[10]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo] X-Spam-Level: On Fri, Jul 10, 2026 at 02:04:58PM +0200, Vlastimil Babka (SUSE) wrote: > We have been moving remote objects to an on-stack array and flushing it > when full. Instead, we can swap them towards the beginning of the > supplied array and bulk-free it just once. > > Also add a comment to explain the rationale of freeing remote objects > last, because now it would appear to be simpler to free them first. > > Signed-off-by: Vlastimil Babka (SUSE) > --- > One more cleanup I realized it's possible when processing feedback to > the previous one [1] > > [1] https://lore.kernel.org/all/20260707-slab-simplify-bulk-pcs-v1-1-4850dbe0d904@kernel.org/ > --- > mm/slub.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 22045dc919ef..966d2fb114e8 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -6255,7 +6255,7 @@ static unsigned int __free_to_pcs_batch(struct kmem_cache *s, size_t size, void > static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p) > { > bool init = slab_want_init_on_free(s); > - void *remote_objects[PCS_BATCH_MAX]; > + void **remote_objects = p; > unsigned int remote_nr = 0; > Maybe explaining what magic you're pulling off would be useful in the code as well. > for (unsigned int i = 0; i < size;) { > @@ -6270,19 +6270,17 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p) > } > > if (unlikely(!can_free_to_pcs(slab))) { > - remote_objects[remote_nr] = p[i]; > - p[i] = p[--size]; > - if (++remote_nr >= PCS_BATCH_MAX) { > - __kmem_cache_free_bulk(s, remote_nr, &remote_objects[0]); > - stat_add(s, FREE_SLOWPATH, remote_nr); > - remote_nr = 0; > - } > - continue; > + if (i != remote_nr) > + swap(remote_objects[remote_nr], p[i]); > + remote_nr++; > } > > i++; > } > > + p += remote_nr; > + size -= remote_nr; > + > while (size) { > unsigned int batch_freed = __free_to_pcs_batch(s, size, p); > > @@ -6296,8 +6294,12 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p) > size -= batch_freed; > } > > + /* > + * Processing remote objects last decreases the chances of cpu migration > + * while freeing to sheaves and compromising object locality > + */ > if (remote_nr) { > - __kmem_cache_free_bulk(s, remote_nr, &remote_objects[0]); > + __kmem_cache_free_bulk(s, remote_nr, remote_objects); > stat_add(s, FREE_SLOWPATH, remote_nr); > } > } All-in-all, LGTM Reviewed-by: Pedro Falcato > > --- > base-commit: e1fa26489025d6deac76d1dbfe2e0720a3ad84b1 > change-id: 20260710-bulk_free_remote-7fbe6f3abf5d > > Best regards to everyone but Pedro (btw this is not hard-coded, > there's a config option for this), I know there's a config option to change your signature but I haven't been able to simply omit this bit :| Anyway, I get a stray, you get a stray review. Nice trade. -- Pedro