From patchwork Fri Dec 6 00:31:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13896155 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 5E963E77171 for ; Fri, 6 Dec 2024 00:31:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D82EB6B0122; Thu, 5 Dec 2024 19:31:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D316A6B0126; Thu, 5 Dec 2024 19:31:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BABEE6B0128; Thu, 5 Dec 2024 19:31:37 -0500 (EST) 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 9816F6B0122 for ; Thu, 5 Dec 2024 19:31:37 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 24C911C81BA for ; Fri, 6 Dec 2024 00:31:37 +0000 (UTC) X-FDA: 82862655330.10.4B2D85F Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf22.hostedemail.com (Postfix) with ESMTP id C1706C0009 for ; Fri, 6 Dec 2024 00:31:17 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FeCQUqYF; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 35kVSZwYKCPs1x2kdrjrrjoh.frpolqx0-ppnydfn.ruj@flex--yuzhao.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=35kVSZwYKCPs1x2kdrjrrjoh.frpolqx0-ppnydfn.ruj@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733445087; a=rsa-sha256; cv=none; b=fLhHkBqdxcMM+pM55KyYRYl02bSQnYHeCt/dHP9VtHGt651RCbDYOAKaf27tl8PnGts2sm pZgn0u3F3dJ2aa/TCr3ULCXsNHLS4I03u8yvx9rJHH4h9RwaHJuj7A19EqqeiS6r20wd2W jhBIZ+JWxnta3tW9itGrQ7ZaA++VXeM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FeCQUqYF; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 35kVSZwYKCPs1x2kdrjrrjoh.frpolqx0-ppnydfn.ruj@flex--yuzhao.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=35kVSZwYKCPs1x2kdrjrrjoh.frpolqx0-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=1733445087; 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=1SqX7QIgiKZesXHlSwCnSo0CRZIrCnW302Nl66sa9nmsEMBHRXso4iBS7ebMr9azvIvVQB mPQiJLRJxuDR1X+TghAaZnCW0H43bfzQIGPd2q2nLpRjSGuVdEyXt6ppCMP9W3cEEk4Qmx dhq1uouUjHILgmhBTvEW9Hal7AU3KcE= Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-725a30c9a35so903547b3a.2 for ; Thu, 05 Dec 2024 16:31:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733445094; x=1734049894; 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=FeCQUqYFwgw41nYw6JVdGyw/g0jTeWBE9zUBrAyxcGd9q1LNB5eCAA+APkdpss6Pcy ugCCV0nMbNaaiPgNeB8KSDx+p9X6BdJ4YVM5rUu4zOiCjQPwJ5sFyAg859DD1g0xIKb0 N7hi+vPSxMWPToo99s4r71CbYz7EcoZHQ5sKVKavYnNM1wYf3elpKc3E8+U50zaecCPi +wmXi5SWRyLFZ/M4OPwHWUHT2QA8myIbENRuUDYjOLb0tfNz6VDsBgLBUuQOfio5wK4k qgp9cpZbJRzdb1iUdORCebG7HcMVP0VCQ/+c3FWQsbqzjhONKk8z5DIWoIfE41pC9BYr OXfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733445094; x=1734049894; 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=DtxxLTyR0OQ3qZACfjxYUdn7hBbYVhlnZi9z9pd8nxMc0r4hPbgyOq1EjDqmgJYjHN i1nQ6fsBo8gwN7wz/iIivqHVsogVG7FxLDt7hRRxON18//nRDf2qKJIaaHH2uSN3aG5R YKiQuvsb0vPg5usWa4u+UJ3SeAZ624QouZUy+kAEqyqTp9nEFFOm6pZyqwRDzMNDl9/p 0tnj4V5yffSeYDkmpJWN4ReoxxKdveqVg1+pChsFb3eIMGnejHhzPhRUQi5TEZ2O+NDu sOTQGjAp2TvwjIcT08HfQKduiWbV3WhCwSwVVSwUj0BNzlWrY/0rnDmKMVNQ9qSLjl2t Qlaw== X-Gm-Message-State: AOJu0YyM0pey2idTgWZik9gyCQPWRL3lNL3xnAgXfqinaJDR/Guf7Xl9 eh/rpY3NNWJxKfkITovdZ5aGUIKiKvDUA+skR4bhNuHQ9kE22OXrGQUydsjZ0XmDuv8CEoh4ab+ wAw== X-Google-Smtp-Source: AGHT+IG6Au9pfRghDcM8iM0cy1enSAIDDkXjALs9OLLc2AlZ1mMtncq3AmviK9jGO8YbyJSyYoHMLUHAqO4= X-Received: from pfbc10.prod.google.com ([2002:a05:6a00:ad0a:b0:725:8ee5:e458]) (user=yuzhao job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:8d6:b0:725:8f15:f897 with SMTP id d2e1a72fcca58-725b80e4a9dmr2046628b3a.4.1733445094214; Thu, 05 Dec 2024 16:31:34 -0800 (PST) Date: Thu, 5 Dec 2024 17:31:21 -0700 In-Reply-To: <20241206003126.1338283-1-yuzhao@google.com> Mime-Version: 1.0 References: <20241206003126.1338283-1-yuzhao@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241206003126.1338283-2-yuzhao@google.com> Subject: [PATCH mm-unstable v2 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C1706C0009 X-Stat-Signature: 6onarkzdxamkuogaywbmagazj7w1nqy9 X-HE-Tag: 1733445077-123279 X-HE-Meta: U2FsdGVkX19QxwWvfHY3O3d5h2new7d8ycHeAlVRD+Y80CGPjoZA7y3sT5ftfgv98BpKyHFdM24XzgOj+zE7rVN7zGZjQSBHsoj08Uub10zCJ30+PxGk5kObj9snIRqFeR6J60oxdBprlNEj1SDS6bWM4J9HwWqdTk74RMJfNMD5ZqreGsdrxrkLyyt0atV9cMkFi8Ee8l/mkS5uF3vjn4cCBMn1bo/fID5+RK83d0jtsZfA7dj68uGExcXDVnhyqcXdJbcxaa6yLhjUCUQPH2FedCv76BILkR6OULYXf45VamCeFSydDEWGgPSJPYO+y+uBIBgMJf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ILT0LVYeKu5EfO7zPUItsYnWUcfPOhlhvFy19hXt2pnqi4YrX0bxgyQriZjlTTJHHCeu63uQdg9umnEalfOlM0JcV0TYsJ/2Y7uOpaUkA7a+ZfXs+HNRkd+jzHC2LK X-Bogosity: Ham, tests=bogofilter, spamicity=0.006686, 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);