From mboxrd@z Thu Jan 1 00:00:00 1970 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 8C209D0C604 for ; Sat, 26 Oct 2024 15:37:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E68916B0083; Sat, 26 Oct 2024 11:37:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E171E6B0085; Sat, 26 Oct 2024 11:37:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDE566B0088; Sat, 26 Oct 2024 11:37:41 -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 B06386B0083 for ; Sat, 26 Oct 2024 11:37:41 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3B76981795 for ; Sat, 26 Oct 2024 15:37:23 +0000 (UTC) X-FDA: 82716157524.25.AD06A2F Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) by imf24.hostedemail.com (Postfix) with ESMTP id DC2FD180013 for ; Sat, 26 Oct 2024 15:37:35 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=OjvguAeM; spf=pass (imf24.hostedemail.com: domain of yuzhao@google.com designates 209.85.222.52 as permitted sender) smtp.mailfrom=yuzhao@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=1729956852; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GanVEa8cxLQoFBTsvQcEmQf1/zCR9K0WFuLJ4NsXrxc=; b=dH5+p1UCBt8Qgl1+UYfJ2H8Qc9EIsUPZYu9OvwVu7/wz2jT7nCyijw2R7UdutPPi5JRSQz KG6ut8G0ImQdI8D1eb+ob/feF+3m1ejJsY1sfYIWKU7rYqn7ajJ1iBFG4pABg1jBmsueMH iNEJPmDShAPUy0LsY8FzZlkL7fZOXUA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=OjvguAeM; spf=pass (imf24.hostedemail.com: domain of yuzhao@google.com designates 209.85.222.52 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729956852; a=rsa-sha256; cv=none; b=VNUDVU2t/L+QjXMokHHi+HSTSgypAMuV/1n6+rmr2p9JhAGdnpmDXgXLR5WkAEJz3z7NQC v1Tvq4c4nDPgw6XLOLsndx3fc3AvW+U2Fv0I2Zz/+npzKrsOXXGloM5I6PBt0TWj3oahEX JC4BL79BF+YHTf3nv/evsra1XcJEqFU= Received: by mail-ua1-f52.google.com with SMTP id a1e0cc1a2514c-84ff43e87cbso824863241.1 for ; Sat, 26 Oct 2024 08:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729957058; x=1730561858; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GanVEa8cxLQoFBTsvQcEmQf1/zCR9K0WFuLJ4NsXrxc=; b=OjvguAeM3OwVAsEWgSmZ+gkkolae3y1+On+u6pwJOXyy5zQw0sX+cjlKE7VBaroxAt BQddzqwpWMBET9bnN0FWZf09dLtaHRyq01rtJCMvS9Db22Cnh924GcbCHduBldEviDrp vBWMZ8XAioAuzAO4d8Q/vrPwXgbt+kpY4KhwsjM93N0J90heRvOBTHWCIV42vp/4iyqc 4CmaU3R++gy/bvjLioJZ0gz6801hnnBbYGtOnFCSbMk8Y6GL4PpK/2LH6H0KS2S0okrb 4sri7FCcSc7imggNI7E7bh3m7zcwLqR5w0Lw9Oqx0azcbeN0Ce/uGAjlUYWvy1gK/AVn q3Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729957058; x=1730561858; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GanVEa8cxLQoFBTsvQcEmQf1/zCR9K0WFuLJ4NsXrxc=; b=Ig9yRXmEpWI0uBIr7G2QGAJKqaQ8eWAjM+qHLmmp8BAKXz7tI8d7RhLgstMBNGMwYN QYywSGieM8y7zR6eMAmhJvhai6TuNXGX5rqZg/wzRUPziDuw0wy1v/FU6c1PtrTgFKz+ 9YtyvlINToXFDvEY0GTU/uLNF3sOKnTRHa+qc0QSoNU7AIFvGcLrpMhH48eKah3RzAaU a9DaCri9RxMxQFO3FAsLsD9esgeNWASps1o4Lj/icjjMVRwa+5D+iGJtduL2YaX4QsWJ 04+XApfmvboyXoUF7MJ54kImQDZpADmwamS8TiHxdvBYMGt5MxjUVTOGLN91qcDk8Iy+ vMuA== X-Forwarded-Encrypted: i=1; AJvYcCWWW71JddP09XTfDxGCqiag0F4ll5PyomP7aT3ieE/KByCbWASV59ogek7hBbo5I3YVwtsMcKyJFQ==@kvack.org X-Gm-Message-State: AOJu0YxqYT0XDIbUst7hACMpRRWCC2emPWXR4/eqJbf8EsgsuhY/74KE atc4yn7bhodP6Dw3zN4ThLBtw1cHgDxT9rw/HDCFLhnHcd7fzT3k9YPktOOApjWn3ThjrYLdKx1 ok0KzhHDvvmzYoqnfEQfGy136zLrrYKBQd2e5 X-Google-Smtp-Source: AGHT+IG2RGgBmdZacmDvK+ZXfc1orwt5wJxlOHkWOH534qXUZnG23pX4f5qZaNSJZCpJ6+484snWzRlS7OBe2bIA/4c= X-Received: by 2002:a05:6102:2ad2:b0:4a3:b506:56ac with SMTP id ada2fe7eead31-4a8cfb44d52mr1991537137.7.1729957057835; Sat, 26 Oct 2024 08:37:37 -0700 (PDT) MIME-Version: 1.0 References: <20241026071145.3287517-1-shakeel.butt@linux.dev> In-Reply-To: <20241026071145.3287517-1-shakeel.butt@linux.dev> From: Yu Zhao Date: Sat, 26 Oct 2024 09:37:00 -0600 Message-ID: Subject: Re: [PATCH] memcg: workingset: remove folio_memcg_rcu usage To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Hugh Dickins , Yosry Ahmed , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Meta kernel team Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DC2FD180013 X-Stat-Signature: o45ygn69ej4sxqymuzofon5hj5mooa9c X-Rspam-User: X-HE-Tag: 1729957055-697098 X-HE-Meta: U2FsdGVkX1+kUTnItY1iJlT28UNjBCiVZI80WnZUGF1eFvahNJQX+lNufI1qRGeNUteIx2klYAcMv86qdkcMFmD3GPYVe9zPzK92hsMdlh69waG370I/fE2F6pIn5sOpu1+YFeoMfzj6CZfV2a2K4k4wldjy7iktqxJN37mw+VB0/RAx5UJN9yiiGidSUPwyrSl6VAjPP56HQSpKeBwwsr4T/TfC5cpf+T08LIxzaQAq2jDNKudLuRnWW6KYjuyPh1v5kmqi2Mw+/heBQkdKQMziESkQjNF9geQpLFWy1Jyf84IMeRWdguUxFBJTOK5iMoe8VMRoh1jIPuaM7GDhfi0iv/P1YsNQrF8CCTi+F8Z1iLkEu1k55ujhw3AJ7wX8azvcMVCxZOR5y65M9ykp09vpCE2yTDjSUXIJMQLK6TUK2NmkOrl7EtJJmTBdn8cJTWnbWNooupALqIwp28ZNgQ7kkCf8Fou92Vj96geXNAsCxRg9B8jCXTePeHKXLsToIof5ZHSRI3N0oq7PgBkyKFHNZxyNocA/MZfIAA7wcG/DaosiyKgU4zU8V6V4FfnF01i7JKXV+0Rd4ZyRJ92IJFJIhsUZMBzcKVnqVTvc/3GhKETps9r5X/2EB1FWQ8C03WRBVjKgiaOc0XH+PbY3BugP2QFsl0COPguB9wiXC23myu5xLcTQlBHTeNqMgY8cFfr7QFvqCyQOxL7TqVC7W5cXwZUnHTJNDVOq+lTea/NTN4lIM+7sJ90gLqfn0ne9KHiRDn+g3LuHH9Y6fWspZeFXm7Wswpc/gA28tHzBW5KuAqkCpV/Qj92J1sv4DoaQMWe6TBPygrXACJi3AgipuFcANFLD6Ks2BksdN/xdq0QK2wk0gkyxAfvdqt+DlYFR+zp66V/Zm7ImGWUZbIBT1e3MuchDidrDNVf3QqE/OWwjSKDgw6igqsVv3rqaYrpO6amuVS0GhEccZbYqI6G /jK4+ueJ nDpybh+K02Qe3Ul+rgpzyd5xs0AMiTGi3OcD6oJMPhE7lEopTmNxKcwDQJCxlQwhPS7KzWSkVJ/sqULwBegx3VcoFYjuWgH6chdL41igo/XeOl7uyMfMmKVqT0/Mh7vN6bgC4iflZNAyCMf7R6YcByuzDGJ0TJ65zFPtYz/ANcmNf0wY552qij0baW0bVARsYgcrgIapcClcbT8h66PcEMoenFhGIYMDsE/91q7Nvg8WHKwISE9X/hO1d9DvQThwKdQ9tzk/6LGgKIDM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sat, Oct 26, 2024 at 1:12=E2=80=AFAM Shakeel Butt wrote: > > The function workingset_activation() is called from > folio_mark_accessed() with the guarantee that the given folio can not be > freed under us in workingset_activation(). In addition, the association > of the folio and its memcg can not be broken here because charge > migration is no more. There is no need to use folio_memcg_rcu. Simply > use folio_memcg_charged() because that is what this function cares > about. > > Signed-off-by: Shakeel Butt > Suggested-by: Yu Zhao > --- > > Andrew, please put this patch after the charge migration deprecation > series. > > include/linux/memcontrol.h | 35 ----------------------------------- > mm/workingset.c | 10 ++-------- > 2 files changed, 2 insertions(+), 43 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 932534291ca2..89a1e9f10e1b 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -443,35 +443,6 @@ static inline bool folio_memcg_charged(struct folio = *folio) > return __folio_memcg(folio) !=3D NULL; > } > > -/** > - * folio_memcg_rcu - Locklessly get the memory cgroup associated with a = folio. > - * @folio: Pointer to the folio. > - * > - * This function assumes that the folio is known to have a > - * proper memory cgroup pointer. It's not safe to call this function > - * against some type of folios, e.g. slab folios or ex-slab folios. > - * > - * Return: A pointer to the memory cgroup associated with the folio, > - * or NULL. > - */ > -static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) > -{ > - unsigned long memcg_data =3D READ_ONCE(folio->memcg_data); > - > - VM_BUG_ON_FOLIO(folio_test_slab(folio), folio); > - > - if (memcg_data & MEMCG_DATA_KMEM) { > - struct obj_cgroup *objcg; > - > - objcg =3D (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK); > - return obj_cgroup_memcg(objcg); > - } > - > - WARN_ON_ONCE(!rcu_read_lock_held()); > - > - return (struct mem_cgroup *)(memcg_data & ~OBJEXTS_FLAGS_MASK); > -} > - > /* > * folio_memcg_check - Get the memory cgroup associated with a folio. > * @folio: Pointer to the folio. > @@ -1084,12 +1055,6 @@ static inline struct mem_cgroup *folio_memcg(struc= t folio *folio) > return NULL; > } > > -static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) > -{ > - WARN_ON_ONCE(!rcu_read_lock_held()); > - return NULL; > -} > - > static inline struct mem_cgroup *folio_memcg_check(struct folio *folio) > { > return NULL; > diff --git a/mm/workingset.c b/mm/workingset.c > index 4b58ef535a17..c47aa482fad5 100644 > --- a/mm/workingset.c > +++ b/mm/workingset.c > @@ -591,9 +591,6 @@ void workingset_refault(struct folio *folio, void *sh= adow) > */ > void workingset_activation(struct folio *folio) > { > - struct mem_cgroup *memcg; > - > - rcu_read_lock(); > /* > * Filter non-memcg pages here, e.g. unmap can call > * mark_page_accessed() on VDSO pages. > @@ -601,12 +598,9 @@ void workingset_activation(struct folio *folio) > * XXX: See workingset_refault() - this should return > * root_mem_cgroup even for !CONFIG_MEMCG. The "XXX" part of the comments doesn't apply anymore. > */ > - memcg =3D folio_memcg_rcu(folio); > - if (!mem_cgroup_disabled() && !memcg) > - goto out; > + if (mem_cgroup_disabled() || !folio_memcg_charged(folio)) > + return; > workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(fo= lio)); if (mem_cgroup_disabled() || folio_memcg_charged(folio)) workingset_age_nonresident() We still want to call workingset_age_nonresident() when memcg is disabled. (We just want to "Filter non-memcg pages here" when memcg is enabled, as the comment above says, which I assume still applies?) > -out: > - rcu_read_unlock(); > } > > /* > -- > 2.43.5 >