Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1766235rda; Tue, 24 Oct 2023 02:36:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnEQyd5ZRwhLq2kYyW1yABLjchfykg5K+88fA0f55Qv3kX8qnMGhxDsnCNlLyqSB8WuWkY X-Received: by 2002:a05:6a20:8404:b0:17d:e6d5:7585 with SMTP id c4-20020a056a20840400b0017de6d57585mr2385176pzd.18.1698140160905; Tue, 24 Oct 2023 02:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698140160; cv=none; d=google.com; s=arc-20160816; b=QzGuav0W/zh27lZnY3AQsObeSoWBaKBlAUb77/ZlCohHfSvkkxmV9JNJb2Vgje2N7A PYf1EqJknhUuWGxclnA4I4ulanliz3lFg8dC3nvAM31eHo+Fua2Z4S+IMIX7b6Eqi/J7 lolK6gqXxK/v2RIl0gHYzhEwPJUdhHWJvvpsjjvxk4kuhEccYNkSCTbFAel/mZdlvYGG P5wN79KMom6d2K3gPVybhRRCfhn7Kz7FhsgNUZutPS1OTSLKFb6SplCcE153VpTAVOnG Ju8P1hBkmkfliH2faOp/am5YUjFIBdoLHc98aJCbq1s4PsrUGHgFfHrHSyR6L1/hiSGi o/+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cdvJNGs14r77ax8dSUQgIW9duarJJopRajvvGp2TDMo=; fh=pb+eBl776ZRvna1F9CtRk2Qy3fEtolZ93e7lS3CUucI=; b=U7JtxYL5/QYjVrpVhoEfh1QOQtTxH58e18fQT5aF+meSA2DGY9oGalIZcvOy0ZDcug 5iKZ+6qMp2GbVegGFJfkYkZKD+u+3TG+fD+TM2PBJyxX92PCkobFyJbY460gcRxHz3a4 Vwq6aOI8KbWaB42lZ6nciZujCmSqPkX+V5xHCN9GLFVlcmy0G98hH+ZIIBC6VgCzltmH jpn66JbrS+wgs9gCxQ2xJOak2ynasxZcb8OWS88e7qVkrAlN1l7PyOqKfYJB3OsIcdOj sXViyElBF5/2TiQ5TodKId/m/BP2M+nzBNNDqsUlCkGTuBzhLn7OBDutjhhNPgxvlzct ehGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LFQxXGGR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ng11-20020a17090b1a8b00b002792831692csi10878854pjb.58.2023.10.24.02.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LFQxXGGR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id AB9E4807F4AD; Tue, 24 Oct 2023 02:35:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232908AbjJXJeq (ORCPT + 99 others); Tue, 24 Oct 2023 05:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234581AbjJXJeP (ORCPT ); Tue, 24 Oct 2023 05:34:15 -0400 Received: from out-197.mta0.migadu.com (out-197.mta0.migadu.com [91.218.175.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DBD1170D for ; Tue, 24 Oct 2023 02:34:13 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698140051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cdvJNGs14r77ax8dSUQgIW9duarJJopRajvvGp2TDMo=; b=LFQxXGGRKgIbWAldNJ1TYZrnkEc0I+pD5nGoJ0Dqwyqt32dcDScSAvf2HkxURKE+MuV4uf VITI/OvMyXtzkGrkQIUB2hTODauxk/xJEPGsyPf7Ow4uqMZV7ixHrnzuwbIKcLr4S5SXvq SpnsSqfJOa1quAz1cL2pg8WHPN5pFGw= From: chengming.zhou@linux.dev To: cl@linux.com, penberg@kernel.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou Subject: [RFC PATCH v3 7/7] slub: Optimize deactivate_slab() Date: Tue, 24 Oct 2023 09:33:45 +0000 Message-Id: <20231024093345.3676493-8-chengming.zhou@linux.dev> In-Reply-To: <20231024093345.3676493-1-chengming.zhou@linux.dev> References: <20231024093345.3676493-1-chengming.zhou@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:35:12 -0700 (PDT) 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 --- mm/slub.c | 70 ++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 486d44421432..64d550e415eb 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2449,10 +2449,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; @@ -2499,58 +2497,40 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab, * 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; + 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; - new.frozen = 0; + } 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. + */ if (!new.inuse && n->nr_partial >= s->min_partial) { - mode = M_FREE; + stat(s, DEACTIVATE_EMPTY); + discard_slab(s, slab); + stat(s, FREE_SLAB); } else if (new.freelist) { - mode = M_PARTIAL; - /* - * Taking the spinlock removes the possibility that - * acquire_slab() will see a slab that is frozen - */ spin_lock_irqsave(&n->list_lock, flags); - } else { - mode = M_FULL_NOLIST; - } - - - if (!slab_update_freelist(s, slab, - old.freelist, old.counters, - new.freelist, new.counters, - "unfreezing slab")) { - if (mode == M_PARTIAL) - spin_unlock_irqrestore(&n->list_lock, flags); - goto redo; - } - - - if (mode == M_PARTIAL) { add_partial(n, slab, tail); spin_unlock_irqrestore(&n->list_lock, flags); stat(s, tail); - } else if (mode == M_FREE) { - stat(s, DEACTIVATE_EMPTY); - discard_slab(s, slab); - stat(s, FREE_SLAB); - } else if (mode == M_FULL_NOLIST) { + } else stat(s, DEACTIVATE_FULL); - } } #ifdef CONFIG_SLUB_CPU_PARTIAL -- 2.40.1