From patchwork Sat Oct 26 07:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13852086 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 717F9D10BE5 for ; Sat, 26 Oct 2024 07:12:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF9A76B007B; Sat, 26 Oct 2024 03:12:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D81B46B0082; Sat, 26 Oct 2024 03:12:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C22B96B0083; Sat, 26 Oct 2024 03:12:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A0C8D6B007B for ; Sat, 26 Oct 2024 03:12:11 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E328814148F for ; Sat, 26 Oct 2024 07:11:49 +0000 (UTC) X-FDA: 82714883454.07.A0A6F7B Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) by imf02.hostedemail.com (Postfix) with ESMTP id 5E7B580015 for ; Sat, 26 Oct 2024 07:11:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=MoOsBK0K; spf=pass (imf02.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.176 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729926574; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=GxQOGmQPdgw5Cv/LfTKFz+nlFJDJQN96Dif2xmEC5v8=; b=xS2xzvDHQ1HYEGxtDcjZmyRU6PwmVeJJ3/VOg7SdX+La/J7tMv8y/emJoFLcaUtVzMBB6u BfOSzJrY4R/Bo+N3oKoWWZQb/bn4qND2ydBwU6RjGjggtik5zN2sR1/7NZWNHJZxRV9mrK hHQX7kQCBQ2sXfO0Dvp2Oaty/7I2fNA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729926574; a=rsa-sha256; cv=none; b=iPpPnthhKxUs/GPpEERHBFN05QEb+ZqILZoZk32UNcbsXPLE9H/Pnnva7NXQoL7+RuMRrU 21L9lNntEpXirAe0Iz3GkSGO3DYInNmICMzVLamxpyAtdt6CmHySe/aXnoVQI93O7nVztp GbIoGLREWf0MbNcoK1k1v7EZ5GO3SoU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=MoOsBK0K; spf=pass (imf02.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.176 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729926727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=GxQOGmQPdgw5Cv/LfTKFz+nlFJDJQN96Dif2xmEC5v8=; b=MoOsBK0KzMJ5rNWJ9B2Hf9HOvvhnjmEahVjjoMdczDmHzO7F19hXEYtfn4+JwsIoP3Yjsb MhtDC5RvwwYjrtHLqgm+f7k/MbWy1+sKZDC95w6r6tc0rt+QVZ5psu6uh1kQYmGYxXMGbD ct1sldQHsH3uIhYL6Lvog1T76qr2hUU= From: Shakeel Butt To: Andrew Morton Cc: 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 , Yu Zhao Subject: [PATCH] memcg: workingset: remove folio_memcg_rcu usage Date: Sat, 26 Oct 2024 00:11:45 -0700 Message-ID: <20241026071145.3287517-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5E7B580015 X-Stat-Signature: 7kxs3d4g88fb31kynuhccu9qwtopwods X-HE-Tag: 1729926690-551643 X-HE-Meta: U2FsdGVkX1+XTvlkcbrVy6Y2XcH65+pkU7O9qwo9+syUYtbPEGgceXO5kJBNixPM72gRgGlLAxDS8ybJldXA86wEMdx5rBqlHjzN2KcuE2AUzbtLknx0FyxHHGLS5lTnxzeBgNUDJeZtZaQNQfacJagQfSVgpsOHgE2Fkm9b2w/nibCVadBwQ6GCRThhoMT7RJ81+aMwRAPnGe5OKnx956L9hwJmuISJCGrzDH6IO25PgV3pUG6ZqhpoV3SU+KIQObmYmzKQR/DwGdV6Ewi92O2Q7PQNJrMLdjylm82iEYCz19spmyYWEgdhj7who95dfJBX6SbAN+QpnGqzgQJD9P3BJ3La9FG/eXXaSEdNUUvy7f8zpnzGy8DJ8+hTOq4FTW+X61iAqFtAWKB/HdKDu65Hpqiv4JhUxKWNXauKDpue4QOYac3r5oRnN+gvzUHhBfuIy2sLOdHiv6+GutrFDUtvMQTh5Xs7JfkAkjXQt0bSPqr4H9vNcrze2bltqle6sVa39orEwjZNXoj7oZChQ/cKj6+kj31hZ3bPR9hGuN37d54ttPhfq745/vWBmOhGgiYWBB97zspQkhg8l+pMUDd+k4ZivBPVDQ4OWWi2TsxCXqNAPMmmn5OzZaPFu8UPSv9yi6R2b9AhcuWFcm+hmc0YrciaaqogftgLwiCWENyszlf7MexXuEF/8NJtr1CogWrAsCJ7lVeslABWQ6r1XpKMDrSNwPP1V9pEfNKO/Mh9PakCMFp5I0FfY7stj9WBkN/LdlYStKQlsj4X3quHcY9Sts+5GGSR6PS4l3CAKQqrWt/gtscIxzBqd0LSOzkU1i8RYhTK48dFiiRJJSU36T3XnTVdcU0pgy6RtWRtvrLYX0qpriNecI2YqfVFvotxrGpYnslgJoaJGsKpFJ+56vK4DszH25c0yqFd0sfvMlnEjtYYd6DjxjyNoU5eKz6qh2WARh+eNen11Ucxu/P EGeNllw5 qBENbPsPe0cAMqku/euDuFSF9xS1eEplQfWrBmKJZlymanVE+QyJO3sx8jcAkbQRfOalHRPpEs1G1mJ/JQNXqEnV+2J0qFqpk6bDCnj6Lvtvln4MwOaq3sEej2S6hWCEpFgJpRbNl6lkn9uUXG9ieqMzakvLd3wq/R1FBfQ8CDOv/uXqYlRgWLRQ2noen4Ca3qjvjatQDphKFEOp06/twZG9H1g== 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: 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) != 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 = 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 = (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(struct 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 *shadow) */ 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. */ - memcg = 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(folio)); -out: - rcu_read_unlock(); } /*