From patchwork Tue Jul 25 18:57:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13326949 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DD65EB64DD for ; Tue, 25 Jul 2023 18:57:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E25E76B007B; Tue, 25 Jul 2023 14:57:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD64E6B0080; Tue, 25 Jul 2023 14:57:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C773A6B0081; Tue, 25 Jul 2023 14:57:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B8D176B007B for ; Tue, 25 Jul 2023 14:57:51 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9160D40F76 for ; Tue, 25 Jul 2023 18:57:51 +0000 (UTC) X-FDA: 81051043542.01.3393BD7 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf11.hostedemail.com (Postfix) with ESMTP id 756FA4001E for ; Tue, 25 Jul 2023 18:57:49 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ezzYOc28; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690311469; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Yph/ZlbCl28tbkn0Iq6ks5vDDL2gwzA7iKSLMUU7U2M=; b=5HqxXNA9DhCGmznIMYdFE5FW+Lmg1NQITSyoNF7p/Kvyy7m1uFGedPBfSP2UziZ44ZRu9X rx7G2M2iD1zCAwwTR4i1wzhZh9ntXdTc8ywHDCCP8yAOLiResoXwB7FM2dMsV9L6NNaQCv wzkJItFlwgR6793c3K4ue5csVLoGYM0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690311469; a=rsa-sha256; cv=none; b=rzfQuRfmDs+3ji5RxyOLhi7M4f1N77Kbrg9U5mH26fCL0WoCQdZLJND0rYZdT8NA1PaNP+ hx4zRto52hVIfmqAdvg7OrjH+DiUKXOxrqV0bWTvUaQ70fgxIzjuRVn6juxDG39g11fLwo mrARVkEzyY6bGqkLoWePfLVXOcCqhS4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ezzYOc28; spf=pass (imf11.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1b9e9765f2cso30938185ad.3 for ; Tue, 25 Jul 2023 11:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690311467; x=1690916267; 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=Yph/ZlbCl28tbkn0Iq6ks5vDDL2gwzA7iKSLMUU7U2M=; b=ezzYOc285NqQ0TNbMdWpxvC1ToDwlZu0iYtsXbievJqp6wzVnZvQy/Ja0mvhvEmbO8 /o24m5x2ZQ5J2HlrcyGQUyJSHsjpfaN5PZmJKSWDvA9hPvaapz+RlaJq2KOQJN9RweeU PADYTZqSeT1hMTCMAyWbuv35kP9azkj1sHtXNC65XT3e+BBawL6T3l+bcS4HtL3nfs+a fq0rGXozbisod1W0GwVO5g/1KEtolR7I63NO+wiNdZhCRTMDEwKO6NGGbt9MZOeUK8eA 7UqUHZ8EFLILFN3hOHRX8ExkR2w8yZt0O7GOvqlbkUh5jv7DUIaDgeR7XfGPx+34xUQU pFpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690311467; x=1690916267; 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=Yph/ZlbCl28tbkn0Iq6ks5vDDL2gwzA7iKSLMUU7U2M=; b=TqVJWFhcSBW3ZmBQR6VT5vfUOx/5vefkFyt/cxQHiXaHuQnIl/RrXpHfnLUP7RIJYJ iezViemq/uB5bhj0W3waITC6jEnn0+yyMcxFlYZ859qlwxywkIxIXZsY+mBVMkqVAoaX haCQkfKqr6AcJwAj2yFC/0b++bDMzH0o3bZDLOy5Ho+XlAXy4TcCWNkD67X1krFhHrxB iockN18yvT6oSc+fEPr59E0Z9KrsSH6EWd3J/E98iNlz8IC+VtkQO+7vukgrzPteGPQk BNw5ncWKlpvRWJjjz9o4XSOb8IP6kM9O92cCWo2OKtTGglFn2di8fl/lkmcStib219sE grVg== X-Gm-Message-State: ABy/qLbSPm+GgoD2yA0I9ofvUnEOTElVE2hKeROq1rxtvEHszGCbZzGs I7AQzLQ4EVvoXcnHCrIe/dHB2soMuoToUj842rh/GA== X-Google-Smtp-Source: APBJJlEtrcJe4CtotFOxB3ORWHUUSl/kexVmRP7Y+qoCEdP25Wfgf54RYq35V16lRYJQLQt2t2VfrA== X-Received: by 2002:a17:902:728a:b0:1b9:dea2:800f with SMTP id d10-20020a170902728a00b001b9dea2800fmr42799pll.8.1690311467409; Tue, 25 Jul 2023 11:57:47 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([240e:306:1582:8dc2:70ef:4d19:edfe:c3a3]) by smtp.gmail.com with ESMTPSA id j17-20020a170902c3d100b001b03f208323sm11443150plj.64.2023.07.25.11.57.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jul 2023 11:57:46 -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 , Suren Baghdasaryan , "T . J . Mercier" , Kairui Song Subject: [RFC PATCH 2/4] workingset: simplify lru_gen_test_recent Date: Wed, 26 Jul 2023 02:57:30 +0800 Message-ID: <20230725185733.43929-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725185733.43929-1-ryncsn@gmail.com> References: <20230725185733.43929-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: 756FA4001E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: kaej3puqheu9bike5rnzqdtjhmcwuj1i X-HE-Tag: 1690311469-386961 X-HE-Meta: U2FsdGVkX19n+0/grLcQruuZp93UVRHx2lB3ZcNxaN/XT0SFAUC5qvci8f+Pdr6IaQ3uxHhoF69oga+2NUvLLwjPLxL1UmNiv9tUsKFeAWl4Z2ZPvuC3G1gVlODEFNIARVQw6FiGLaUsscgecZjPrtVqbG8Ji0zLHPwEtM/9t2ee20VfzPFEegfvClByYo5GAxBeERxUGsJU7CSzw55VM50Lc5lyHXpiqesbazSR73fsXlqZzJYNt49+0Zi3mB7MmS4OIKttwCUVOJb6yeU/bLrQevqiEDBZB2LiO3zMIoisZHVCxaUUlxsjUuYnXXeBvo55OfMUKA+7V6ZXO1hK1fe4ZfD//neKHM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GgtMiLUO03BjySYlwgYOhKWx343ydY4zUYOCKBbRFv+W0Rp6vwtdqfz0D/t5rT+NT9+S1fKyt26a3xl9svrKfc83MKHDWKrZX4U4e2VWUrASFF1MfzFm1KXPbOeEvwf+xMSEEj1tKTVLcEbVEl6Yrl1a1Wv4EjDtVrmwQqA7dABRZUDIGdVa1Wf+0PVuBeEyfbZktHxL0hsjBy3DZhTQt6XxV46KEj+vZVQXXerkNrp72ohMWe+89LHEz7wFw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.088275, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 c0dea2c05f55..126f1fec41ed 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -357,42 +357,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 shadow. */ -static bool lru_gen_test_recent(void *shadow, bool file, struct lruvec **lruvec, - 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; - unpack_shadow(shadow, &memcg_id, &pgdat, token, workingset); - - memcg = mem_cgroup_from_id(memcg_id); - *lruvec = mem_cgroup_lruvec(memcg, pgdat); - - min_seq = READ_ONCE((*lruvec)->lrugen.min_seq[file]); - return (*token >> LRU_REFS_WIDTH) == (min_seq & (EVICTION_MASK >> LRU_REFS_WIDTH)); + min_seq = READ_ONCE(lruvec->lrugen.min_seq[file]); + return (token >> LRU_REFS_WIDTH) == (min_seq & (EVICTION_MASK >> LRU_REFS_WIDTH)); } 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 = folio_is_file_lru(folio); int delta = folio_nr_pages(folio); rcu_read_lock(); - recent = lru_gen_test_recent(shadow, type, &lruvec, &token, &workingset); + unpack_shadow(shadow, &memcgid, &pgdat, &token, &workingset); + lruvec = mem_cgroup_lruvec(mem_cgroup_from_id(memcgid), pgdat); if (lruvec != folio_lruvec(folio)) goto unlock; mod_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + type, delta); + recent = lru_gen_test_recent(lruvec, type, token); if (!recent) goto unlock; @@ -492,9 +488,6 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset) struct pglist_data *pgdat; unsigned long eviction; - if (lru_gen_enabled()) - return lru_gen_test_recent(shadow, file, &eviction_lruvec, &eviction, workingset); - unpack_shadow(shadow, &memcgid, &pgdat, &eviction, workingset); /* @@ -518,6 +511,9 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset) return false; eviction_lruvec = mem_cgroup_lruvec(eviction_memcg, pgdat); + if (lru_gen_enabled()) + return lru_gen_test_recent(eviction_lruvec, file, eviction); + return lru_refault(eviction_memcg, eviction_lruvec, eviction, EVICTION_BITS, bucket_order); }