From patchwork Sat Dec 7 22:15:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13898422 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 ACFE6E7717D for ; Sat, 7 Dec 2024 22:15:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A97F6B0362; Sat, 7 Dec 2024 17:15:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2591E6B0364; Sat, 7 Dec 2024 17:15:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 120DB6B0365; Sat, 7 Dec 2024 17:15:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E662B6B0362 for ; Sat, 7 Dec 2024 17:15:31 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8D4DC120315 for ; Sat, 7 Dec 2024 22:15:31 +0000 (UTC) X-FDA: 82869570252.02.2EE520E Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf20.hostedemail.com (Postfix) with ESMTP id EB7881C0002 for ; Sat, 7 Dec 2024 22:15:09 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QEP1HRls; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3AMlUZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3AMlUZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733609712; a=rsa-sha256; cv=none; b=YA5jTk/m7Eq94y7u3aP18Ws0agFyKgFE0xClIPMOrZ+9sZagSOr2UEOM+y00C4m3b8sTJ8 ekoSyJoBGRLM0RHxNkfzu7pq1F0jL3h5SV0/f/X2K4Uk8IEgPnyUXrNdKI5dJhJTXPwJR9 tAK77gczzVLyXVeURH0vtazVMPsshsU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QEP1HRls; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3AMlUZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3AMlUZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733609712; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gY9A2hZ07C4gph5EkXou5eK7gRFH6gXGFcx+0iC/Exo=; b=O+14OzPN1H1GeqTSCBU+tCGhoHFRDpBanPLAVBEQvzzg0FmqlL2D0vzq5UNh6zQBg1uH7n 1oSiAEAZtnx7OdkAILGmxviitXcr7PVhnDuKAjx/l2VnGV4/4HvJsxqwEuTZgxIdkaBb72 u5F1dR2LFx4XEJFO57T3w5M7VUv9GJM= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-725e4bee252so58807b3a.1 for ; Sat, 07 Dec 2024 14:15:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733609728; x=1734214528; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gY9A2hZ07C4gph5EkXou5eK7gRFH6gXGFcx+0iC/Exo=; b=QEP1HRlsyp9QdogPiYqlydDr7XSW6Is2BQSS1y2uq4vjTjuQgDrD3AhEln8YB+v1zG v1Zt0RhjsP0tFWfO1lZByxx2ZZhR9/+98wkextSb+QKwZT31SHKge+RtnKpdCsJkJ5nn YgE8rh1/1+uXCA6CRrgC625FPDpGpapO4QtLn4fe7azldZdPsEjbzX/y6JN7sBsHmDTy yzdE6nx3EnjEEQhJGAdlofoxx9bM78UYx74PJfF2KJ0G0SL7qXl98Dw/fZOPJT+c4ael K22dXpBkFzLoH3o6fJs3dBkAEas4uWTGT5xp0fvmLMAnH2mM5IHrjOF/XVEFGiEnTR0n 8tAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733609728; x=1734214528; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gY9A2hZ07C4gph5EkXou5eK7gRFH6gXGFcx+0iC/Exo=; b=TuzJHhdwfNWyMoMJhmDwRw2Ks2VOYbDP+O9znM5i2Uku53iQK4UiGOQ8OtmXObvL95 QjLwlO0ntkaWxY31EwL0loMyJSf7RfF9Ounwob6N3i1wgJ96HuLo8A+L37cDzr2n4EvV T6hGD2kjkpNs/atWQ59sUChgI/quiQ3dbQMGm5O+LXSzlz0iesDQgvxmqkWYS+rSahTa aharr5BoRBZE1Jk7tNQ5m8ZnQRkysDfZmf7rzvleuWCIRrdstQlHv+5clcJcpE+dgnu4 y/wDKVRhadBTTOX9ek7bG1L+a/IuiKE9wJrF1br5B5f5Xwqrjl4zqBS+AyQbEUTz8RDg E3/g== X-Gm-Message-State: AOJu0YzTtuarMGsVjX59NVhVYhaCqe0aqLw1sYcV41N0/JrfuSqUa+MU K14STZkkF1vSayy7TTiZTgKeEFMyA4Kqur9t6r2yoIOqXemSK966yzAeGQhGT0dgeeO/f4WdRgJ H5g== X-Google-Smtp-Source: AGHT+IHCXiEm/R2rY0sBQTBrLZxsmJB5U1ibMxl9sF0XXm74TaiiQnoh1RCoPUcB5Jt5hjXX9XZSsqYn8nU= X-Received: from pfwz36.prod.google.com ([2002:a05:6a00:1da4:b0:724:f614:656f]) (user=yuzhao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1911:b0:724:f6a2:7b77 with SMTP id d2e1a72fcca58-725b81a3eb6mr12675093b3a.17.1733609728505; Sat, 07 Dec 2024 14:15:28 -0800 (PST) Date: Sat, 7 Dec 2024 15:15:17 -0700 In-Reply-To: <20241207221522.2250311-1-yuzhao@google.com> Mime-Version: 1.0 References: <20241207221522.2250311-1-yuzhao@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241207221522.2250311-2-yuzhao@google.com> Subject: [PATCH mm-unstable v3 1/6] mm/mglru: clean up workingset From: Yu Zhao To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , Kalesh Singh X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EB7881C0002 X-Stat-Signature: 9dazb41o7njubgxuqa9msdpkqabkfmgt X-Rspam-User: X-HE-Tag: 1733609709-84567 X-HE-Meta: U2FsdGVkX1+u4LEPntNiR41QX3C+3/jd56YXZG29j7pAy9inw9t4da8XhnTdPW4CpR92ymvwm14ejbkKFXtxYQrsMAm68uTQKAo2JYXv/teCs5b9S/tbj22TNejjoun6Su4nQordbSSDYmBkOCGUQtt0W/Q1H7BUTM4hzKRmR7VK6pLVR0P1xYcSVY6jJuDeR76sc/cfIvgo4DBVYyQ65URdMSKpTxcyIKQIwCOS6Bfkn3qPPon5jcyvgztfW6QtsRKuIGbcXsfxndALsBmNVivC5SX+ZGAIdjUVZkIHWdti6cmqATTVCM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GajK4IyN96Ok1ZiOX6at3SPSydKh4aj7a6MXBDZoOFxEgZdNtAb/s1ZClKny/gXgTHsIc0hVG+Xx9LtowizfBDEGCXHeuhKYfwTmoCFs1iAdFhwCZY0oYw9/OmyJKHtwq7dSSCBzWdk1ZQgDFRRiY7IxRc6IT3JJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000992, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move VM_BUG_ON_FOLIO() to cover both the default and MGLRU paths. Also use a pair of rcu_read_lock() and rcu_read_unlock() within each path, to improve readability. This change should not have any side effects. Signed-off-by: Yu Zhao Tested-by: Kalesh Singh --- mm/workingset.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index a4705e196545..ad181d1b8cf1 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -428,17 +428,17 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset, struct pglist_data *pgdat; unsigned long eviction; - rcu_read_lock(); - if (lru_gen_enabled()) { - bool recent = lru_gen_test_recent(shadow, file, - &eviction_lruvec, &eviction, workingset); + bool recent; + rcu_read_lock(); + recent = lru_gen_test_recent(shadow, file, &eviction_lruvec, + &eviction, workingset); rcu_read_unlock(); return recent; } - + rcu_read_lock(); unpack_shadow(shadow, &memcgid, &pgdat, &eviction, workingset); eviction <<= bucket_order; @@ -459,14 +459,12 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset, * configurations instead. */ eviction_memcg = mem_cgroup_from_id(memcgid); - if (!mem_cgroup_disabled() && - (!eviction_memcg || !mem_cgroup_tryget(eviction_memcg))) { - rcu_read_unlock(); + if (!mem_cgroup_tryget(eviction_memcg)) + eviction_memcg = NULL; + rcu_read_unlock(); + + if (!mem_cgroup_disabled() && !eviction_memcg) return false; - } - - rcu_read_unlock(); - /* * Flush stats (and potentially sleep) outside the RCU read section. * @@ -544,6 +542,8 @@ void workingset_refault(struct folio *folio, void *shadow) bool workingset; long nr; + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); + if (lru_gen_enabled()) { lru_gen_refault(folio, shadow); return; @@ -558,7 +558,6 @@ void workingset_refault(struct folio *folio, void *shadow) * is actually experiencing the refault event. Make sure the folio is * locked to guarantee folio_memcg() stability throughout. */ - VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); nr = folio_nr_pages(folio); memcg = folio_memcg(folio); pgdat = folio_pgdat(folio);