Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2880727rdb; Mon, 4 Dec 2023 09:57:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4RuZRKf/IJtYbtaqwLc0d2QbqcsuiDgnRmx+5W9Brm1W7SUmkvdCCflIxKZZ685K5m8QZ X-Received: by 2002:a17:902:720c:b0:1cf:d2c5:ae87 with SMTP id ba12-20020a170902720c00b001cfd2c5ae87mr1688964plb.11.1701712625995; Mon, 04 Dec 2023 09:57:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701712625; cv=none; d=google.com; s=arc-20160816; b=t5nkGbe1OwJf7XGEGh4FtzKV/18ZpkgvhOsJ++ebTBoaBOv98sh5kqRL3VMOJ/fHwa LQTT57qVYszvENIaCQKN0QCZ/bw/qq0iD9bsuIsJM941GoWzlzHjq26ORBCD4YYgCwDA dX2x9iQW4FeFSBlxnTfIJljOXPCzOmIjqbE8xOLqcrbBvNRBAIR7ZypMeUXBLnroq46E pDIeQeFWKV2fzkgoQa7JgTV+bfPS7tDwZ7LVf/IzpzegiThzNWwzRAsc7gYoOgO/PpD9 bfj3ti/sg9ndDL0vnNQQHMGW/HZsIYxXhC63GnuKydEGgImDy1VnMzclEi9iygrih+Po 5YAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=r+ChwpOzxHvem0IUTQpKzGeMDXIKtr46bb48LKkyBgs=; fh=Zg3i622FB/TNsZSoj31W6LYcX5NYKjfrRVF5e5Aqs/8=; b=sNTtMJG9axbElDuctOtLWReMw/o11KfsapEy2zxPAOTRws5Li8klWGXXHxnKPGMeU4 aCqUmP9jBctyEPjIOupoFYBaFf/F/t0MR8JwE3QZIfN6eE0O8iA9NoVnh2rzWQchTNeX lXKfxx3vKCtI6CbZgIJ3Uq3c5gUpMGYVni/QhtHCqrRuR8QKuDjM3KLAL8fpcteS7QBn u0rGJkOc9aScE5mrPar6BYdzsta4SwkanO/GY/RmSNlSizoh9f5BGRjvJtavM15Dga1X xGhnx1bkQyDXDRK9Mvzvkno+gkCMQx3MVnFQvebjlBZWQHfyDIg9yTHYVdsFVuMB7FkQ Bhmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id g10-20020a656cca000000b00578b4082453si8381031pgw.712.2023.12.04.09.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 09:57:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 6E1BC80B9922; Mon, 4 Dec 2023 09:57:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbjLDR4m (ORCPT + 99 others); Mon, 4 Dec 2023 12:56:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231561AbjLDRzv (ORCPT ); Mon, 4 Dec 2023 12:55:51 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1C139A for ; Mon, 4 Dec 2023 09:55:57 -0800 (PST) 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 2D5C6220DC; Mon, 4 Dec 2023 17:55:56 +0000 (UTC) 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 13742139AA; Mon, 4 Dec 2023 17:55:56 +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 aFNfBKwSbmWYDwAAD6G6ig (envelope-from ); Mon, 04 Dec 2023 17:55:56 +0000 Message-ID: <93dcdf0c-336b-cb20-d646-7a48d872e08c@suse.cz> Date: Mon, 4 Dec 2023 18:55:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v5 7/9] slub: Optimize deactivate_slab() Content-Language: en-US To: Hyeonggon Yoo <42.hyeyoo@gmail.com>, chengming.zhou@linux.dev Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chengming Zhou References: <20231102032330.1036151-1-chengming.zhou@linux.dev> <20231102032330.1036151-8-chengming.zhou@linux.dev> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++++++ X-Spam-Score: 8.92 X-Rspamd-Server: rspamd1 Authentication-Results: smtp-out1.suse.de; dkim=none; spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of vbabka@suse.cz) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Queue-Id: 2D5C6220DC X-Spamd-Result: default: False [8.92 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; 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]; DMARC_NA(1.20)[suse.cz]; R_SPF_SOFTFAIL(4.60)[~all]; BAYES_HAM(-3.00)[100.00%]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.18)[-0.885]; RCPT_COUNT_SEVEN(0.00)[11]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email]; NEURAL_SPAM_LONG(2.71)[0.773]; FREEMAIL_TO(0.00)[gmail.com,linux.dev]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Status: No, score=-4.9 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 04 Dec 2023 09:57:03 -0800 (PST) On 12/3/23 10:23, Hyeonggon Yoo wrote: > On Thu, Nov 2, 2023 at 12:25 PM wrote: >> >> From: Chengming Zhou >> >> Since the introduce of unfrozen slabs on cpu partial list, we don't >> need to synchronize the slab frozen state under the node list_lock. >> >> The caller of deactivate_slab() and the caller of __slab_free() won't >> manipulate the slab list concurrently. >> >> So we can get node list_lock in the last stage if we really need to >> manipulate the slab list in this path. >> >> Signed-off-by: Chengming Zhou >> Reviewed-by: Vlastimil Babka >> Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> >> --- >> mm/slub.c | 79 ++++++++++++++++++------------------------------------- >> 1 file changed, 26 insertions(+), 53 deletions(-) >> >> diff --git a/mm/slub.c b/mm/slub.c >> index bcb5b2c4e213..d137468fe4b9 100644 >> --- a/mm/slub.c >> +++ b/mm/slub.c >> @@ -2468,10 +2468,8 @@ static void init_kmem_cache_cpus(struct kmem_cache *s) >> static void deactivate_slab(struct kmem_cache *s, struct slab *slab, >> void *freelist) >> { >> - enum slab_modes { M_NONE, M_PARTIAL, M_FREE, M_FULL_NOLIST }; >> struct kmem_cache_node *n = get_node(s, slab_nid(slab)); >> int free_delta = 0; >> - enum slab_modes mode = M_NONE; >> void *nextfree, *freelist_iter, *freelist_tail; >> int tail = DEACTIVATE_TO_HEAD; >> unsigned long flags = 0; >> @@ -2509,65 +2507,40 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab, >> /* >> * Stage two: Unfreeze the slab while splicing the per-cpu >> * freelist to the head of slab's freelist. >> - * >> - * Ensure that the slab is unfrozen while the list presence >> - * reflects the actual number of objects during unfreeze. >> - * >> - * We first perform cmpxchg holding lock and insert to list >> - * when it succeed. If there is mismatch then the slab is not >> - * unfrozen and number of objects in the slab may have changed. >> - * Then release lock and retry cmpxchg again. >> */ >> -redo: >> - >> - old.freelist = READ_ONCE(slab->freelist); >> - old.counters = READ_ONCE(slab->counters); >> - VM_BUG_ON(!old.frozen); >> - >> - /* Determine target state of the slab */ >> - new.counters = old.counters; >> - if (freelist_tail) { >> - new.inuse -= free_delta; >> - set_freepointer(s, freelist_tail, old.freelist); >> - new.freelist = freelist; >> - } else >> - new.freelist = old.freelist; >> - >> - new.frozen = 0; >> + do { >> + old.freelist = READ_ONCE(slab->freelist); >> + old.counters = READ_ONCE(slab->counters); >> + VM_BUG_ON(!old.frozen); >> + >> + /* Determine target state of the slab */ >> + new.counters = old.counters; >> + new.frozen = 0; >> + if (freelist_tail) { >> + new.inuse -= free_delta; >> + set_freepointer(s, freelist_tail, old.freelist); >> + new.freelist = freelist; >> + } else { >> + new.freelist = old.freelist; >> + } >> + } while (!slab_update_freelist(s, slab, >> + old.freelist, old.counters, >> + new.freelist, new.counters, >> + "unfreezing slab")); >> >> + /* >> + * Stage three: Manipulate the slab list based on the updated state. >> + */ > > deactivate_slab() might unconsciously put empty slabs into partial list, like: > > deactivate_slab() __slab_free() > cmpxchg(), slab's not empty > cmpxchg(), slab's empty > and unfrozen > spin_lock(&n->list_lock) > (slab's empty but not > on partial list, > > spin_unlock(&n->list_lock) and return) > spin_lock(&n->list_lock) > put slab into partial list > spin_unlock(&n->list_lock) > > IMHO it should be fine in the real world, but just wanted to > mention as it doesn't seem to be intentional. I've noticed it too during review, but then realized it's not a new behavior, same thing could happen with deactivate_slab() already before the series. Free slabs on partial list are supported, we even keep some intentionally as long as "n->nr_partial < s->min_partial" (and that check is racy too), so no need to try making this more strict. > Otherwise it looks good to me! Good enough for a reviewed-by? :)