From patchwork Tue Sep 12 18:45:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13382047 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 7EC79EE3F0B for ; Tue, 12 Sep 2023 18:45:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16D776B014A; Tue, 12 Sep 2023 14:45:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 11F2F6B014B; Tue, 12 Sep 2023 14:45:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFF616B014C; Tue, 12 Sep 2023 14:45:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DBB846B014A for ; Tue, 12 Sep 2023 14:45:44 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B3B9880288 for ; Tue, 12 Sep 2023 18:45:44 +0000 (UTC) X-FDA: 81228824208.08.2F37B4F Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf12.hostedemail.com (Postfix) with ESMTP id BFCF24001B for ; Tue, 12 Sep 2023 18:45:42 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ary4hzCd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.171 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=1694544342; 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=9t2k/YGSbVN1+MHtdBH3OwcOic7suhow6uThzVwUsig=; b=8qbi2ckCnHMBaF1lzz7fEr7bzf0nl2FTuEpKHAVLoQK5av3hHaZmqPErdAKhnDxGgYKAEZ csgotIPHItE4Selqjmc+X1OAYGu4YURFELZndYQeaPoKgMfYTSdQytZpsrERbLvwX4cXV6 dDYQfi6y6Nln0wb5GHuozr0lk9Q2G08= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ary4hzCd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694544342; a=rsa-sha256; cv=none; b=dHgEDNuS1UVhVjwD56bqLqS4Ai2CTfT6VHxmN7n67pUAChV6nLjUxNQerfJLhatK1Bz3ev Y6tfM5ttFGTdMs/OECuyXQiXwKaARU3HGFpkP9f8vcOJAxMi5tsDOH7+nN9KsVWdzVKhgw H+Ul1ZQNg8aYWWjwZ0dvcBoOcKMG4E0= Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-57759a5bc17so2143530a12.1 for ; Tue, 12 Sep 2023 11:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694544341; x=1695149141; 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=9t2k/YGSbVN1+MHtdBH3OwcOic7suhow6uThzVwUsig=; b=ary4hzCdnI2MARhGFcZKYUGrvXKdctrMjPrO/hIwd+jMpAu493sF1BSCxmVAg4Vlc8 8m9MDc971HEGLMFrSgiSMkwOYB1U5/e0+l1W9PnUaa+cS6PoL8kpwIA4/Scyotlr2Fc+ 0HIkCafPNHRUBMXUxrVJi8CYXBrFgrTzjcLlueHIeBjmDeATSjLJVLsQ+gDmDvOCjKa/ thUQ24+Ry/lagnJ6VpO+EDWPK/VUHbVY6uAX1rwqlpTgPCdk3Vd0dbR/iMDhDOD1wyLF ZgExbPe/Aj+dSGY9UAK4wg5GcormaHnAZYaRFOl30hiTTygJCUvMuy0QyUT5FBLlK//s 5KBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694544341; x=1695149141; 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=9t2k/YGSbVN1+MHtdBH3OwcOic7suhow6uThzVwUsig=; b=rPIgmPrMWLtQ0m85UK/I1a4juL89jxOmw2B2iNZSEkHvMGG5mHlJ2MSxhuAfdkT+Kt rLOOei6L+f6O820UvgYgAJW9sAWSt5Rf9GAOmLmxkr/Q0oWllSmcB+CijcCPl0OcadvE XSzugDnsULgCN5mPbjytXGpXG8TN8k3NRU/g7f1ZcJYGBcWIY219zsx+cnZ/KJ95WuOO 2Pvu7v42WimyYE8OsIG9CubI22yYNKeF9YLWohQmvqWYjLgyxvoOdplLgPWhygBbfsVj jxXA0xMJPk8aSg3fU+ghT/buALPdb2oOz/+gLRGYGvXDgXpGJkUCt3s9XXU91TJrlZVi rcaQ== X-Gm-Message-State: AOJu0Yxj/6XK2HnU9TiRuiT3I9nCtCVpBjliz+h5w6bmVrXPUiQNhS9x nkkWLlHIMczcJpE3Rc7ld7r1UmzXEcK7ZrpaSVHZhg== X-Google-Smtp-Source: AGHT+IEAuA4/F1B0Lt9LeFUVwDamYyShSMqx6Vqa1EAIDmY4Te7Z5WUkjLcK04QCzmySN/XdckjO9A== X-Received: by 2002:a05:6a20:748e:b0:149:7fea:d89d with SMTP id p14-20020a056a20748e00b001497fead89dmr230203pzd.54.1694544340991; Tue, 12 Sep 2023 11:45:40 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([124.127.145.18]) by smtp.gmail.com with ESMTPSA id q18-20020a63bc12000000b00553b9e0510esm7390605pge.60.2023.09.12.11.45.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 12 Sep 2023 11:45:40 -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" , linux-kernel@vger.kernel.orng, Kairui Song Subject: [RFC PATCH v2 3/5] workingset: simplify lru_gen_test_recent Date: Wed, 13 Sep 2023 02:45:09 +0800 Message-ID: <20230912184511.49333-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912184511.49333-1-ryncsn@gmail.com> References: <20230912184511.49333-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BFCF24001B X-Stat-Signature: 7y6ayiyfkka5tafwakjkd7oiifb3bf18 X-HE-Tag: 1694544342-875004 X-HE-Meta: U2FsdGVkX1+d/mgoj7928yMAsVBv51h43SAUELBNLvOcHeo8f2i284ihrB1iC24ODi44KNkp7PE781HxTglu+tC3qn4XK7Fs1vI/f2Ow39dL5sQqf/D0Sc5oxucxRZsvTRq750K4xBOnR/Fe5HR+6g6ljvYYf9VHIRcucQ/VbvJWHfTk9HyEcHMAS6ojrfQP+nv0FcU2uxue+Yb5/IOUZOSjPoyfVDYUAuQeICBRvOQcEl/6AS75YD5Aiv/tzAQdDdhERZs8POzqJnsKfrSGD0rxZpshQu5+UaAw9h8A1fIdp/vZ8p7IyvxNZGNYcc6q5na2gZQjuEv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EzdlhRX+qrgTJkmep/rWKIt72yQYUBgmYVzCzKN3e5VnGiTer1hf+quV3dsqwaNHI4g5utyRXfwXhXFzFzvLqyMriDCxHEP9jw5AAozHG/P9EPletfnEJxolU9IQC+aytGilt1CmFzQSeTnH1MsjuW0swRIee1lwIhbyZuZCFkbwkLeJK7jB/trTeH3cdEV5ee7FFZyoMbnJKXfknVQW7xyMgu4yGYE498Vkxe6T3/ksmFbph8RJ/0yJwbY7L0wrwrHm8rsljPFlI4hhEyWrTT0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.005164, 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 b5c565a5a959..ff7587456b7f 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -345,42 +345,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; @@ -480,9 +476,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); /* @@ -506,6 +499,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, file, EVICTION_BITS, bucket_order); }