From patchwork Fri Jun 28 21:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716623 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 131ABC3065A for ; Fri, 28 Jun 2024 21:03:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 361296B009E; Fri, 28 Jun 2024 17:03:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 312396B009F; Fri, 28 Jun 2024 17:03:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EEE66B00A0; Fri, 28 Jun 2024 17:03:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E787A6B009E for ; Fri, 28 Jun 2024 17:03:53 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B2D7414060A for ; Fri, 28 Jun 2024 21:03:53 +0000 (UTC) X-FDA: 82281524346.20.C5DA31F Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) by imf10.hostedemail.com (Postfix) with ESMTP id 89AABC000F for ; Fri, 28 Jun 2024 21:03:51 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lZwpcIdW; spf=pass (imf10.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.171 as permitted sender) smtp.mailfrom=roman.gushchin@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=1719608613; 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:in-reply-to:references:references:dkim-signature; bh=RgRJB5ojFnC1EEazDyS1AJJPjVu1TOm/QXaplK0X/Xs=; b=BLxMV44cchIPkszEJYMknW/cUL96c3R82H37my/nEgF2HPvzQMme+sto7OaOpiir1k15DF RwF6d+g05YQYCEb3o11oykJ/Q46yZ18b7bk7CRsltNxgYX8fwJgw+omVTcxWv2JunaIlRF oeo9FjF6OM1ry0/4W7hUoQbGnc8Wmxo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608613; a=rsa-sha256; cv=none; b=whgp3o/Be8UmDdIjUUgR3phO+H/RbtEO04bZpkcZ/BXxaa8YVefmwOsaeGKCA7u2CtyIUX FX4ggkjNxGHH+ctHJSz2Vfu/Kk3Xc/heI/JpiWnL45At3+v3obglENE7BDFvbVigeREpcq 274NM7/FAAgCQ1qes2rIAHiO/K9paak= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lZwpcIdW; spf=pass (imf10.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.171 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719608630; 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: in-reply-to:in-reply-to:references:references; bh=RgRJB5ojFnC1EEazDyS1AJJPjVu1TOm/QXaplK0X/Xs=; b=lZwpcIdW8TqGKNu091IVqrkYFQAou0Jw6wdWJ44IBEE2EcR7K1Bthx5XJTC93f4pV0sNmo Ju27X4CNJNK2KcwGlp2hOd4iCh2dmvSHuE4w6o6tKw6YyQNfKgbQZxUbNWt2HxE+dA7hYn mEOzBm4Z5lqqWgKuByG7tdOaT20Wpeo= X-Envelope-To: linux-mm@kvack.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: hannes@cmpxchg.org X-Envelope-To: mhocko@kernel.org X-Envelope-To: shakeel.butt@linux.dev X-Envelope-To: muchun.song@linux.dev X-Envelope-To: roman.gushchin@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Roman Gushchin Subject: [PATCH v1 1/9] mm: memcg: move memcg_account_kmem() to memcontrol-v1.c Date: Fri, 28 Jun 2024 21:03:09 +0000 Message-ID: <20240628210317.272856-2-roman.gushchin@linux.dev> In-Reply-To: <20240628210317.272856-1-roman.gushchin@linux.dev> References: <20240628210317.272856-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 89AABC000F X-Stat-Signature: 41fpio3p46o4kgs8effcm8555x39o3k4 X-HE-Tag: 1719608631-348874 X-HE-Meta: U2FsdGVkX18Hdt2JBuMV9CZDAWLvp0OAvYOnczIYacIMvwsMXwa81jIcApyRtyMaAFVvHa+pHroVkoZvWpUVGjrplz/aZDgzONqiwOdIgDXpOcZTHm/sjyZ78LoyNbYvtKg52h3ILs0+4eCj5dAwo79IDsNtrqRAKlRKSvJD16hgjZ5cYeHsIL6oyPCJc94PlKFYQli/RKD+z96Ru3hZWNjZi9HIXgoJJMvpHOmRjp2DaMa28uc20VciaFqihaqhi+4BcD8FiU7aR8qEpfmsdD+irp5+e+C4NydaWy+592ZefXd2Ye9NCYJvAgI/Z0Z8a9k8Mo5CFx1CEwF+Q3zYXnQKqkA6fnmDOr8W5icdpr4VW0ugONx2cyisMHhGnflFsQioV+H2O3AmdD/svt3ON+14gOpg8gAbrfO/+xFPF8O8Rz+BF7onfVS3wnQb6BrcNjjCvPzuFORSImqeMxwJ4J7zEsY/rtMn71855xB/+TjXh7gFgVtFyvdaerWepYilfWIFvmRH44cIifJWy0Ni6tJGlE+PPWYYlJKGdhQ2jhgPiKdHvb8YLWNcL0yULYhfcWRSjLpinF9D38DLXYdX99m5ff6aEmLab1hRLNPIeulFdWNe7gIf3eDOkAOPZxaCGVQSVM1tSzmGtYax7Qhwhc5ZjIx821LnFBVRHdq16JqQMxzGv9mxAoii7z/WdenPLGEOiBk6TA/6SCBL418PTF+lv0sSUPuaC1gMXlFl4WxXYQ9oO9AztFbBwAkunmMtApLUMBNMJ+iw/FunfR/jnI7s5j5uNG1XnUVrA066VK63Nw9o4Z5ZeeVLBpj3soDNj5SYFWEDpHwJG4Rx3re8RWCnmmduSCyGUXrt3yREzasx9gWVG8s5QuQh/YugBJi+iD6Id51z3Bb0Do25Kv8ehjJD6SpgghxBBZUP4IN5B+fM8cSBiBnuBRPZeV9AbeLNyf5duC6mtOBB0QCmWE2 Da1xsqAr 5n27vkR2SwSgv583z1KU7a3qdk5jW0hW0IIsDGWGYIk/l8HGVyX1Jqry+xcTNCNpt2v3HvocDlQk5szaXPxYAhZchGWrdLwn1lxQKbInHUadrOv1BllDuNjD9iCPKhsi3O+CNgO9WU1eHv+iX7s/NqKgZYG3IdkN3UFdy 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_account_kmem() consists of a trivial statistics change via mod_memcg_state() call and a relatively large memcg1-specific part. Let's factor out the mod_memcg_state() call and move the rest into the mm/memcontrol-v1.c file. Also rename memcg_account_kmem() into memcg1_account_kmem() for consistency. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- mm/memcontrol-v1.c | 12 ++++++++++++ mm/memcontrol-v1.h | 2 ++ mm/memcontrol.c | 31 ++++++++++--------------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index 6ac47954eefc..c73a0ff0cc39 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -2913,6 +2913,18 @@ struct cftype memsw_files[] = { { }, /* terminate */ }; +#ifdef CONFIG_MEMCG_KMEM +void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) +{ + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { + if (nr_pages > 0) + page_counter_charge(&memcg->kmem, nr_pages); + else + page_counter_uncharge(&memcg->kmem, -nr_pages); + } +} +#endif /* CONFIG_MEMCG_KMEM */ + static int __init memcg1_init(void) { int node; diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index 64b053d7f131..61620e2b0bf0 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -107,6 +107,7 @@ void memcg1_check_events(struct mem_cgroup *memcg, int nid); void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s); +void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages); extern struct cftype memsw_files[]; extern struct cftype mem_cgroup_legacy_files[]; @@ -125,6 +126,7 @@ static inline void memcg1_check_events(struct mem_cgroup *memcg, int nid) {} static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {} +static inline void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) {} extern struct cftype memsw_files[]; extern struct cftype mem_cgroup_legacy_files[]; #endif /* CONFIG_MEMCG_V1 */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c251bbe35f4b..802a077e2e2f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1718,7 +1718,6 @@ static DEFINE_MUTEX(percpu_charge_mutex); static struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock); static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, struct mem_cgroup *root_memcg); -static void memcg_account_kmem(struct mem_cgroup *memcg, int nr_pages); #else static inline struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock) @@ -1730,9 +1729,6 @@ static bool obj_stock_flush_required(struct memcg_stock_pcp *stock, { return false; } -static void memcg_account_kmem(struct mem_cgroup *memcg, int nr_pages) -{ -} #endif /** @@ -2642,18 +2638,6 @@ struct obj_cgroup *get_obj_cgroup_from_folio(struct folio *folio) return objcg; } -static void memcg_account_kmem(struct mem_cgroup *memcg, int nr_pages) -{ - mod_memcg_state(memcg, MEMCG_KMEM, nr_pages); - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { - if (nr_pages > 0) - page_counter_charge(&memcg->kmem, nr_pages); - else - page_counter_uncharge(&memcg->kmem, -nr_pages); - } -} - - /* * obj_cgroup_uncharge_pages: uncharge a number of kernel pages from a objcg * @objcg: object cgroup to uncharge @@ -2666,7 +2650,8 @@ static void obj_cgroup_uncharge_pages(struct obj_cgroup *objcg, memcg = get_mem_cgroup_from_objcg(objcg); - memcg_account_kmem(memcg, -nr_pages); + mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages); + memcg1_account_kmem(memcg, -nr_pages); refill_stock(memcg, nr_pages); css_put(&memcg->css); @@ -2692,7 +2677,8 @@ static int obj_cgroup_charge_pages(struct obj_cgroup *objcg, gfp_t gfp, if (ret) goto out; - memcg_account_kmem(memcg, nr_pages); + mod_memcg_state(memcg, MEMCG_KMEM, nr_pages); + memcg1_account_kmem(memcg, nr_pages); out: css_put(&memcg->css); @@ -2845,7 +2831,8 @@ static struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock) memcg = get_mem_cgroup_from_objcg(old); - memcg_account_kmem(memcg, -nr_pages); + mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages); + memcg1_account_kmem(memcg, -nr_pages); __refill_stock(memcg, nr_pages); css_put(&memcg->css); @@ -4806,8 +4793,10 @@ static void uncharge_batch(const struct uncharge_gather *ug) page_counter_uncharge(&ug->memcg->memory, ug->nr_memory); if (do_memsw_account()) page_counter_uncharge(&ug->memcg->memsw, ug->nr_memory); - if (ug->nr_kmem) - memcg_account_kmem(ug->memcg, -ug->nr_kmem); + if (ug->nr_kmem) { + mod_memcg_state(ug->memcg, MEMCG_KMEM, -ug->nr_kmem); + memcg1_account_kmem(ug->memcg, -ug->nr_kmem); + } memcg1_oom_recover(ug->memcg); }