From patchwork Wed Dec 13 13:04:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13490998 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 3E1E9C4332F for ; Wed, 13 Dec 2023 13:04:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA35F6B03A2; Wed, 13 Dec 2023 08:04:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B2B9E6B03A6; Wed, 13 Dec 2023 08:04:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D6BA6B03A2; Wed, 13 Dec 2023 08:04:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 832086B03A2 for ; Wed, 13 Dec 2023 08:04:21 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 52867C0B72 for ; Wed, 13 Dec 2023 13:04:21 +0000 (UTC) X-FDA: 81561813522.18.4874B60 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf10.hostedemail.com (Postfix) with ESMTP id 69DA8C003C for ; Wed, 13 Dec 2023 13:04:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tvD1IhOL; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 30qt5ZQoKCEM3txw3fmrjilttlqj.htrqnsz2-rrp0fhp.twl@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=30qt5ZQoKCEM3txw3fmrjilttlqj.htrqnsz2-rrp0fhp.twl@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702472659; 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: references:dkim-signature; bh=vCXE7g0+VpXRLRcaIF4VoQOYAIZ4TbByITks61Imd2w=; b=htGtzrhTq1o881yRqb7oZ+FQ83LA+hQ2svsZew4UyOXJyhGEhE2nhW8om/5dR27hLofyxo 55beeGYH3UlE+I7Kc0W22atcEi3jPCGmGTZwgKuSqGtH8Yvh5dNCT2kj2JdjTOA4ET2ShL txRMSk+tgvh3LFP+mrzGjBKwLcZyJ/4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tvD1IhOL; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 30qt5ZQoKCEM3txw3fmrjilttlqj.htrqnsz2-rrp0fhp.twl@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=30qt5ZQoKCEM3txw3fmrjilttlqj.htrqnsz2-rrp0fhp.twl@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702472659; a=rsa-sha256; cv=none; b=ZlLm8RQl8D9dmVJwTN1mmP+erXCXm71l7vhMV0vUNIAXDY50uQR3Mn6qUYmwyhtIM5MSmS VDgGFPQdUI6oMkSneXFqoL/KMV61hlgZXbu0ub5AQKT/Lpy3EakgrDAJsnXfkQyRSToupl +YIhFagYu1HI7X/PM02m2GvNl29DeII= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5e31a4a893bso2007357b3.1 for ; Wed, 13 Dec 2023 05:04:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702472658; x=1703077458; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=vCXE7g0+VpXRLRcaIF4VoQOYAIZ4TbByITks61Imd2w=; b=tvD1IhOLyn7OeI5j+f9RquDngiew1yb6ryPYdIW6pt07aaXG8eJ7XloO5rO5NHlvyd C/GnqKBMCfhOV0KpeMkAM1t+lRsb++l3GeURo4lGClSr0XXH8KjflRAoKsG3jm/cW5Is AZ/Onmr2nV6Dcoj82zqyZnCI9CCO6zwSiJZmfVRfo+h6JFRqhu/r/fjqLEGZpWFU3yyN ErfLCzf+JdWArUeBHnmWpsU5KIOQSVKSUjD3wADvvV2vDpLkiq3DRQz3dzQsli4t1Uxt R0pzY5waJWkTKtkcApR4H5f+ZskcjMbVUT0bkqivEMuDvaN6Fh0UuuKjodycc+UOjYPy oz2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702472658; x=1703077458; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vCXE7g0+VpXRLRcaIF4VoQOYAIZ4TbByITks61Imd2w=; b=fP7W/NG8CyWG52I3Q985+xqCemtX2hr7dTQSUQjkPaycIPRhG7Cb/roP8T+QYAWjxN /6VkPcVkqTTJJ1LlJlbnkSjFJzHbpJDr3oz2AXEqlbI1RumdVy6dlvJJ/tAo6u51/EE/ o4/mOi2vGu2p68L0Pt15CmRIhbL140xwMcH4kQmyjWRHHRWa4LI6CEXIvNp+0nbVJm7x RwDvhi3waOD8spsqAANXDt/9GidUpRFl/c58gpKIzsy3dGpjTaoFvlLlhRSiC2vHfjp8 Ll4gkjBdetps5ETShaz354QALhIH9taPD5LbYjmNwd5CO24bE3BwJUADLyhrgnoR+he6 RHSw== X-Gm-Message-State: AOJu0YzJnIxmXNkPT6m1gvDXQqmzgSgVLfSUDqh/RDpFLXLmLr0G2B9j Q97C1tbWdk9oGHBcNRpV82hY6+qVROZ062l0 X-Google-Smtp-Source: AGHT+IHFyl5FYdDTCrGeZyNNjuEA0Y+CP3zEYtG+YyGQAliiPJKAt0BsPzfTeOGxsKyB2/mcMXNxQgfYHSTxErWf X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:3749:b0:5e2:c745:7f63 with SMTP id fw9-20020a05690c374900b005e2c7457f63mr12307ywb.10.1702472658353; Wed, 13 Dec 2023 05:04:18 -0800 (PST) Date: Wed, 13 Dec 2023 13:04:14 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231213130414.353244-1-yosryahmed@google.com> Subject: [PATCH] mm: memcg: remove direct use of __memcg_kmem_uncharge_page From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , "Matthew Wilcox (Oracle)" , cgroups@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspamd-Queue-Id: 69DA8C003C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: h31aiqidnytwcba6ht9kqwouqyg59k1i X-HE-Tag: 1702472659-653267 X-HE-Meta: U2FsdGVkX18o8/F0nAARqgIOk7BoEt/5hh/jzYPjzMu1k7gcdhljHPzZZDIaA6JTtfZwEsWMokf8CI9k5ik9pin3y09LtUH0twlZaw68GqVfhgsakX5zagM8WDMUWc0GDCiRsTNvt82vtRD268zg2os/v21lvoYqrgFuwbEK2qR626PwlqLBjR8Yypiv03Op9T9FECgD7wm1RxkWXqtEbjhCOAaAK1vOxnAntuaQcmNXsbytpy/puqBvsWjJysvKjVasg3JSLDWLZyWImn/MZ4m3Jj8wYZ0OP/IGrE2Flq1S/dkAaBsnDNdzS2Trisyl5ZGJkw1ENRS+c//GmCwLrKNr8KiNoIe97yXrMeisdHfHVN0c++Gf2YZ1tJyZ7KvusDgWqtlN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DM9y5B5dcxyRJzQ2ezCD+zX9mhbrZfCH7g9meQBUS8XEfEEBw2wbvZuJFrp2KYdHFrIbJuC2dBzDIVacw+Filp4u7Ka0+yAAKhPxKJ+ebVi8PZSD4sM68xnRRnBcrm9l15MgQX3S2bvIcUoApDBXUTthQeGcQ8Was1jF7JG6HD/ijgstBxputrKt/IgsgzuduLCMn5rRqPjGkdWg4/qOY5o4NA== 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: memcg_kmem_uncharge_page() is an inline wrapper around __memcg_kmem_uncharge_page() that checks memcg_kmem_online() before making the function call. Internally, __memcg_kmem_uncharge_page() has a folio_memcg_kmem() check. The only direct user of __memcg_kmem_uncharge_page(), free_pages_prepare(), checks PageMemcgKmem() before calling it to avoid the function call if possible. Move the folio_memcg_kmem() check from __memcg_kmem_uncharge_page() to memcg_kmem_uncharge_page() as PageMemcgKmem() -- which does the same thing under the hood. Now free_pages_prepare() can also use memcg_kmem_uncharge_page(). No functional change intended. Signed-off-by: Yosry Ahmed Reviewed-by: Muchun Song --- include/linux/memcontrol.h | 2 +- mm/memcontrol.c | 3 --- mm/page_alloc.c | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index a308c8eacf20d..2009ca508271a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1844,7 +1844,7 @@ static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp, static inline void memcg_kmem_uncharge_page(struct page *page, int order) { - if (memcg_kmem_online()) + if (memcg_kmem_online() && PageMemcgKmem(page)) __memcg_kmem_uncharge_page(page, order); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 69b0ad4552425..09efbfa2733e8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3301,9 +3301,6 @@ void __memcg_kmem_uncharge_page(struct page *page, int order) struct obj_cgroup *objcg; unsigned int nr_pages = 1 << order; - if (!folio_memcg_kmem(folio)) - return; - objcg = __folio_objcg(folio); obj_cgroup_uncharge_pages(objcg, nr_pages); folio->memcg_data = 0; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7ea9c33320bf1..f72693d91ac22 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1086,8 +1086,7 @@ static __always_inline bool free_pages_prepare(struct page *page, trace_mm_page_free(page, order); kmsan_free_page(page, order); - if (memcg_kmem_online() && PageMemcgKmem(page)) - __memcg_kmem_uncharge_page(page, order); + memcg_kmem_uncharge_page(page, order); if (unlikely(PageHWPoison(page)) && !order) { /* Do not let hwpoison pages hit pcplists/buddy */