Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1950521lqz; Tue, 2 Apr 2024 02:42:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOR4qSQmd04BOnpytw5oeF9HTb9uomoqdM+0kG0v0IGH2ZxSHL+srrXzpRVF7PBizUfnboldf0XbCr7DiYChsk+/OlAV0W6dyD/Qt+tA== X-Google-Smtp-Source: AGHT+IHZk0tQ3VEDZ6nLRE736VyYxI2y1YXakkhN2pVC78SWgX47eYMbDgsWAd27xLfvRKoQezuw X-Received: by 2002:a05:6a20:2d21:b0:1a3:bd8a:edd with SMTP id g33-20020a056a202d2100b001a3bd8a0eddmr17825147pzl.28.1712050929559; Tue, 02 Apr 2024 02:42:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712050929; cv=pass; d=google.com; s=arc-20160816; b=djUZHSQUhyrAzf5eElnSfRbXTk8csZ2QPMBut4gRCS9osB3QjkJGe0b9bZk2WgJ89S rFpydBGGbLO2XeYEP6xl+6j9dINDui9gY4jIN2myx3RIviTIodVwJdzfEV6ZxK3KeGVJ tRGNG6x6IGmxvToGQJZNT2103n7PB98MGanA37rKmSe9Gr94ppIDcpGFrWFZVjjUEDaO wDMMJwp5/tqlbrSW+Np28RlK1xXulObdJZS5n76RicY79dhzLEqI2qR2hGabbDhVIZfc 3hHHIsDJZ1P341MV04N9hUTOW5GKhu+DqBMS6Rhek+6D97rSEkoI9cnlYZ497oZcbYFH CU2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature; bh=EE8a+wnZE91QojPp3DV/yCTs38b1kVho56fYvZnxQs0=; fh=MS6UY0Ie8OklUyI/Nq0PzyaL2G0XzHmBCHrUo51Lf3c=; b=yj/VvFsv857kK5fkU+Zni24EOki+bkfZN7YNUicaz3A53/kylNSm1Wu46KnpI9vwUr F1rDf9LoaBokRJp+wRdnAyEprEYBzYr0fyuZLPBlqS9Mtm7m0VdyW3xrfv1wAsxJQw3x jNoSHSrdOduzneiuepcaIHW/+RTWhr/n0lqeEcDJZ3+qcqcHBRf2LwtUYwLpnRJWWS37 +f3jaEIWMHffXsbTztcXZoag9vvDlVmnHUgtdbFRygjuc85NUk4gbEVtz2f+dBGHBxcp Tfvy8bK7uVogQMbpqqL1qtJ5qj/fV4Xwfe7DZTn57rJHgIh1nSMpHWBczqaMEIuDKwuN DoZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=bqQJ+GdV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-127648-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127648-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cb15-20020a056a02070f00b005d8c1b5a3bdsi11766307pgb.216.2024.04.02.02.42.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 02:42:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127648-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=bqQJ+GdV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-127648-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127648-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 40B47284C5B for ; Tue, 2 Apr 2024 09:42:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61A9C58AAB; Tue, 2 Apr 2024 09:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="bqQJ+GdV"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="E5xRPWUe" 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 92C549454 for ; Tue, 2 Apr 2024 09:42:00 +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=1712050922; cv=none; b=VoiPOx/+W0ue9+3nlI0jhTs8oDBYStWxiyZ2AhIFuAVWFC3uXLKr/WajUEE/dhpPH+S6il4GEXmq8IQZ67SjDyCcedReEhKy+h4YgESgyVneBt+umx+9jiKzypjCbm08QQTHSGv4uCE0bPY8pfcJYdC6TkDZ8/B0zZC8R6IewDY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712050922; c=relaxed/simple; bh=4P6NmsQd9ymTEeqbbtoj/MFmztwiWWpFPE3C3DIaKHQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oNOtac7NX3GMyPPVOx8Mm6shhOUGK3WVQnRRAWOssOk9879kcJXUGrCnoVvqlrFRtvqhv4O571+jsRhld4lOy+o+3mChZlNBENa08eYNVX0d2FbDNeLs1eU/mQpaTQ3FXH11umWeJtZxza9htDmmKUokM/P+yc+raYulDJt7Tqs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=bqQJ+GdV; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=E5xRPWUe; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 8EC7920EEB; Tue, 2 Apr 2024 09:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1712050918; h=from:from:reply-to: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=EE8a+wnZE91QojPp3DV/yCTs38b1kVho56fYvZnxQs0=; b=bqQJ+GdViZ/PcRAUfTqvgjd3mqqtqqTbpRPQifuS/ygPstRqVS+jHnwNIziT6Y2sxeeC8y ckr2jVBT0jf1mwnJeKx8NustibVm2uiqE/86dfxvUKWk6oVfKy7jWbMUS8Iy9em6/7Em+v x4UYvNYKQ/lgglPS8/hsCw5PFcsbcFo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1712050918; h=from:from:reply-to: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=EE8a+wnZE91QojPp3DV/yCTs38b1kVho56fYvZnxQs0=; b=E5xRPWUeeMOUJ4QbU/2ftypWQ7KnHvURp5ssvETvW31ZcDGYjsCPLy9RSvvfx+gWUvE1IO 6+EFM0mC+F90a9Cw== Authentication-Results: smtp-out2.suse.de; dkim=none Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 722A013A90; Tue, 2 Apr 2024 09:41:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id BuEkG+bSC2YIAgAAn2gu4w (envelope-from ); Tue, 02 Apr 2024 09:41:58 +0000 Message-ID: <69089796-9a3b-41a1-9b7c-18c773b96aa2@suse.cz> Date: Tue, 2 Apr 2024 11:41:58 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/4] mm/slub: simplify get_partial_node() Content-Language: en-US To: xiongwei.song@windriver.com, rientjes@google.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev References: <20240331021926.2732572-1-xiongwei.song@windriver.com> <20240331021926.2732572-4-xiongwei.song@windriver.com> From: Vlastimil Babka In-Reply-To: <20240331021926.2732572-4-xiongwei.song@windriver.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -1.10 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spamd-Result: default: False [-1.10 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; RCPT_COUNT_SEVEN(0.00)[11]; FREEMAIL_TO(0.00)[windriver.com,google.com,linux.com,kernel.org,lge.com,linux-foundation.org,linux.dev,gmail.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_IN_DNSWL_HI(-0.50)[2a07:de40:b281:104:10:150:64:98:from]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:98:from] X-Spam-Level: X-Rspamd-Queue-Id: 8EC7920EEB On 3/31/24 4:19 AM, xiongwei.song@windriver.com wrote: > From: Xiongwei Song > > The break conditions can be more readable and simple. > > We can check if we need to fill cpu partial after getting the first > partial slab. If kmem_cache_has_cpu_partial() returns true, we fill > cpu partial from next iteration, or break up the loop. > > Then we can remove the preprocessor condition of > CONFIG_SLUB_CPU_PARTIAL. Use dummy slub_get_cpu_partial() to make > compiler silent. > > Signed-off-by: Xiongwei Song > --- > mm/slub.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 590cc953895d..ec91c7435d4e 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -2614,18 +2614,20 @@ static struct slab *get_partial_node(struct kmem_cache *s, > if (!partial) { > partial = slab; > stat(s, ALLOC_FROM_PARTIAL); > - } else { > - put_cpu_partial(s, slab, 0); > - stat(s, CPU_PARTIAL_NODE); > - partial_slabs++; > + > + /* Fill cpu partial if needed from next iteration, or break */ > + if (kmem_cache_has_cpu_partial(s)) That kinda puts back the check removed in patch 1, although only in the first iteration. Still not ideal. > + continue; > + else > + break; > } > -#ifdef CONFIG_SLUB_CPU_PARTIAL > - if (partial_slabs > s->cpu_partial_slabs / 2) > - break; > -#else > - break; > -#endif I'd suggest intead of the changes done in this patch, only change this part above to: if ((slub_get_cpu_partial(s) == 0) || (partial_slabs > slub_get_cpu_partial(s) / 2)) break; That gets rid of the #ifdef and also fixes a weird corner case that if we set cpu_partial_slabs to 0 from sysfs, we still allocate at least one here. It could be tempting to use >= instead of > to achieve the same effect but that would have unintended performance effects that would best be evaluated separately. > > + put_cpu_partial(s, slab, 0); > + stat(s, CPU_PARTIAL_NODE); > + partial_slabs++; > + > + if (partial_slabs > slub_get_cpu_partial(s) / 2) > + break; > } > spin_unlock_irqrestore(&n->list_lock, flags); > return partial;