Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp474956rdb; Mon, 22 Jan 2024 09:47:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnf4V/CNcerlYMxe+WjjxayWkAaSYJS9J529uXiJUGmJ6OvdusfOO9HVat9Rx2taZMIxpZ X-Received: by 2002:ac8:7ca4:0:b0:42a:3a7c:face with SMTP id z4-20020ac87ca4000000b0042a3a7cfacemr3008833qtv.134.1705945671333; Mon, 22 Jan 2024 09:47:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705945671; cv=pass; d=google.com; s=arc-20160816; b=pWzcYxA96ujO2V8c5fRIEmuBYSBsMv+MCvMU3E4hmXEEFkYW38bf0ndXohlyyBD5Nx t3SV0VYkATIqlxpiv7yMVvhaj3rYjtbrZJciEpdhcs6O29tbChk8Q5UIS+XN7Q1MAWaz +Ax0t/jhKnpADG2xur+JVbjf4CRo2JqAkuZA8DAJ6+np+pu+SujXbiSM3+jpGSqlkIPi V3g5F8sQCuxilnm6JuX2KyqR5q/B1xwCB/0FwNYnRnWWW1Sk/ZjB5mKgCc/xaG1IYS4R DPOFesn43gIpaMTWJEBhYu2HcKEH6/AzP9F0tLRzQSjiKkJLKtdSjFALKGn1IeafSeTr D+Hg== 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:dkim-signature:dkim-signature; bh=+BcI2f1DWEvDi/Qr4PdTFHB53Q+BL3Gr3mer1rs/hRw=; fh=MZAcN0P9U0Zn+wSioh1BXD+c0KseIloBi7frnWwxXIs=; b=uEsUVNthKwv5EmmFwY5Qepm+0v1OnwSjFCSGEHoD7TK654ghpqtYvNcS4FlfkDQTSi xvJp6jAK7AN2QbYS0hgRojBySlrK+/YAuQmBCYsOY2w0a/jceqSUBksSAH4zK5lO8/CZ BmEeRrvgbLKqmDsbnIg+/m0MWxLlWcwyV1Kwb00cQad8orPgWgvkSWkReyIT4yWsBrhh UA+0BQKEhuH66vSWLcYPMvzESkxP83m6Pi8S/8YAWmBVRJx0r6C0rHLVhCVvw4HW0sWX Y0vHcBu3s01cvMcnLDJ+1L8ibiuyFBaJHxkDfdaqI3E6lKw7PD/lzMe9+UAnrEz7lye4 fRcw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=C9n4lLYT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=C9n4lLYT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=U0E03061; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-33757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33757-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bp31-20020a05622a1b9f00b00421af2e8f53si5916972qtb.624.2024.01.22.09.47.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:47:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=C9n4lLYT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=C9n4lLYT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=U0E03061; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-33757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33757-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0CC441C27B56 for ; Mon, 22 Jan 2024 17:47:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CC0A4BAA7; Mon, 22 Jan 2024 17:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="C9n4lLYT"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="U0E03061"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="C9n4lLYT"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="U0E03061" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 951614BAA2 for ; Mon, 22 Jan 2024 17:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705943597; cv=none; b=RvGg6eABewR5JcAFJWo54jVUagXBLd4LfgE5Nmy+al/64LGuL11wSQh4Y7RZkJkAdGI7ahwn8ZPuT71Xueab3TZxdTTBdQ3XGvU3rcQl+V4GN7wkNSqgyP/fJ+L4oJQkJu1JaZkPK6+5iWRhMm4gcy5JUE40SeUlXwklPaz4YoQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705943597; c=relaxed/simple; bh=eK7d3MG7N6Aqc45gYJeNpsG+NQTSq7gYjxILB/X0pJk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rcSDGB85lJhVyWXlj7f55xa7NDW3ZmUrDXeiHIfEeHOJJRPoMVfpcmKhceKGRg0sp7mfBa+Q3FV/iY0UznmMzkKgZ/5El/Amrsg3m9XxArmx5WTu9HSoepr9W2BH5eRrYNtUPCyt0x5Oajyz1QPdQFvWJmBRrhwXxrqaMIc8jBo= 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=C9n4lLYT; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=U0E03061; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=C9n4lLYT; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=U0E03061; arc=none smtp.client-ip=195.135.223.130 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 imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out1.suse.de (Postfix) with ESMTPS id 81E3B22088; Mon, 22 Jan 2024 17:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705943593; 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=+BcI2f1DWEvDi/Qr4PdTFHB53Q+BL3Gr3mer1rs/hRw=; b=C9n4lLYTyW8m+oJGEbe+cIJG2OXyT8KgB3X9cn82+C0lAykfyVHXwuem5POohTZBREZH/6 MFCOiBxCjNbyJpKmW7vSmaeUf0rSqAO7UmKJfXMOolVgBSyIt3pwDRdd5G4oI019i+VTQ7 ytMywBuxK78mvRChO8IywXyOsI5joTc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705943593; 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=+BcI2f1DWEvDi/Qr4PdTFHB53Q+BL3Gr3mer1rs/hRw=; b=U0E03061dl5X3HrGBv/nhNNE914wcs2KdfKnO+tCuxm38bDCVVe5+ImJMy6biDZjFKe2vg /F3ntfVeySBOF+Bg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705943593; 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=+BcI2f1DWEvDi/Qr4PdTFHB53Q+BL3Gr3mer1rs/hRw=; b=C9n4lLYTyW8m+oJGEbe+cIJG2OXyT8KgB3X9cn82+C0lAykfyVHXwuem5POohTZBREZH/6 MFCOiBxCjNbyJpKmW7vSmaeUf0rSqAO7UmKJfXMOolVgBSyIt3pwDRdd5G4oI019i+VTQ7 ytMywBuxK78mvRChO8IywXyOsI5joTc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705943593; 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=+BcI2f1DWEvDi/Qr4PdTFHB53Q+BL3Gr3mer1rs/hRw=; b=U0E03061dl5X3HrGBv/nhNNE914wcs2KdfKnO+tCuxm38bDCVVe5+ImJMy6biDZjFKe2vg /F3ntfVeySBOF+Bg== 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 6909A136A4; Mon, 22 Jan 2024 17:13:13 +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 6VL5GCmirmWqDAAAD6G6ig (envelope-from ); Mon, 22 Jan 2024 17:13:13 +0000 Message-ID: Date: Mon, 22 Jan 2024 18:13:13 +0100 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 1/3] mm/slub: directly load freelist from cpu partial slab in the likely case Content-Language: en-US To: Chengming Zhou , "Christoph Lameter (Ampere)" Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Joonsoo Kim , Pekka Enberg , Andrew Morton , Roman Gushchin , David Rientjes , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240117-slab-misc-v1-0-fd1c49ccbe70@bytedance.com> <20240117-slab-misc-v1-1-fd1c49ccbe70@bytedance.com> <76641777-1918-2b29-b6aa-bda9b5467aa3@gentwo.org> <412b8618-0941-4d9d-85df-ee480695e7f7@bytedance.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=C9n4lLYT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=U0E03061 X-Spamd-Result: default: False [-1.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BAYES_HAM(-3.00)[100.00%]; MID_RHS_MATCH_FROM(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[10]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[gmail.com,lge.com,kernel.org,linux-foundation.org,linux.dev,google.com,kvack.org,vger.kernel.org]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 81E3B22088 X-Spam-Level: X-Spam-Score: -1.80 X-Spam-Flag: NO On 1/19/24 04:53, Chengming Zhou wrote: > On 2024/1/19 06:14, Christoph Lameter (Ampere) wrote: >> On Thu, 18 Jan 2024, Chengming Zhou wrote: >> >>> So get_freelist() has two cases to handle: cpu slab and cpu partial list slab. >>> The latter is NOT frozen, so need to remove "VM_BUG_ON(!new.frozen)" from it. >> >> Right so keep the check if it is the former? >> > > Ok, I get it. Maybe like this: I think that's just too ugly for a VM_BUG_ON(). I'd just remove the check and be done with that. I have a somewhat different point. You reused get_freelist() but in fact it's more like freeze_slab(), but that one uses slab_update_freelist() and we are under the local_lock so we want the cheaper __slab_update_freelist(), which get_freelist() has and I guess that's why you reused that one. However get_freelist() also assumes it can return NULL if the freelist is empty. If that's possible to happen on the percpu partial list, we should not "goto load_freelist;" but rather create a new label above that, above the "if (!freelist) {" block that handles the case. If that's not possible to happen (needs careful audit) and we have guarantee that slabs on percpu partial list must have non-empty freelist, then we probably instead want a new __freeze_slab() variant that is like freeze_slab(), but uses __slab_update_freelist() and probably also has VM_BUG_ON(!freelist) before returning it? > > diff --git a/mm/slub.c b/mm/slub.c > index 2ef88bbf56a3..7fa9dbc2e938 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3313,7 +3313,7 @@ __update_cpu_freelist_fast(struct kmem_cache *s, > * > * If this function returns NULL then the slab has been unfrozen. > */ > -static inline void *get_freelist(struct kmem_cache *s, struct slab *slab) > +static inline void *get_freelist(struct kmem_cache *s, struct slab *slab, int frozen) > { > struct slab new; > unsigned long counters; > @@ -3326,7 +3326,7 @@ static inline void *get_freelist(struct kmem_cache *s, struct slab *slab) > counters = slab->counters; > > new.counters = counters; > - VM_BUG_ON(!new.frozen); > + VM_BUG_ON(frozen && !new.frozen); > > new.inuse = slab->objects; > new.frozen = freelist != NULL; > @@ -3440,7 +3440,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, > if (freelist) > goto load_freelist; > > - freelist = get_freelist(s, slab); > + freelist = get_freelist(s, slab, 1); > > if (!freelist) { > c->slab = NULL; > @@ -3498,18 +3498,19 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, > > slab = slub_percpu_partial(c); > slub_set_percpu_partial(c, slab); > - local_unlock_irqrestore(&s->cpu_slab->lock, flags); > - stat(s, CPU_PARTIAL_ALLOC); > > - if (unlikely(!node_match(slab, node) || > - !pfmemalloc_match(slab, gfpflags))) { > - slab->next = NULL; > - __put_partials(s, slab); > - continue; > + if (likely(node_match(slab, node) && > + pfmemalloc_match(slab, gfpflags))) { > + c->slab = slab; > + freelist = get_freelist(s, slab, 0); > + stat(s, CPU_PARTIAL_ALLOC); > + goto load_freelist; > } > > - freelist = freeze_slab(s, slab); > - goto retry_load_slab; > + local_unlock_irqrestore(&s->cpu_slab->lock, flags); > + > + slab->next = NULL; > + __put_partials(s, slab); > } > #endif