Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1765827rda; Tue, 24 Oct 2023 02:34:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFn9g8q6a84ybrW4QCgpTQU6L6r/7Mr8ZWB3ipI19etdsbLYYnlxprKl69u6Tth4lOQ2uKd X-Received: by 2002:a05:6a20:160e:b0:16b:f8f0:1c0c with SMTP id l14-20020a056a20160e00b0016bf8f01c0cmr2406680pzj.0.1698140092353; Tue, 24 Oct 2023 02:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698140092; cv=none; d=google.com; s=arc-20160816; b=PJfJSxEceYWio1DEE2Od+wjN1j1uiru26UddJuzrK9xIQBnqB+eR4V95TkZisYdIX+ Oqa3bfkux5X34zU5/wbLYCFyXj1zCKAn3d4MgpM1csgBuG+dyBQxFrA8tFk7x/PfV6nW DG6rcXQWkhnziyuH/mYHXE8y95ll7cItfstIhuGXDY1WQqoCcpYl00PO26uEgSwhnud3 T5bmWOunK+IwNutai8bP6OeQ0h1kjRWe4m4aDmBdZigqu4wpqqO1LDtDavctb0NMBQPj cEJRi/pSJ4JR1Iss3zGb2qtCut61qFrujEBiGc2gllVQ/37s35+FuFnSzSka9kFZ4727 BOuA== 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=mVsHpTi8/ybc90IBC2PUgLSTYbIjUF6GvQZHOJT0cXI=; fh=pb+eBl776ZRvna1F9CtRk2Qy3fEtolZ93e7lS3CUucI=; b=p0ftoifEN7+EFIyIaZVr4O0sW5yscx2DLzrZgQzKaEeaQ3oRYiOA/DTg1mPbm1GJGt EObZqdITXrR3J8ijre6mNBjJAdaMXaX09D/GWRETeiZYe3ZinCdl77BSOeuIQ+A0zYrA SHLwObRUUqciipcaeJkqaYl6ZiLaHOkpejIqs1v21F2wAJwtiPspRsX9gBhqYGojqHJJ Lceh6FeOgQnHl3Pu9wQDUQ6OMjoUxCtkbGDx/IgynR2kBQnSFD+CVasRJ9yJyghR5bfn Qa4zg7+LV5lPiiXPRC8xdyF1Md2g5hgOtOnNvM1J2ps7NWZWu5uGg1HGCUT5T4WwS6Uy G0ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WkSYYMuX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c6-20020a17090ad90600b002568a675b65si10824894pjv.141.2023.10.24.02.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:34:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WkSYYMuX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id BD0CB8030997; Tue, 24 Oct 2023 02:34:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234208AbjJXJel (ORCPT + 99 others); Tue, 24 Oct 2023 05:34:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234531AbjJXJeI (ORCPT ); Tue, 24 Oct 2023 05:34:08 -0400 Received: from out-206.mta0.migadu.com (out-206.mta0.migadu.com [IPv6:2001:41d0:1004:224b::ce]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45085D7F for ; Tue, 24 Oct 2023 02:33:59 -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=1698140037; 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=mVsHpTi8/ybc90IBC2PUgLSTYbIjUF6GvQZHOJT0cXI=; b=WkSYYMuXGHeVTVvJKeEDkqylfQ5ISuw3VBdmhEEMq+LWy2qJeirb8he9LzRmfOp5qZ6+kT ZswKHPlHfUqDgf+oW4CzD+qBmu/0yksI5xZDpGRNHQHcev4VmDR1H8HChl9GYIrTSRecZo StPLjAgG42c97ebsxtS4Z+pyEQMwhsc= 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 1/7] slub: Keep track of whether slub is on the per-node partial list Date: Tue, 24 Oct 2023 09:33:39 +0000 Message-Id: <20231024093345.3676493-2-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:34:51 -0700 (PDT) From: Chengming Zhou Now we rely on the "frozen" bit to see if we should manipulate the slab->slab_list, which will be changed in the following patch. Instead we introduce another way to keep track of whether slub is on the per-node partial list, here we reuse the PG_workingset bit. We use __set_bit and __clear_bit directly instead of the atomic version for better performance and it's safe since it's protected by the slub node list_lock. Signed-off-by: Chengming Zhou --- mm/slab.h | 19 +++++++++++++++++++ mm/slub.c | 3 +++ 2 files changed, 22 insertions(+) diff --git a/mm/slab.h b/mm/slab.h index 8cd3294fedf5..50522b688cfb 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -193,6 +193,25 @@ static inline void __slab_clear_pfmemalloc(struct slab *slab) __folio_clear_active(slab_folio(slab)); } +/* + * Slub reuse PG_workingset bit to keep track of whether it's on + * the per-node partial list. + */ +static inline bool slab_test_node_partial(const struct slab *slab) +{ + return folio_test_workingset((struct folio *)slab_folio(slab)); +} + +static inline void slab_set_node_partial(struct slab *slab) +{ + __set_bit(PG_workingset, folio_flags(slab_folio(slab), 0)); +} + +static inline void slab_clear_node_partial(struct slab *slab) +{ + __clear_bit(PG_workingset, folio_flags(slab_folio(slab), 0)); +} + static inline void *slab_address(const struct slab *slab) { return folio_address(slab_folio(slab)); diff --git a/mm/slub.c b/mm/slub.c index 63d281dfacdb..3fad4edca34b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2127,6 +2127,7 @@ __add_partial(struct kmem_cache_node *n, struct slab *slab, int tail) list_add_tail(&slab->slab_list, &n->partial); else list_add(&slab->slab_list, &n->partial); + slab_set_node_partial(slab); } static inline void add_partial(struct kmem_cache_node *n, @@ -2141,6 +2142,7 @@ static inline void remove_partial(struct kmem_cache_node *n, { lockdep_assert_held(&n->list_lock); list_del(&slab->slab_list); + slab_clear_node_partial(slab); n->nr_partial--; } @@ -4831,6 +4833,7 @@ static int __kmem_cache_do_shrink(struct kmem_cache *s) if (free == slab->objects) { list_move(&slab->slab_list, &discard); + slab_clear_node_partial(slab); n->nr_partial--; dec_slabs_node(s, node, slab->objects); } else if (free <= SHRINK_PROMOTE_MAX) -- 2.40.1