Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp125730rdb; Wed, 1 Nov 2023 20:26:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoOcLQjFhqfITueZgRz8o4y3kwU5uGHrkq+bjRpVy8lVXZOb3bUk/aOhU8ObPpqr1YP02+ X-Received: by 2002:a05:6a00:814:b0:6bb:aaf:d7db with SMTP id m20-20020a056a00081400b006bb0aafd7dbmr23548902pfk.29.1698895571002; Wed, 01 Nov 2023 20:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698895570; cv=none; d=google.com; s=arc-20160816; b=dmDLy5Q6u6wWApGRTyoGbYBSagdRyL5fTR0/PUKbhZ2IvQltkSPsyI6RgZtrsrW4iK gmxqFbDVQSC5zYuR1HlH7/RZhPB7dwWAD5XZvT5MmdPA7OMkQl8aK3wKC9oFfefqrD5i jq42BFBP4tYTUqaQx3CONdWYc8v3XCa/er8rC71v4dhVSauOJcqBeoGtaPy/SctDlm0o Dexl0+ZchGibX58Dn1jM1Amj4i9VnmZj8yS76+UbhwsVkqQ7dVP7Uom504Lx9MtTAq4N HcZrwEzB1Br9pXccLBU8GWotaZkg4QIG8+nEZhA91OWG4MsCiz2WLf6NiXHcOYyGH6Cl UEFA== 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=IPS3iWC0ordY9Z/gFrasLVfoOU0ee6NMzPFkJtmjEdA=; fh=mNx4emnblabKsSvYnWt3rJfr5klL7EHzY3/GxImb0OY=; b=L0Ub74VHRuNi5XhcHBSuA0Qnts5OKvGRpS+RPzyIw59Q/acRjhizSHFG31/0SxObGf nbdMXJ4a/dLCzIMQ/NkUvMIkOyY9IS31+N8nblwJjM6HF5Hp08uOA7v9SwTA+99wUTqS ZbfVmGarCysGxbr1sdGaRED6HOPnDmdW5OrcliXCyJim7NbgecHZIzpWyvvo2zarsCQ3 7SOXgNH96pCCSyGMAhRII0ALOMweS52BPSkmiecqYuOYYYk/jBjeGITqnbX+IAVP3dEi 1vzlDaSbtyuZEv2/B1sHPs8Nsw2M/VPQq+sYTLla4WUFEIRpkzbQyXGb8Fy7OnljyB7t yTgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="v1GKoBc/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id f7-20020a056a0022c700b0068fd7cb5864si3067895pfj.263.2023.11.01.20.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 20:26:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="v1GKoBc/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 1B14C807D999; Wed, 1 Nov 2023 20:25:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348352AbjKBDY5 (ORCPT + 99 others); Wed, 1 Nov 2023 23:24:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348366AbjKBDYw (ORCPT ); Wed, 1 Nov 2023 23:24:52 -0400 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B6D120 for ; Wed, 1 Nov 2023 20:24:49 -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=1698895487; 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=IPS3iWC0ordY9Z/gFrasLVfoOU0ee6NMzPFkJtmjEdA=; b=v1GKoBc/GWi/6wA+3MMyQ6L15tftj7e2VTfNMKRmvlXo85TA0YUcUSnVVJ8Kga11asCboO btJ3b5nOE+cya1I08GWukxT+lICauUTNrau2aealf4F9CdmRScWkmlPsoHeV6UcabxAXZx LYjHaUg928T27sxO5LCHMigYm2gu+Xw= From: chengming.zhou@linux.dev To: vbabka@suse.cz, cl@linux.com, penberg@kernel.org Cc: rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou , Matthew Wilcox Subject: [PATCH v5 3/9] slub: Keep track of whether slub is on the per-node partial list Date: Thu, 2 Nov 2023 03:23:24 +0000 Message-Id: <20231102032330.1036151-4-chengming.zhou@linux.dev> In-Reply-To: <20231102032330.1036151-1-chengming.zhou@linux.dev> References: <20231102032330.1036151-1-chengming.zhou@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 01 Nov 2023 20:25:17 -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. Suggested-by: Matthew Wilcox Signed-off-by: Chengming Zhou Reviewed-by: Vlastimil Babka Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slub.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 03384cd965c5..eed8ae0dbaf9 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2116,6 +2116,25 @@ static void discard_slab(struct kmem_cache *s, struct slab *slab) free_slab(s, slab); } +/* + * SLUB reuses 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)); +} + /* * Management of partially allocated slabs. */ @@ -2127,6 +2146,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 +2161,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--; } @@ -4833,6 +4854,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.20.1