From patchwork Wed Sep 20 19:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13393226 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 5F3C1C04FED for ; Wed, 20 Sep 2023 19:03:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4BE86B019E; Wed, 20 Sep 2023 15:03:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFCF66B019F; Wed, 20 Sep 2023 15:03:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C751A6B01A0; Wed, 20 Sep 2023 15:03:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B3A4C6B019E for ; Wed, 20 Sep 2023 15:03:19 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 86808B3EA1 for ; Wed, 20 Sep 2023 19:03:19 +0000 (UTC) X-FDA: 81257898918.07.FE11983 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf17.hostedemail.com (Postfix) with ESMTP id 796D640030 for ; Wed, 20 Sep 2023 19:03:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=N6okLFhm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695236597; 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=SXDXLfwQ0rN/NkRQHGcA+48P9cgCCQ47pt4nGg6amro=; b=LSS47t4Q2VkDaqS+2eN5zSblamW1CZ12QAoXec0Sk5gJi30rB+dYKRcVQSJ/Cbl8S9OsLR DL+jJzJSSDRwXqH8fwW7aMNSCkrmJkKrsA/dhiN1fZStV9jnPQFd2IICoJ1Jfoo8s1rMXW op/Z7Pz89HcvVOJhpLIqk0HSRPaUPZY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=N6okLFhm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695236597; a=rsa-sha256; cv=none; b=G8JAB9elmOHYwSJ4IeZnHbTWFCCclodMu5zk5uHkLQCNcp4pT4aD8h7FP059SVttMybKCl w9Xkbod585iBGSSmRWfCxyUyFIF4prkxw1oX52QWtzbiJWMSXLMHk3WzTXt3XSoU5ycdmE 57jcKeruclD5zo34DtKW7opFNjZYNlo= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-68c576d35feso105297b3a.2 for ; Wed, 20 Sep 2023 12:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695236596; x=1695841396; darn=kvack.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=N6okLFhmeOhgtBWpAWqc8lbPkEAJEFuCe+fUn0eEqgng0ptDjxBmPQWDdPc5IBG2x9 k43zsL/dC3m5MG48N3xTyED4wkDgHezFvuOcuIHsyFz3o7LdBk5xTmWIl7xbzUu83HQG OdNtbax2bpCPcuItOCePPZ7hzLoi+zRwbU+RcFCF1ksEL6UCv4fHhCYnlkpaQEVbz/Tn 8IF2ug0jnEZ9/lP71DVhFCF+kVsRPjoy5P0nQzmucOUqbuvlpDCcP1eR3YEDfeOJZiqm OjMhhd7yuZamNq4aZBGRJSk6fjdtl+CSL6/xKWp0xhXrCX4VS3J1+iXwgN0SJrxg2uod dKLw== 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=ka//SUFNX6zaG7Y536Rh7vF6UoWe+R3Q2TuuSFNUOaTV6leHBRlakAUFXMk5Iw7fbJ UXC7sU294DU5Ind9jn/9E/+EskCfaT2+2Z+eMAiKHnTAEf/tEeR5oguLcRotrDkR4z/l e2InYIK3ewLxi/Fe8Ym8+AbjU26Dnkw+E4uBhQQGj0YWIO+gg5mqnC2MVc00m7bfPG21 1TcIzrUQcaugyumRUGQfo92Z/eEq/DKC0Bnhnri6APB1YiwMpgagdpLuaGEaGJ/6ilQw b8PKquORL6qqgr1kq6d2yMIuIXwwASK3WlrPzMcirBkkhK2s6PWN64pbUg5JAWcH8sQ3 5uWA== X-Gm-Message-State: AOJu0YwbvOhQA4L4mzxWGpq3CY5ir16pRcYV1ahbxTbvQwSMfeO7s9NN jyNH21fTIgo4MSWjqhoGZh37bfYkENbpntqB 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 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 796D640030 X-Stat-Signature: ndjxgaibjxaitkrs1tz3d5y4zpmpbwd6 X-Rspam-User: X-HE-Tag: 1695236597-467355 X-HE-Meta: U2FsdGVkX184lLYaWuHYSRg2y65FplpMkw5UfFkZbwXsUPIYlw6hl2+hCIN8WvDLbbvfOnpyJ22dV7y0u8OtIKCCb5alThdzCX5Kv3icjsfs5TomLUK3bfscnTWgF/pHrddCYq06NuANcnnCzvB6txEY1jxFnEIHMA6ZangnuiHNUjHzOPclSJgSbOPhKIpiGe4+Hu9r69NjC/e0J0BXMEGAafy7d9ZenFMSuGa7Yeq720p3J6C6IgjGH7qdKMjNb3CkG6Agkh2lSDAiSt2cYDTPnqVO/shpGDz6kFgReWVvAshrjlTT4NM8Vbjdr9Cx5rU3YlmpPo5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TKSqTWK2LHT4W0b5i2t0N9eURItOrGYK9zx8fFOBFgRupCd1BWMr3ObLk0X2vnF+H5p3nl1VQepvPVEUo35qK6Nez+aw2UTD6bx9wCxiznFFdGygGfKudNQnt3Ut716o36S7ffL0H5oIA6l0lmwytafhu5LgwQZBGjTwz2+rAreSs/xeUrkMWJ9nUkkwZAdvETtpM8xjF+FpdBcxqV5LU+UVtu9dIMFeKEBCn45vquieF2a9c2woaSxHc0oWB339b4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.019762, 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 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 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; @@ -485,9 +481,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); /* @@ -511,6 +504,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_test_refault(eviction_memcg, eviction_lruvec, eviction, file, EVICTION_BITS, bucket_order); }