From nobody Fri Feb 13 21:25:59 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EC6CC04FEC for ; Wed, 20 Sep 2023 19:03:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbjITTDa (ORCPT ); Wed, 20 Sep 2023 15:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjITTDW (ORCPT ); Wed, 20 Sep 2023 15:03:22 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E710114 for ; Wed, 20 Sep 2023 12:03:16 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-690fe10b6a4so102325b3a.3 for ; Wed, 20 Sep 2023 12:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695236596; x=1695841396; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=SXDXLfwQ0rN/NkRQHGcA+48P9cgCCQ47pt4nGg6amro=; b=RJ1kj3AYzz2QIU/bwzofj+d1kQ2pKduwjLvL5WXNyEGsaCvlz70hIxigGzPKTVe+by KVqTTMG2SZE7R0CT3cppjf1ig1PxwPF6W8EcJFvZ12kS1k70XCeCDhBxH3M3kyH4HgY8 C1aKCRSUeUavnWPPnoNpSCvBnVZbXQeyaidTi7F+Txq9RUL60FHMWNYnbpWfENeClX3W QS3mkchiczt9JyggWgPi+rhZCEkgP6SqkILUYyrdz5kylbJliI8qYOeprf8LdFGPhsFX TL+QXby9omSt8bJ5vEx4c2CtPh9SxQkweEDhMPfW8WSAeY+FBf5JuO7NaBbGBS/Xw3P8 tEsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695236596; x=1695841396; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SXDXLfwQ0rN/NkRQHGcA+48P9cgCCQ47pt4nGg6amro=; b=FIBnWVjZfJRl/uDMu1kLXqRgq6KncufZO5IBFt1Q7KWmlGjEXRtcimwM2rdUwSY3g+ qQdMvPsjiuxJuToMXPFmnA/m3vimixgMDT6Xd2i7OqxjsbFtGPSWLEOTXsIitaBXhKA6 7DO7qxxoZw5wClXFfgQ33xENPSFeWD/nj0CuennlItzLPL/eR2YC69yfXoH7Zdkt63oE sOgYT4c1Jv03l0lq3p+dLP9X1c/dIbsi0XoKDs1NaaUVxRBzqmBVUqMhgRpLs8hzi7Rb IC/PZC9/eCBwLPgVfofnLuVY1Neny653Bf1u4RrH2/zgO3Wab5g73tv9IXjljDugRrSF WMAQ== X-Gm-Message-State: AOJu0Yyi2mChiOv0OL4DxlVynuRpt7BDglxjjUwYfDvw1ROPtIpzK8U2 k5Zkq84Cb3gMc+b8+cUd3W/FeZ+YfIoy9uVJ X-Google-Smtp-Source: AGHT+IHFEuC6SGjGqdSNIHcpHwYS0ynMnc6+JDELyo8UC6MldIkjr9cwZSbjF96jMoK0A+wcrc6SDA== X-Received: by 2002:a05:6a20:1002:b0:141:d640:794a with SMTP id gs2-20020a056a20100200b00141d640794amr2885144pzc.39.1695236595707; Wed, 20 Sep 2023 12:03:15 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([124.127.145.18]) by smtp.gmail.com with ESMTPSA id m5-20020aa78a05000000b006871fdde2c7sm423935pfa.110.2023.09.20.12.03.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 20 Sep 2023 12:03:15 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Yu Zhao , Roman Gushchin , Johannes Weiner , Michal Hocko , Hugh Dickins , Nhat Pham , Yuanchu Xie , Kalesh Singh , Suren Baghdasaryan , "T . J . Mercier" , linux-kernel@vger.kernel.org, Kairui Song Subject: [RFC PATCH v3 4/6] workingset: simplify lru_gen_test_recent Date: Thu, 21 Sep 2023 03:02:42 +0800 Message-ID: <20230920190244.16839-5-ryncsn@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230920190244.16839-1-ryncsn@gmail.com> References: <20230920190244.16839-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kairui Song Simplify the code, move some common path into its caller, prepare for following commits. Signed-off-by: Kairui Song --- mm/workingset.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index 278c3b9eb549..87a16b6158e5 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -323,42 +323,38 @@ static void *lru_gen_eviction(struct folio *folio) * Tests if the shadow entry is for a folio that was recently evicted. * Fills in @lruvec, @token, @workingset with the values unpacked from sha= dow. */ -static bool lru_gen_test_recent(void *shadow, bool file, struct lruvec **l= ruvec, - unsigned long *token, bool *workingset) +static bool lru_gen_test_recent(struct lruvec *lruvec, bool file, + unsigned long token) { - int memcg_id; unsigned long min_seq; - struct mem_cgroup *memcg; - struct pglist_data *pgdat; =20 - unpack_shadow(shadow, &memcg_id, &pgdat, token, workingset); - - memcg =3D mem_cgroup_from_id(memcg_id); - *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); - - min_seq =3D READ_ONCE((*lruvec)->lrugen.min_seq[file]); - return (*token >> LRU_REFS_WIDTH) =3D=3D (min_seq & (EVICTION_MASK >> LRU= _REFS_WIDTH)); + min_seq =3D READ_ONCE(lruvec->lrugen.min_seq[file]); + return (token >> LRU_REFS_WIDTH) =3D=3D (min_seq & (EVICTION_MASK >> LRU_= REFS_WIDTH)); } =20 static void lru_gen_refault(struct folio *folio, void *shadow) { + int memcgid; bool recent; - int hist, tier, refs; bool workingset; unsigned long token; + int hist, tier, refs; struct lruvec *lruvec; + struct pglist_data *pgdat; struct lru_gen_folio *lrugen; int type =3D folio_is_file_lru(folio); int delta =3D folio_nr_pages(folio); =20 rcu_read_lock(); =20 - recent =3D lru_gen_test_recent(shadow, type, &lruvec, &token, &workingset= ); + unpack_shadow(shadow, &memcgid, &pgdat, &token, &workingset); + lruvec =3D mem_cgroup_lruvec(mem_cgroup_from_id(memcgid), pgdat); if (lruvec !=3D folio_lruvec(folio)) goto unlock; =20 mod_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + type, delta); =20 + recent =3D lru_gen_test_recent(lruvec, type, token); if (!recent) goto unlock; =20 @@ -485,9 +481,6 @@ bool workingset_test_recent(void *shadow, bool file, bo= ol *workingset) struct pglist_data *pgdat; unsigned long eviction; =20 - if (lru_gen_enabled()) - return lru_gen_test_recent(shadow, file, &eviction_lruvec, &eviction, wo= rkingset); - unpack_shadow(shadow, &memcgid, &pgdat, &eviction, workingset); =20 /* @@ -511,6 +504,9 @@ bool workingset_test_recent(void *shadow, bool file, bo= ol *workingset) return false; eviction_lruvec =3D mem_cgroup_lruvec(eviction_memcg, pgdat); =20 + if (lru_gen_enabled()) + return lru_gen_test_recent(eviction_lruvec, file, eviction); + return lru_test_refault(eviction_memcg, eviction_lruvec, eviction, file, EVICTION_BITS, bucket_order); } --=20 2.41.0