From patchwork Sat Oct 26 16:37:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13852299 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 40F75D10BFF for ; Sat, 26 Oct 2024 16:37:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8064A6B0082; Sat, 26 Oct 2024 12:37:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78F006B0088; Sat, 26 Oct 2024 12:37:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 656E76B0089; Sat, 26 Oct 2024 12:37:33 -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 4A0756B0082 for ; Sat, 26 Oct 2024 12:37:33 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 73A9EC1764 for ; Sat, 26 Oct 2024 16:37:10 +0000 (UTC) X-FDA: 82716308136.03.C025920 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf30.hostedemail.com (Postfix) with ESMTP id 2BD3980008 for ; Sat, 26 Oct 2024 16:36:50 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JwppYDbH; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf30.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729960479; 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=kDTFYQ4jfbUxBCetm9ZFD4nERqP1KIxH9DYbqDWNu3k=; b=wKT+bPvDvur/2rDz7TP4S6gfqVnPULo+F9owPT2wedcv//twC+O06oQFYAbPlHycFAvIdG Pf+c5OU0L3BTSFXuDMTdI4kJYaObTRpDI2djS8453Kt3kHo28vs2pbrbwufLjHvoVeZ+de hICQGoF7oC4heuUXFzbFzQS4pzDgF3k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729960479; a=rsa-sha256; cv=none; b=laeU/D8Z2TCzFkr5d0WTrEG1slTdycHgiJ3LVa1dwgQMmugTwU3NNvfkk25cCb+HBDQKDw gFT+ZYePNZmUTNacWX10FpY1qf2kJqYvTsYq3TRIcMShlwd1XXJyh/vv8yHKRRNHVwORlv k42t85o8mMF/waMBRlQtrrnylxyvQ88= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JwppYDbH; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf30.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=shakeel.butt@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=1729960647; 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=kDTFYQ4jfbUxBCetm9ZFD4nERqP1KIxH9DYbqDWNu3k=; b=JwppYDbH2Y4GmKniz7qVDqFGFp1tsToZx/rxO0MEc2PqpYqIqAAhWWcca8GGeF3aCjvw9q e2B5pQKYY4kcnmMwPOE2WBXhtzF9a4jmTIGUkmGP4RqDiDN6Nl49PuKHBc2UOZeAtx7GNE E8+8oNOLfm9juAowpJAw1mYzw11TBc4= 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 v2] memcg: workingset: remove folio_memcg_rcu usage Date: Sat, 26 Oct 2024 09:37:07 -0700 Message-ID: <20241026163707.2479526-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2BD3980008 X-Stat-Signature: j78uuo8mdqifqxgaehw47dsbupnbt63e X-Rspam-User: X-HE-Tag: 1729960610-290558 X-HE-Meta: U2FsdGVkX1/jTLabagNrN+3+pI1QWq31hLV6e2W+hBIyxgs5sAISvUrq8D0jDGx86HtQKdaIXtEhY6M/MNEWKutGNczj4ZPs0VjowcA3jAs+8SHmwh+5QJhJQx/odVPrItFM40J/36WTwTKYDpCINtRxsR0Yag+e0HBKqE2TPer+ENlLlXVQMRKpkeaSKy+7mQx41N0YTAzTmTVwYIMZDZlTmhJZ+ORXc5hz7IsIGtmvYu9X8JeRN+wh9AQHATvLvQ78jd2L8oOdLQXZkYO8U1sXNkcetcF4BuyDvjmcuEdQBEUJ9xSI+XG/ofD3zTUpyWsPX/MsXllXGxB0l/uOJwqCY/8pb4KFM00yihcYa1kmBlvLL4cZVOovdhLK+VmdnB6oRfppgSZ8iXmdX023QL198OO2DEd/PTsK265uJeiXTBNyYSOmt+uklo7bz6zeU1ld4+eowXFylSR8p/tcumt14mpfTSH6YfXnVQ9V5Aclm3Q2eIU3N91i7e/Jo4jd+KrP42pZIY5VQqzzSRIfgOhwfeR6CoV7KQfRyzQpcQdQ2IyRUpKvdhJT0OSI0f4oeaVVDpa7AuJu8ygj/veTPyjS0sCpstFAc3HwOtCps8CWvLZf6eJc4nTw98jQ9pqoRddyj/A7CdLmpdCaM+pNaKEituVJ6apIU2Gfz9ORhTnSNq+hXkHrJ9gluAjY/E1i6p9ZYy4aF1it/KP/+rFnXG43tK6wr2yD4TWuL1B/qCkwwdzvhwTQ7gsWPhCZ5cJYPo8kU7huub+9K2EAaXSP9jGwzsoUZefYz4hXWQSwVUkQzePsntm2KGoViY40yuetH5LAHJapCw689XwYMiI0qKZdHFqNs60xx9bW3nigvyMz/BE4ewRfDd0lK7gYBS1Ta1XwlPrwBNZHWXdxiraA2o0qN1Etd7ygwBff/cqLzPIoN0FAx41IWwOAINnxWsPco9MBQ5OZyBwq4CiSf1u GPcpJc19 sLHaYN1+QaM6/+pTMrHkbFWYx84l4Qj5ovktndTvg8PGAM8HZbwdnon3EJ2vlVgIWr47h76is/LJtsYQN7jkmF/P/6NWg5wTFgdQzjmzBSu3ycxhjrEnWhm0tvNMubT7pilW+uodkJLOVhihR2oCIEs6IUNde5w/SoctpBnFaVtylOtJ0nx82SK7m2ddf0YJzj/sRG/KAYPHcmgDpapfCgqiZTw== 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 Tested-by: SeongJae Park --- Andrew, please put this patch after charge migration deprecation series. Changes since v1: - Fix for mem_cgroup_disabled(). (Yu Zhao) include/linux/memcontrol.h | 35 ----------------------------------- mm/workingset.c | 14 ++------------ 2 files changed, 2 insertions(+), 47 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..a4705e196545 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -591,22 +591,12 @@ 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. - * - * 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; - workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio)); -out: - rcu_read_unlock(); + if (mem_cgroup_disabled() || folio_memcg_charged(folio)) + workingset_age_nonresident(folio_lruvec(folio), folio_nr_pages(folio)); } /*