From patchwork Mon Dec 2 03:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13889935 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 E0B83D49795 for ; Mon, 2 Dec 2024 03:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EB2A6B0085; Sun, 1 Dec 2024 22:28:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 69BD56B0088; Sun, 1 Dec 2024 22:28:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53D036B0089; Sun, 1 Dec 2024 22:28:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 33F036B0085 for ; Sun, 1 Dec 2024 22:28:34 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B08FA1418E8 for ; Mon, 2 Dec 2024 03:28:33 +0000 (UTC) X-FDA: 82848586002.19.4E50706 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 2E9341C0002 for ; Mon, 2 Dec 2024 03:28:10 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rRlDcwh2; spf=pass (imf21.hostedemail.com: domain of 3XilNZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3XilNZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733110104; 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=YI9pJYmiT6yhWgOStQUq5ByBL0UjIQ+Tzz4MUV7yG8BmtVFaT33I/lxv+IUvPSTImYN1OD cJBcUreyRND3u67y61/8Y7UZyJK7ZWGYxmfxJ6I4+d2t58jZypYBD8KQpAUWh5RaJP1NiC JfMTiEJchbom3pXAx7MWcQKgYUz1vio= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rRlDcwh2; spf=pass (imf21.hostedemail.com: domain of 3XilNZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3XilNZwYKCCcbXcKDRJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yuzhao.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733110104; a=rsa-sha256; cv=none; b=geWpCdHudKhI/XPtcFR7NCjkvvrf5udXGNH8wQB4DfEGr+2lCjrmo4TR7Bpl/xeHJQwGFI V1iCuZxYzzhR287HfUnoQs/0eEYk87yp5XG8x0qMd+iNnAcmim9ZAXAXJeONvUCwY8pXnU y3wOJJuuA8ZlBCTjCNAU7bkz931AeR8= Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2157145fdb7so12188145ad.3 for ; Sun, 01 Dec 2024 19:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733110111; x=1733714911; 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=rRlDcwh2p+jSJQvwfCkeIl2PuSwDs1Gevdtn3ukOU/OxN95Vbhy/r9bfEnngpN89Uh 4/GTthuTlszEgS+/EvPRk2fMsUUN3SB+2fJWTmWaLtAgNFM39L2zuuDmrqdKb6j1lcoY OBcbIVFm/lcPH7Gz35QPzdqmJWziFSz1FI968KDHOaBRwtjAzz/E2nA5s5P9TFbVGh03 TNC46gT6YNie5A+W9PoP81n+C1uYYHIbY8FXYCNcLcKt6yu2RKa1vq6f5LJ9qSptnqfO csBqxUOzIW59iSWorgOu80wGBSmSSfqDEMSP9+IILac+x7G/F9Ve/LGM/gR9ukjtl0XF Ij8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733110111; x=1733714911; 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=FdooTkm+VKUxzWBrWqYgjcN5e4makE0lA+gPykgfY//4HO7EljXNJe8F12f4IHDdy0 LlJP6gEbBOm+UHePv0izJiSnhw2HsBUOgI4mKeoru7xjZgxAH9W+HVy8dZxUhDVQzzE2 SqFMijs/HrKApMVuPyzDIhowAYxo0iS+it4/MkSmdjTbwkcnm0yVWMbBL0P7OYz196rr 17uZypOw8UB2t4BZ2ILBdKcdDUTF7jgvnCwYqtfq+Nn9k53qyprmXmSVAfQdmiFeeR56 kEXSSG+HvaSjpoIZTGTvK4YMy4DUwEh0fuNYBfaXkfjnpqDsHJdp5X0gBYAdIIug9Jq4 oLSQ== X-Gm-Message-State: AOJu0Ywe8dRwiB35h7TMHIkDeEg94B3E/kp0PPDXL1plPZRradvW47+Y XR+Qt/CJ1PdEJ6UiWfq/GulaSmWeM0nEMA6iwi4dgZkinjYYr/5Fx0x6FWsxF4+pLrDYNNSsKZ7 ikQ== X-Google-Smtp-Source: AGHT+IEqTdJXZQhb+wWTbmtYxN0jo2FTMzf/EWYgoLBGFBa+R/zRxwCYD577vOiuDbQ1RP0KS+rm7MbIVxI= X-Received: from plbll14.prod.google.com ([2002:a17:903:90e:b0:215:3fc5:cd3f]) (user=yuzhao job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e881:b0:215:7b70:79fe with SMTP id d9443c01a7336-2157b707c93mr79972115ad.32.1733110110727; Sun, 01 Dec 2024 19:28:30 -0800 (PST) Date: Sun, 1 Dec 2024 20:28:18 -0700 In-Reply-To: <20241202032823.2741019-1-yuzhao@google.com> Mime-Version: 1.0 References: <20241202032823.2741019-1-yuzhao@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241202032823.2741019-2-yuzhao@google.com> Subject: [PATCH mm-unstable v1 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: rspam05 X-Stat-Signature: 5txhb8ebxxsmhbz9ddqcxih9rahd9rae X-Rspamd-Queue-Id: 2E9341C0002 X-Rspam-User: X-HE-Tag: 1733110090-547721 X-HE-Meta: U2FsdGVkX1+txdxbQ2oyalWK39jqgQA8nkn0AR78vXISvIOxnT+RWsnps+YYizPV2hHGdCtt7wGgxIC3nzpLuKcHwrc5FU8MEQbnsVRo8lIj76Dy31E0lgYfe3CijqOgoIHdqUwD6XxhoZwa/bF6EFdwwHAfr5ey8JqDOqIV8a/4/aDl6Xv7D8I2m/9YHt3qCHpDvo/ZxDRNcjtcQ1oB5NqEO+yjv4XL3lK06cImdMaGiSuthDXn+SDGKy1snp4oDLBIaArcrWd01ifap/yY5ONVq/2X6xoI2YW3NIohIwP23e6URk8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jeHUpLTzcyzgZYcT6G4pfedxyN49F1sWgQ3alyxo4OiDbVFoi+/drtN2JZrMXXXvn5A9PDCzAnrC1lwQdNflgh6qryN8U4KpcV/xDxDrQRIqsY+Uwav6eUlyUVAXxhU7soXS3Cm2NqKSz8G5kc/bRC X-Bogosity: Ham, tests=bogofilter, spamicity=0.102394, 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);