From nobody Wed Dec 17 21:39:25 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B03A215667B for ; Tue, 31 Dec 2024 04:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735619749; cv=none; b=rS9gKuhaz//ekMHoenGFA9WZPTyT89IxxcFxjOvQ1DyWExaVhrvjsSHntLrygjVp4KO4MSLeZYAvRYJNC+Z4YiY76XARBZP1hmdd790ZXV3W55CszAmQuUBBhbIBet7UR7QEMyXGs5EWze8YaFWdJY/XYpwZiAQ+7SJcxyZD4Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735619749; c=relaxed/simple; bh=RWveGCVh3Wwamff71MYhhhcXA2Seyh0CDZrRZOu7WKU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CJalck19qqH3bKKDimOeFBGYriQBeMPhzko6g69rwX0fidaSfCqDCh17a06FSS299OwRN8bayi+hD9K6XIvnIkGxs0ffoKbv7cA1B1t6Q3qN6LcYOTLXivnQra5sCR6nItJqGci4M9F2XTkvGOZbz18/yh5tLhHVzQz16QdNT2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuzhao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eZKkb/yO; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuzhao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eZKkb/yO" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9e4c5343so20994018a91.0 for ; Mon, 30 Dec 2024 20:35:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1735619747; x=1736224547; darn=vger.kernel.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=Xw2CHOQueA9zkMREwjqXXK1goFWTBSTiadQe8+3ME3M=; b=eZKkb/yOn6rf9G7nOKpmxbgziGt0QQkwECcnZ36D0nXD/B2aKh1/IU08S/H2yRh6YA RMxsw6eHqAOMW2oxiryQAgLiBwCSTP1xjGduOxI6KiIYlLF2650bkKdlNwFc6+vh2bHQ AU/St+Amo6UnRn4URUr6MAprYBwH5cCprXpPNKPoP/FG7nKWbTdEq1/oBGQzyVEC6OzV onOys8rqeKQDYZ+wuYosNqT9MSh8ERrbaheS/jTa39X+su75Gj4mULTAlbw4uvj5pfx3 wqYm7uYZdKJnhbHJ99vXFvujvVT5Ngib9JUmTMg0Pzxyq/87R4SR2PROhmlVjdMM01CX DPWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735619747; x=1736224547; 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=Xw2CHOQueA9zkMREwjqXXK1goFWTBSTiadQe8+3ME3M=; b=gfTqO6illo4P5NxDeZhRXbNYNFbvwgkPqKgy0UXQ23yrP5mRC2gen9vo1JNuKi9TWM Avwd0o3MRA+NlLDQWK2kcBi5NmuPdfJzpKNQFTi23Vn1+PMgShWSQP3Xp0uwApQ0uMNI VxVc9+YltgtOBcg+qRX4EGCZOJaF3BAjsPJ4H1JJp8VA849RMH5bzBHHM0DgcvXe6V27 XM5KdsrTtU+UWIsPoxrouoVQu9pbg4iU0gqiHmKxgBYng4dY5WccvrWXUNwWrryaDhOp 3tZTzM0hPIeR6QKT7gx4iZR/wzfH51enuJJyIadfbVuILJ8hKm8iO3n0mu1hsO1st28f 2Slg== X-Forwarded-Encrypted: i=1; AJvYcCXXxfhy8RsRBskm8BcH9TT46jJNTNT8jDbYcCsiY3DAJowg5KIlDUGUNF3TUYQjBFUS0HYrf1vEyFox/DA=@vger.kernel.org X-Gm-Message-State: AOJu0YxV+nqL9GJIBJhqgr7P91LZ/kJbrn2dfN91uRoTkRJoMrY48oCX C/cKA1iNRb4tsX5zRqTv1Z9gdnnTpJA6eQMrzZ9ZdL4h3nz/fLPB+Ko4b0M/qP4M2MAABIIVEur 2ug== X-Google-Smtp-Source: AGHT+IFqFvRA79cO3VpI5IoQ9FD/iueUtKICiJreOXklTdeZ0vkOif4CjJ0SLo91oWp/vZ2d3gnF2M2cOO0= X-Received: from pjbpw17.prod.google.com ([2002:a17:90b:2791:b0:2ef:94c6:5048]) (user=yuzhao job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:524b:b0:2ee:9d49:3ae6 with SMTP id 98e67ed59e1d1-2f452e1d12fmr56370216a91.10.1735619747003; Mon, 30 Dec 2024 20:35:47 -0800 (PST) Date: Mon, 30 Dec 2024 21:35:32 -0700 In-Reply-To: <20241231043538.4075764-1-yuzhao@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241231043538.4075764-1-yuzhao@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241231043538.4075764-2-yuzhao@google.com> Subject: [PATCH mm-unstable v4 1/7] 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; =20 - rcu_read_lock(); - if (lru_gen_enabled()) { - bool recent =3D lru_gen_test_recent(shadow, file, - &eviction_lruvec, &eviction, workingset); + bool recent; =20 + rcu_read_lock(); + recent =3D lru_gen_test_recent(shadow, file, &eviction_lruvec, + &eviction, workingset); rcu_read_unlock(); return recent; } =20 - + rcu_read_lock(); unpack_shadow(shadow, &memcgid, &pgdat, &eviction, workingset); eviction <<=3D bucket_order; =20 @@ -459,14 +459,12 @@ bool workingset_test_recent(void *shadow, bool file, = bool *workingset, * configurations instead. */ eviction_memcg =3D 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 =3D 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 *shad= ow) bool workingset; long nr; =20 + 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 *shad= ow) * 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 =3D folio_nr_pages(folio); memcg =3D folio_memcg(folio); pgdat =3D folio_pgdat(folio); --=20 2.47.1.613.gc27f4b7a9f-goog