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); } From patchwork Fri Jun 28 21:03:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716624 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 E64ECC2BD09 for ; Fri, 28 Jun 2024 21:03:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B45F6B00A0; Fri, 28 Jun 2024 17:03:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 165696B00A1; Fri, 28 Jun 2024 17:03:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E834F6B00A2; Fri, 28 Jun 2024 17:03:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C96956B00A0 for ; Fri, 28 Jun 2024 17:03:55 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8514D120616 for ; Fri, 28 Jun 2024 21:03:55 +0000 (UTC) X-FDA: 82281524430.17.A313764 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by imf20.hostedemail.com (Postfix) with ESMTP id 726FC1C001B for ; Fri, 28 Jun 2024 21:03:53 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=J4erkf2Y; spf=pass (imf20.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.179 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=1719608624; 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=xMDF+K4BIl7gcrHo2WUEmAHLFHOqrbM2Rc/7npZEcT8=; b=Ld7YH1ECIPoBZ9gMZ2lQzDneSho0m9cjtF+N0TEgLcoHsYXB4oe+ce1dwheHFY5dnYHRcp zK6yOaqCrntPyILT5qd/W0vo64aD6WcOOi+jvACxV555LQGM7sU5VVbDEf6K5JbT4cthK0 4R+r+FXRgMPqczk9KvEdM+iHKHaiG9I= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=J4erkf2Y; spf=pass (imf20.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608624; a=rsa-sha256; cv=none; b=lvqMR38VsOsdE5dyWTU3MYQtc8er1geWYQd5Bxj4xLjh43oO00jLOswIBih/jmen4INmYX To91aAfEdKDbixPCIssM8Jh9C/UAbsrZSVaCgw6CnSSUAznAm8VQFPSwF6ApMEFGy7amdn Gk5cBKANz7+RQJ6yLgKirBwkEH0+JzM= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719608631; 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=xMDF+K4BIl7gcrHo2WUEmAHLFHOqrbM2Rc/7npZEcT8=; b=J4erkf2YjUTiJUMZYB1J0+yCmRXUnc59RpTJ8yK14OwGb7VFouZgBj42vekY+DDYdgNdig Ex07/kd5xqqsR3UtmucYNSKqSFqszQLIeVJs8dybLz17eb6z3H7M2D1joHukOI44bfUF+G jCt42MhduBjyhLVrKK6fNNHBrWvoAFA= 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 2/9] mm: memcg: factor out legacy socket memory accounting code Date: Fri, 28 Jun 2024 21:03:10 +0000 Message-ID: <20240628210317.272856-3-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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 726FC1C001B X-Stat-Signature: qa5rndj1zuj3eswbfca44crcuydzz1z9 X-HE-Tag: 1719608633-66197 X-HE-Meta: U2FsdGVkX1+hZ1GA/EmTboWCeyZ5JVq0pGtR7e7fuq/eDc1NGO307uhOrL8mZO5UJtM1YpAet3randYgaFf/48jqUcJ7RKTKdqD7hGt5caefpLXWOtB5Xk7VQReyIqs3/R+PCZOXVI/sWK0NU9ieFv0A8FdlDCjCBT7i3a8BVqeozISp7xnvRQZDbcuDcOnqDIPcMgNBSzlAGH1t52PfZGg+Jhdye0HadaBMcaAwSmxbVYRBeoeDDgo0820BzAL1GwQYms0Lws9pQoIOp//EAPaLay7W55CVfMQZGLAoZKCUcdIGeZHwxjgfO3iJAupUkYE42whSfe62ng/L0loD5cv7SyWuguRTz2A79GBRvV91OO0TMAJ+dNdP1GElnY3iG7cd+jnyDkZmNJaJNld0cApXmdxZXF0jNs9cF9x3db+Nw+w+/wsw8VEMPj1i2rz0kcvfTcBWLrmr8km2THGqJC/ap/6KG0FhU5dEMJ2+gkvH3sdaVrYjuONemXJ1fTE4l8keNcFB9YQ7huxh/VQXg2Dj8Les+grg47lhsXKhvKwUwWuW58ltKIXsx/s2CvDM+yg+pIcv3L1+UZBtXANyp0CGvC2EHSy/WuAzfhFTKqwUEhP50IylvaEIIpkD1+b34pNv9h8eNYMKGRU7wyVpp5RRlp+no7rvf/yupxPLM0rmvgMV5zkyx3eCxdIfavH47otqesjOfNS/aKGIHQzNCFvXk6j6X0Q51P8wunPx1kpP9ZIZC+Q+88r6du85RShOqLBoKKkQJKhwCsFesjjgjf1OCXvqxfTNghI8WE5AqVL3gJWsvApQGT2QApffyaWO5W7mN4S/1kWr00eK4secSilhuYyrtyRn+Maj6mk60wOkFmRIhAAlxwBMsxTm+iimxn1FuRCM3/OBxIWnMLsInQVY61tYniXMWZ9vjTsxVPYQFxhkjxIsTpp8kEdTMusPWy21Djd2dHfwNCaqT3z ZyK+oykV +CngD8Jid8Dmb6CrDo2+LE3t+IcaFQrP06bo9RmC0pQNo18mc6FXdohUOA/EvofrNtulLLNIR7nL/Uw0gR7NQJeLxxysfGOEnQ1uqVvwFP+3ZIpQ= 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: Move out the legacy cgroup v1 socket memory accounting code into mm/memcontrol-v1.c. This commit introduces three new functions: memcg1_tcpmem_active(), memcg1_charge_skmem() and memcg1_uncharge_skmem(), which contain all cgroup v1-specific code and become trivial if CONFIG_MEMCG_V1 isn't set. Note, that !!memcg->tcpmem_pressure check in mem_cgroup_under_socket_pressure() can't be easily moved into memcontrol-v1.h without including memcontrol-v1.h from memcontrol.h which isn't a good idea, so it's better to just #ifdef it. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- include/linux/memcontrol.h | 2 ++ mm/memcontrol-v1.c | 17 +++++++++++++++++ mm/memcontrol-v1.h | 16 ++++++++++++++++ mm/memcontrol.c | 22 +++++----------------- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 796cfa842346..44ab6394c9ed 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1650,8 +1650,10 @@ void mem_cgroup_sk_alloc(struct sock *sk); void mem_cgroup_sk_free(struct sock *sk); static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) { +#ifdef CONFIG_MEMCG_V1 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) return !!memcg->tcpmem_pressure; +#endif /* CONFIG_MEMCG_V1 */ do { if (time_before(jiffies, READ_ONCE(memcg->socket_pressure))) return true; diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index c73a0ff0cc39..c9b4c3e4797d 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -2925,6 +2925,23 @@ void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) } #endif /* CONFIG_MEMCG_KMEM */ +bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, + gfp_t gfp_mask) +{ + struct page_counter *fail; + + if (page_counter_try_charge(&memcg->tcpmem, nr_pages, &fail)) { + memcg->tcpmem_pressure = 0; + return true; + } + memcg->tcpmem_pressure = 1; + if (gfp_mask & __GFP_NOFAIL) { + page_counter_charge(&memcg->tcpmem, nr_pages); + return true; + } + return false; +} + static int __init memcg1_init(void) { int node; diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index 61620e2b0bf0..c8e5119223bb 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -108,6 +108,17 @@ 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); +static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg) +{ + return memcg->tcpmem_active; +} +bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, + gfp_t gfp_mask); +static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) +{ + page_counter_uncharge(&memcg->tcpmem, nr_pages); +} + extern struct cftype memsw_files[]; extern struct cftype mem_cgroup_legacy_files[]; @@ -127,6 +138,11 @@ 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) {} +static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg) { return false; } +static inline bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, + gfp_t gfp_mask) { return true; } +static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned 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 802a077e2e2f..2c0605bbbb31 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3788,7 +3788,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css) if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket) static_branch_dec(&memcg_sockets_enabled_key); - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_active) + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg1_tcpmem_active(memcg)) static_branch_dec(&memcg_sockets_enabled_key); #if defined(CONFIG_MEMCG_KMEM) @@ -5013,7 +5013,7 @@ void mem_cgroup_sk_alloc(struct sock *sk) memcg = mem_cgroup_from_task(current); if (mem_cgroup_is_root(memcg)) goto out; - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcpmem_active) + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg1_tcpmem_active(memcg)) goto out; if (css_tryget(&memcg->css)) sk->sk_memcg = memcg; @@ -5039,20 +5039,8 @@ void mem_cgroup_sk_free(struct sock *sk) bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, gfp_t gfp_mask) { - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { - struct page_counter *fail; - - if (page_counter_try_charge(&memcg->tcpmem, nr_pages, &fail)) { - memcg->tcpmem_pressure = 0; - return true; - } - memcg->tcpmem_pressure = 1; - if (gfp_mask & __GFP_NOFAIL) { - page_counter_charge(&memcg->tcpmem, nr_pages); - return true; - } - return false; - } + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + return memcg1_charge_skmem(memcg, nr_pages, gfp_mask); if (try_charge(memcg, gfp_mask, nr_pages) == 0) { mod_memcg_state(memcg, MEMCG_SOCK, nr_pages); @@ -5070,7 +5058,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) { if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { - page_counter_uncharge(&memcg->tcpmem, nr_pages); + memcg1_uncharge_skmem(memcg, nr_pages); return; } From patchwork Fri Jun 28 21:03:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716625 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 9F3BBC30658 for ; Fri, 28 Jun 2024 21:03:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E61C96B0083; Fri, 28 Jun 2024 17:03:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D494D6B00A1; Fri, 28 Jun 2024 17:03:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC54F6B00A2; Fri, 28 Jun 2024 17:03:57 -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 9240B6B0083 for ; Fri, 28 Jun 2024 17:03:57 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 21B221C0E08 for ; Fri, 28 Jun 2024 21:03:57 +0000 (UTC) X-FDA: 82281524514.18.F525E1D Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf16.hostedemail.com (Postfix) with ESMTP id 09FB8180017 for ; Fri, 28 Jun 2024 21:03:54 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=g2NtijnZ; spf=pass (imf16.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.188 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=1719608626; 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=MPtP5N5DyF6jTL5Hfe6ZNpWs5ObKbQpWVZsP63+oajo=; b=KX3cFNsietITaZwbzo7T1hLCNRGlfGWmwJcLPtK/XXX5M/XtVruL3VnFQsiTTu2qthQEQV 8RWbguAclaZVPfXJO1rx/xjXDQa2JCObtO2laUhlMrDYdFE8SKCyiSqbQDROiu24RGAF8r bwA0u6AckjCOgln5qiaSbO/b555nMrQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=g2NtijnZ; spf=pass (imf16.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608626; a=rsa-sha256; cv=none; b=3pl2GfwPGb+dO/KEnALLgb3jwTG4/8/8gbZdjoZp2bsEMq3xll433dG3/SUY+uilPU1zVO 9Ew3jdYKnhpIxxZJVjnip7aLAYeyQb7q+8gOqkO+y06/2x0O+TJFaisiCZmbYzA21KOG/z yCS733CvjDIBZm+c+XhlQGUFJqEpecg= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719608633; 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=MPtP5N5DyF6jTL5Hfe6ZNpWs5ObKbQpWVZsP63+oajo=; b=g2NtijnZEqgSMhtqKQKM5yPBi+tG0SpRLqJ+5RYIwuiLLTSg1j+c8yL4PEB+DPR8uQ88lD yvfYsoa9kK4zLjnW9p0ZQCAJlr333gFyf6FEdei0K7YOoa7NF/B9RIZfx9vW9RJ9IrNcqN 3uYerGLOAvi0tAsd+SuVTh/1zamik4U= 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 3/9] mm: memcg: guard cgroup v1-specific code in mem_cgroup_print_oom_meminfo() Date: Fri, 28 Jun 2024 21:03:11 +0000 Message-ID: <20240628210317.272856-4-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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 09FB8180017 X-Stat-Signature: g3jdhid397oriufg95h7gkazd873msxu X-HE-Tag: 1719608634-960015 X-HE-Meta: U2FsdGVkX1/RCkZ/d3MJqY3TCNU6/V/xcXEIyxo2zHBPwa4NTpLd++ucXJnHpZ4vFBwe32XGhbyavoliL44G4I6AHJpVTfBlkzSMoOzzoUdpPb7vg/GbGk/vkT8dP41679KSG3lShJKo4vJX8yvp8lwfJ/egAqX7zWdqztg0ZvmE9ibG35ZMaF9jCq2lZ4TBlUa+8aTSWGjMM9H/baLmm822WTgbtOrEHmdAJnVR+GqoVbi3BZUe5LHV76j9dof8MBXbTiORpkwyoYRvh+60xy2JNBfw933a2LDlMa6SAuH83feTLQ108pEAsmK+XH9TSaVXuJv//cmE3CoVp3A04xf/dCwh7wQa0fIdPBF+cJ0jEHPpggQKXpIYZC3tLCEMTujm891mJ/S8i0fanky4J5jRNbRXTRYHqbP2lT2/ZC4AAjXJ865kos98pNZmKZktWdDF2yYXJlT+4PGDprNGi1SplnNdSELYNvee0fRu6j0ySxcFXYY/MojuPrn2cY+zkQ74uNUU1AGvWIlltScSWmHr01IY8231vA7QMu+UAZ06UwA0Rrp+qsHHE60f1gIHSQ4RkNz8vscLrFencs2eNdKXEqIjyyjUW6/gEpPTnUcTb15EJ84DiclVIkxGGme2eVAAo5VBWJCbZKRAnxAlRabNbjnXoNTk7DMXUntTC3ABaiFuqIgw70hnQ2MWhXNoh7yWtc9YHeSMrjrMNc8diCnsvLm+CRY0I1tqCuhbbJCiHqsT3TMJnBcd+fcGBGu/NkgHaxMZCbWBkrJX48Aayms+JWq8ZkRTwI8xzanS2r2L2ZJuvqfPfLOBtlB4c3DBRyNDkX61xpPmdf569NVZwL54ExzOTGFWpC5qj2iS9xrmZZb6FP3XV9e+EAAOVsE8p2kNcthPoMyyhKA8K+/HflnxybrsULszj7z5CDp7CO89Uv87wC2QEM+vYNVNWkDIkbly9NaTUGM3qDkDfdh XnA690jD yq4Lk3RZkxFcbwtfFc52Ry+bLo5n0TPly+DTkenmogxiKmZCS5Bd/MW4l9EjATgPCEDAkRaXVpb53xXNEbhcqonYjrZFcCA9yAGnwrjkEZJQ0/0aGrivBgoJ8e8LIZ0Y0veFBstUEC4er3oXgGqBy5YM1EQ== 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: Put cgroup v1-specific code in mem_cgroup_print_oom_meminfo() under CONFIG_MEMCG_V1. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- mm/memcontrol.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2c0605bbbb31..b69abd327549 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1532,6 +1532,7 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) pr_info("swap: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->swap)), K((u64)READ_ONCE(memcg->swap.max)), memcg->swap.failcnt); +#ifdef CONFIG_MEMCG_V1 else { pr_info("memory+swap: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->memsw)), @@ -1540,6 +1541,7 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) K((u64)page_counter_read(&memcg->kmem)), K((u64)memcg->kmem.max), memcg->kmem.failcnt); } +#endif pr_info("Memory cgroup stats for "); pr_cont_cgroup_path(memcg->css.cgroup); From patchwork Fri Jun 28 21:03:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716626 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 4BAF3C2BD09 for ; Fri, 28 Jun 2024 21:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8450F6B00A3; Fri, 28 Jun 2024 17:03:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77D906B00A4; Fri, 28 Jun 2024 17:03:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AD0A6B00A5; Fri, 28 Jun 2024 17:03:59 -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 345A46B00A3 for ; Fri, 28 Jun 2024 17:03:59 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DF7BE14061D for ; Fri, 28 Jun 2024 21:03:58 +0000 (UTC) X-FDA: 82281524556.12.009B756 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by imf21.hostedemail.com (Postfix) with ESMTP id D3B311C001E for ; Fri, 28 Jun 2024 21:03:56 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qScH7uId; spf=pass (imf21.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.180 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=1719608618; 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=Ftjq9d47t8edbds95FzE0JhHDxWshorq1wfRXh80pJE=; b=bjkBoBK9jcosW68cXKzWVDrBh3RpbeRckeKwxhMHVC8K3KPFELvHIfgNucUHHjRIaiSnsX UMNgeUW4t8X6BvX8+ejtB5sFrQ7GQUiUuEi28fuF99nKAOUi4pApEuTWYZ5oVdvlWFF+G4 dpA+kRkrR2dkFY5oCf4GJ3JiINBlblo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608618; a=rsa-sha256; cv=none; b=OfnVRKvA+aENBVtCQZbLAN1alSMwUEuHTgKREYOpJrznuGA160bJ+0VNiDLaQJis4QnD4Z VPApdeQXNoVTwN7QTOTL7Mj7WmziXaMuinkxvlGYvBnSgNLpVOQbyIu2cr3VNwpsQZ0h2M 4Yh9G0Y9gtlRT55DhCOLWbazL+bJm/w= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qScH7uId; spf=pass (imf21.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.180 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=1719608635; 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=Ftjq9d47t8edbds95FzE0JhHDxWshorq1wfRXh80pJE=; b=qScH7uIdUhSfmN6nvR0ns/TrqGeFu3T4kb4Qb1WEjtGASe1cRWhPo/8WujA5868tRA/ntU Qv1YDCW1CXcDnM7amCXludxngCWUhPkf+uTrkSiIPsSPh4N2G/INANYAWA8vJE9HtcH6rd 7MPWOjrK/oVLHuzKgcF7Z1x+p8nCgHQ= 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 4/9] mm: memcg: gather memcg1-specific fields initialization in memcg1_memcg_init() Date: Fri, 28 Jun 2024 21:03:12 +0000 Message-ID: <20240628210317.272856-5-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-Stat-Signature: iq58p7cu7bb94dmnz8yqde18nwi6h6zs X-Rspamd-Queue-Id: D3B311C001E X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719608636-657425 X-HE-Meta: U2FsdGVkX19j9SKBGyfbsMWUXweUp/OM91N0vFS41RU5ofrDcDjJrRQWBeVfgwcWuj8GyGpFuQBeSYEfgTQuQrUr0jQj1BprDDI58srjlCsEJoAvSYykXzvU/R3h5K13v/EVmZ0+jnqK7x/7Vwxk7BCDxMFNhPOWFFPb5LvFuAxEzvvMTNfpmq1fjpqzRbblLQifmvRYh/8GB9hpPT8vWu566a1zfADazwLel2wXoS2sKCHqxE+Ubo66k1XhHH5H+3n3bFCGt1khdh8yVum88+dMjus/0eH5BLtcG7IXcpEQ6O6Pc1kQrIRmYIPc0ra9vNJp+SkpUy18U2g4MaPCjUgUniPaVFivjLk5MZAw7N9tGpVnT0VDU/AfZl0jMEU9pHFPosgEXHeLu2dxPYuNd9Q50A9Bm+5KaOF+SEmxFHHE4Tv1+8O7JMsrX1l849I1TbCN8wwHN6XKtzS2j9hOmqppHgUaH7m1OhgVgzkiYEKvbgNf5C9qehBaJn/VvjOah5GhMgcd9lucc2d+2i8tKTJrZGQsjFGh2jJr1537CDUJvUwZQLc8madZY0wyyR21Fm8oE1h6YRz965Pm+vafuvBiEyVnHypUq6h0Q4XW8WWeSOx+pBdyUp6lQhgWroXlpzFXZplRmeqmGN4qMQvAW9Jdyd4vuODchYxssz2TU6Sk+xw8iJohd5EGHm3M/S4NM9w4dv2aTUIuKgDtNi/Mb97VhhTPEyk6HLCx9QAfBotzu/7wfF9PdlLkN19YBEohL5Sz9df59zF0VLxmYRUl1ZTJuzbx8f72ZhRFmPKStQNvIAdR1UxEOYsnlpej57SuBaCoIY9tOAwUemqQ2ClioWLGQlROzx5DDSWw0GYUz4cF3dbgFXHIZnj1p4jRtYAGBICYfK4/ul8YOLWVF8CHUFm7ld1TxWzzFH5Cj4EOoyzP4A6wrRcCJhKQGnOEVvSCublttsvxzScewtWpW7a 1uDJYs0O rxznDXSNxsPedEB85ArENee3hpCTcq2+3i5h+pao5LqbF0QqCrB9bZPjOPVqvf7pmOZXjz/bhCVoHgGqQ9iJTHyP2JO8GxNdgshbG+s4WjxhMryt1e6WpeTIBlHW71v071QkDzq/6NqAtRt0W8lmAdhABzQSlEBqNhpvB 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: Gather all memcg1-specific struct mem_cgroup's members initialization in a new memcg1_memcg_init() function, defined in mm/memcontrol-v1.c. Obviously, if CONFIG_MEMCG_V1 is not set, there is no need to initialize these fields, so the function becomes trivial. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- mm/memcontrol-v1.c | 9 +++++++++ mm/memcontrol-v1.h | 2 ++ mm/memcontrol.c | 6 +----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index c9b4c3e4797d..5fa48a45e34b 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -1961,6 +1961,15 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of, return ret; } +void memcg1_memcg_init(struct mem_cgroup *memcg) +{ + INIT_LIST_HEAD(&memcg->oom_notify); + mutex_init(&memcg->thresholds_lock); + spin_lock_init(&memcg->move_lock); + INIT_LIST_HEAD(&memcg->event_list); + spin_lock_init(&memcg->event_list_lock); +} + void memcg1_css_offline(struct mem_cgroup *memcg) { struct mem_cgroup_event *event, *tmp; diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index c8e5119223bb..6545fa1b7d09 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -76,6 +76,7 @@ int memory_stat_show(struct seq_file *m, void *v); /* Cgroup v1-specific declarations */ #ifdef CONFIG_MEMCG_V1 +void memcg1_memcg_init(struct mem_cgroup *memcg); void memcg1_remove_from_trees(struct mem_cgroup *memcg); static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) @@ -124,6 +125,7 @@ extern struct cftype mem_cgroup_legacy_files[]; #else /* CONFIG_MEMCG_V1 */ +static inline void memcg1_memcg_init(struct mem_cgroup *memcg) {} static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {} static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {} static inline bool memcg1_wait_acct_move(struct mem_cgroup *memcg) { return false; } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b69abd327549..e78ed54d46d2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3624,13 +3624,9 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent) goto fail; INIT_WORK(&memcg->high_work, high_work_func); - INIT_LIST_HEAD(&memcg->oom_notify); - mutex_init(&memcg->thresholds_lock); - spin_lock_init(&memcg->move_lock); vmpressure_init(&memcg->vmpressure); - INIT_LIST_HEAD(&memcg->event_list); - spin_lock_init(&memcg->event_list_lock); memcg->socket_pressure = jiffies; + memcg1_memcg_init(memcg); #ifdef CONFIG_MEMCG_KMEM memcg->kmemcg_id = -1; INIT_LIST_HEAD(&memcg->objcg_list); From patchwork Fri Jun 28 21:03:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716627 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 912ECC2BD09 for ; Fri, 28 Jun 2024 21:04:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E6116B00A4; Fri, 28 Jun 2024 17:04:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F72D6B00A5; Fri, 28 Jun 2024 17:04:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 472016B00A6; Fri, 28 Jun 2024 17:04:01 -0400 (EDT) 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 23B306B00A4 for ; Fri, 28 Jun 2024 17:04:01 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C7136C066C for ; Fri, 28 Jun 2024 21:04:00 +0000 (UTC) X-FDA: 82281524640.24.C84C7F9 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by imf20.hostedemail.com (Postfix) with ESMTP id 9941F1C0020 for ; Fri, 28 Jun 2024 21:03:58 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mCAeERC+; spf=pass (imf20.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.179 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=1719608628; 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=4Gko9mOqc4M2HUbbQQMLzyuB6FTp1sWHdFkm9zq9sAg=; b=toZr7MvQTMcZ6gEaFwLx5O98H3MUHWAKlbRlVYjoZPyo5PbfiGtM+YFSbz5xaMFm5ETxWQ dUC9O4BkL0Skq+GtUiv5OCmhkEFDbeNaMWpL5nljrPIUmwYPkhVoHZFp8lOauotlw+gpcP SSmDZqG+7wmR97Y2yqEur3xb7coV7Lw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mCAeERC+; spf=pass (imf20.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608628; a=rsa-sha256; cv=none; b=s/RNuYznclFLu7amzkYAvXTgIgXsAE1MuSvLHwKsK6LldW6PUUzO+1xK9iUn1cmOBoywrM 6q6PccJs+w2v9eUJ9lzgxc2u1mpyly0D53d4YZuPaYDOdiEgFWZ6apSuyHXga0faaCRM55 gN07yet5fi/vV3DjaZS/LTtLwbn+p9U= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719608637; 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=4Gko9mOqc4M2HUbbQQMLzyuB6FTp1sWHdFkm9zq9sAg=; b=mCAeERC+c6Yj5vycSKci8wNhAB/nesVI2GHgURAokGRwV7rW3HGEm3uOVZsrp4Gu1bOnqk a9zM6zNYkc0TTI4tfWxEsWmjW8Hxkx8JhWQ395qb6r8Gzk+odTsPIaX2TgqBCkN6Z4sXq3 v3sBwt+Un5qFd0rva1oekEX3RG9Vaqo= 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 5/9] mm: memcg: guard memcg1-specific fields accesses in mm/memcontrol.c Date: Fri, 28 Jun 2024 21:03:13 +0000 Message-ID: <20240628210317.272856-6-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-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 9941F1C0020 X-Stat-Signature: h8mk14xb6n3ymqr8gak86d81ah7k7udg X-Rspam-User: X-HE-Tag: 1719608638-231266 X-HE-Meta: U2FsdGVkX19JUQFukBGIp0IG7gy/+/RUlguhmuAmz0C4pMxQShneqkhhAnjsgtss4zBYvfMmyLkEPJSL8CuhULJbvLdiI9W/jsOqkBWmKlEcm90kDQlh5mSw1/Nu63WJ0wnxpEBurvbYeBorFrXU52ELVCObFiYJp0fwTogtyNrHH2nWvX6bE2HNgtzzZ51bn8r/gVdKGl2twt7Vit4SplDXchdZD6ftn1Do/mBxkp1HrGlltGCvtNQRwLKXN6LWJGyhte6OwE/LLn1YTrMVPm12uUFQVrgbkdMySRUAEWC8Vq7ZrgPSF+JWHfbIe1Gb/uqE2cCYH6SdiBPB+S9j99jryOWHYlGytJPZ9u7YzB3dWKQhh1ElYv11BHhCjFqEfVk+MPIgZt6EVlzL4SCZ2+bB5cZuhA+f077x54JJlYAYFfr3mIubWALnREyXrTV3WXfS3dHSu396BSgOmznPBZ3PaQ4q/LqP3s7gDS9eeU7jmocj+vM6m+Lvdd5ZMmDz8OMdkl/lZp8v15uYtCUoDqZLm70sp41J8k7gzIg08Ln/WeH6yXMmGKAA+6hu7ZpypuHkU+yFxF34K+NCutqRS6cUVOz/vIP3x0jmHswkQVhP3CuN9UGR61IskMu6MuEX3GKpJhX+K2cPyIS3Vjdk3YWx2CY8tCbqhSFGCQeqHGXqd+WX80th3peDGYURHFzgUILQIg2q+yCTnjUg4B6MSvw1kddFcKRUuZab/u2UuxRqg2vvVlQOnu8d5MYdN3r5Ydy6xk29SZpqNZXF0cOB1ACJifSjXh7tIkjn6ipXffujlxZWI6bDmOIL68yBUJu9c0THTwCvHE0lxNjOmx5HR1nB934c/n3cvDCQKgDLQCjRye6GcRESSpgbcFEf5Nkw7Bj1UHBMGnEzcAvpyCn8tdNOuqYK7wBt9TeDjvDHdyqDHGzaGe6PJW+2MjQR4tgY88BC5QZnG27j+XlcTgL 1HhSkW7v Zns4k9RUNyiiFaFj8e5Tfo4r5wyXGvxM/W5sOJaO1aEZSMVoEoePKHA3PvdB5ZG8CctiX3j1pfLtBdq16MMB7VrST1lmMF4P/44rda+bsFeGCE1c= 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: There are only few memcg1-specific struct mem_cgroup's members accesses left in mm/memcontrol.c. Let's guard them with the CONFIG_MEMCG_V1 config option. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- mm/memcontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e78ed54d46d2..661e3a70e685 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3672,20 +3672,23 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX); if (parent) { WRITE_ONCE(memcg->swappiness, mem_cgroup_swappiness(parent)); - WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable)); page_counter_init(&memcg->memory, &parent->memory); page_counter_init(&memcg->swap, &parent->swap); +#ifdef CONFIG_MEMCG_V1 + WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable)); page_counter_init(&memcg->kmem, &parent->kmem); page_counter_init(&memcg->tcpmem, &parent->tcpmem); +#endif } else { init_memcg_stats(); init_memcg_events(); page_counter_init(&memcg->memory, NULL); page_counter_init(&memcg->swap, NULL); +#ifdef CONFIG_MEMCG_V1 page_counter_init(&memcg->kmem, NULL); page_counter_init(&memcg->tcpmem, NULL); - +#endif root_mem_cgroup = memcg; return &memcg->css; } @@ -3820,8 +3823,10 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css) page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX); page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX); +#ifdef CONFIG_MEMCG_V1 page_counter_set_max(&memcg->kmem, PAGE_COUNTER_MAX); page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX); +#endif page_counter_set_min(&memcg->memory, 0); page_counter_set_low(&memcg->memory, 0); page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX); From patchwork Fri Jun 28 21:03:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716628 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 C85B8C30658 for ; Fri, 28 Jun 2024 21:04:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3FEA56B00A5; Fri, 28 Jun 2024 17:04:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AD8A6B00A6; Fri, 28 Jun 2024 17:04:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D94A6B00A7; Fri, 28 Jun 2024 17:04:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EA3756B00A5 for ; Fri, 28 Jun 2024 17:04:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 815D6A1702 for ; Fri, 28 Jun 2024 21:04:02 +0000 (UTC) X-FDA: 82281524724.14.68749ED Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf09.hostedemail.com (Postfix) with ESMTP id 5F8C4140014 for ; Fri, 28 Jun 2024 21:04:00 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mHSdMIeh; spf=pass (imf09.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.177 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=1719608630; 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=9l0JWNwiJR4vL4yVXqOBdtMhTUxMdQRWjUtEfPwLXqg=; b=pewOtvs0ntwmqWXdjvui5DNc3k6uiB85J79g0Hsq+nJhaP0PJfwJyqxytbAmw/DPZprOBW a2SB1RQbtdeHc/Mjm0gGEE6WEJ1gAJwoMaZY5JcYS29dpVLkhmij72nseQDERxNFbvhEON VASE/k6GoQjoi+mB2b50SHokpcqbT2g= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mHSdMIeh; spf=pass (imf09.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608630; a=rsa-sha256; cv=none; b=lAcDHu14mIi4JOivw0guWy9GtI2TkeAKuAwVxSxsn4HhTmF0o25+uunmjYmWrfd5P9OQVj StCpZ5YG1VS6oNlHJ/bDuQqge5ILfuQu3eqwOkSXb8GRC29fGZju6qRsYRGySHdKeRSs2n FoaSz/sK/AR6FqQP1EGHKoB5ECHiNsc= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719608639; 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=9l0JWNwiJR4vL4yVXqOBdtMhTUxMdQRWjUtEfPwLXqg=; b=mHSdMIehmfU80tUJ13pZQ5VJl08J44pqQFvWQh7HCi0HobI2vAa9le3PXL2LVITuRM7jfV ZbPYZXPvjueIrJ5ZFTUtdCNBYN0/RQ7nwmOF7mYOr06/IRW9+FAPlz3QzGyQ6PGml9o/HS 9EKtVQoUKle2Fb8KcYURkjqecYYRsic= 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 6/9] mm: memcg: put memcg1-specific struct mem_cgroup's members under CONFIG_MEMCG_V1 Date: Fri, 28 Jun 2024 21:03:14 +0000 Message-ID: <20240628210317.272856-7-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-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 5F8C4140014 X-Stat-Signature: hx3kezjhydhgyar745w581ui684nz6fe X-Rspam-User: X-HE-Tag: 1719608640-183994 X-HE-Meta: U2FsdGVkX1+4WxHcohbcSv0sGwC6RyPxitp21MmfVH8tAwmlYsz/OLAEQIDT+Ygr8nbWaC0Ogezm76wDDoRprEBnSf4tf5JLfPJun3N9gqvZbKQQsV7R1i+NIeeGOj8melphcsYJPBeQCYpTELdmRctJXDSmiw1+44N/FuMkKqMmGroW6osUKrvqbdc8gscx6X8JlD5desPFuAG3WALG0mgOWitP+jREo8OYNAKaLh3i0I//vr8KyTEn5jrsjfVmz/hDEOt8IqX+GnPjn4N6nuOAgPI7yY5BSPNu2qtjl3urcsLvePoxWDaCn0MIHAZlgtn0AUHfIl3amHSap0LC4YRlQOGqDrI2Whwwp+9/NvEUFIy9MSti2kczelVg/mb0oNWRaJ2qTeY8KRkXo8Mc5iKYk67sh3oPOFAB/22JrDPKzU8kbvACKNhrp/6GsXP17RU7qLlw6ng+MzT2tRCepnF6RMgrC2ePyfhp0hAgHr15Jl3VJXnivO/+Ka5v2UlCpGJlskmlXDh3HJiJTM8rUdeGJ0goPHPZFZIVOGppd4FnC3dRSQhuLIh/+f9+WS6fBE6eIjFMO1l75c5x9oB1PczfbJodUGgwaFdoAiSFqZGdxlgg1knjf+jzFTyKCqgoDTQZ25plLI+qxRNldaFDr4PjFMvE/xB5DFfPP96v4ts9puGM9pRsBoZTSe9ekxsjYE1Uv4XTzZjzbIRyPqjVzsu82t0l0zX4QQ6JrCc6ues87y0DATWJBWqBh8Zo59sdWaHI4I8Gpjh1h6pF4G46VBmsZ2ujtO6ppEWQs38aD/Zy2i8JHaa8c0fl8BBGgoqiFzL5iH4fdoXtkj2uOHu4MzBAKlDTcusQ8R4THJv6gioqVOauxQ3O8e6W0CyyNBc4A1nEBgMdhniZVnbWakHG/V79t7qzqer9GN0Cp56oF1yGQCBI56Fg2Y2WVUbkKw8JoUmssNz96LVReFZV3ac jdSyczn8 C+2yJ3o4h1MOkR15TPPsi4vbFkqIEEBcTz+5qDfpargvO08p0DA/zsE2hfZF8IT2vZ06X+DVMNEmIviPwxz+OzJDmd54VuaIrN7ljwHYZzf4k4AzEQQrQcXbNkiOVdsXc3z8/rPIls9PksXxnxWZdIv3/kc3is1q3csEbNCzKGm2wv0vcY8k554K9MXeuGIKPqU5UfyFCGSzS4EM= 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: Put memcg1-specific members of struct mem_cgroup under the CONFIG_MEMCG_V1 config option. Also group them close to the end of struct mem_cgroup just before the dynamic per-node part. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- include/linux/memcontrol.h | 103 +++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 50 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 44ab6394c9ed..107b0c5d6eab 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -188,10 +188,6 @@ struct mem_cgroup { struct page_counter memsw; /* v1 only */ }; - /* Legacy consumer-oriented counters */ - struct page_counter kmem; /* v1 only */ - struct page_counter tcpmem; /* v1 only */ - /* Range enforcement for interrupt charges */ struct work_struct high_work; @@ -205,8 +201,6 @@ struct mem_cgroup { bool zswap_writeback; #endif - unsigned long soft_limit; - /* vmpressure notifications */ struct vmpressure vmpressure; @@ -215,13 +209,7 @@ struct mem_cgroup { */ bool oom_group; - /* protected by memcg_oom_lock */ - bool oom_lock; - int under_oom; - - int swappiness; - /* OOM-Killer disable */ - int oom_kill_disable; + int swappiness; /* memory.events and memory.events.local */ struct cgroup_file events_file; @@ -230,27 +218,6 @@ struct mem_cgroup { /* handle for "memory.swap.events" */ struct cgroup_file swap_events_file; - /* protect arrays of thresholds */ - struct mutex thresholds_lock; - - /* thresholds for memory usage. RCU-protected */ - struct mem_cgroup_thresholds thresholds; - - /* thresholds for mem+swap usage. RCU-protected */ - struct mem_cgroup_thresholds memsw_thresholds; - - /* For oom notifier event fd */ - struct list_head oom_notify; - - /* - * Should we move charges of a task when a task is moved into this - * mem_cgroup ? And what type of charges should we move ? - */ - unsigned long move_charge_at_immigrate; - /* taken only while moving_account > 0 */ - spinlock_t move_lock; - unsigned long move_lock_flags; - CACHELINE_PADDING(_pad1_); /* memory.stat */ @@ -267,10 +234,6 @@ struct mem_cgroup { */ unsigned long socket_pressure; - /* Legacy tcp memory accounting */ - bool tcpmem_active; - int tcpmem_pressure; - #ifdef CONFIG_MEMCG_KMEM int kmemcg_id; /* @@ -284,14 +247,6 @@ struct mem_cgroup { struct list_head objcg_list; #endif - CACHELINE_PADDING(_pad2_); - - /* - * set > 0 if pages under this cgroup are moving to other cgroup. - */ - atomic_t moving_account; - struct task_struct *move_lock_task; - struct memcg_vmstats_percpu __percpu *vmstats_percpu; #ifdef CONFIG_CGROUP_WRITEBACK @@ -300,10 +255,6 @@ struct mem_cgroup { struct memcg_cgwb_frn cgwb_frn[MEMCG_CGWB_FRN_CNT]; #endif - /* List of events which userspace want to receive */ - struct list_head event_list; - spinlock_t event_list_lock; - #ifdef CONFIG_TRANSPARENT_HUGEPAGE struct deferred_split deferred_split_queue; #endif @@ -313,6 +264,58 @@ struct mem_cgroup { struct lru_gen_mm_list mm_list; #endif +#ifdef CONFIG_MEMCG_V1 + /* Legacy consumer-oriented counters */ + struct page_counter kmem; /* v1 only */ + struct page_counter tcpmem; /* v1 only */ + + unsigned long soft_limit; + + /* protected by memcg_oom_lock */ + bool oom_lock; + int under_oom; + + /* OOM-Killer disable */ + int oom_kill_disable; + + /* protect arrays of thresholds */ + struct mutex thresholds_lock; + + /* thresholds for memory usage. RCU-protected */ + struct mem_cgroup_thresholds thresholds; + + /* thresholds for mem+swap usage. RCU-protected */ + struct mem_cgroup_thresholds memsw_thresholds; + + /* For oom notifier event fd */ + struct list_head oom_notify; + + /* + * Should we move charges of a task when a task is moved into this + * mem_cgroup ? And what type of charges should we move ? + */ + unsigned long move_charge_at_immigrate; + /* taken only while moving_account > 0 */ + spinlock_t move_lock; + unsigned long move_lock_flags; + + /* Legacy tcp memory accounting */ + bool tcpmem_active; + int tcpmem_pressure; + + CACHELINE_PADDING(_pad2_); + + /* + * set > 0 if pages under this cgroup are moving to other cgroup. + */ + atomic_t moving_account; + struct task_struct *move_lock_task; + + /* List of events which userspace want to receive */ + struct list_head event_list; + spinlock_t event_list_lock; +#endif /* CONFIG_MEMCG_V1 */ + struct mem_cgroup_per_node *nodeinfo[]; }; From patchwork Fri Jun 28 21:03:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716629 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 02B77C2BD09 for ; Fri, 28 Jun 2024 21:04:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CB2E6B00A7; Fri, 28 Jun 2024 17:04:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07A0E6B00A8; Fri, 28 Jun 2024 17:04:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9B466B00A9; Fri, 28 Jun 2024 17:04:04 -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 B045C6B00A7 for ; Fri, 28 Jun 2024 17:04:04 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6BF0A407AD for ; Fri, 28 Jun 2024 21:04:04 +0000 (UTC) X-FDA: 82281524808.02.EB82467 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) by imf12.hostedemail.com (Postfix) with ESMTP id 5897D40013 for ; Fri, 28 Jun 2024 21:04:02 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Ed+Zv3p6; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719608621; 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=7SlGJox9o6WayxiPYLup7HEpqh8S+qxFa/JeE0i8vpE=; b=n0ri8D6fx4HvMezySmpX7ugZlbgzk9HX+p/2UTD96dqd8jWXTChirrOlxKL3NKhh9nBdfy +UgTMuvhkF3bFlYM2ZI4K9/PIqKlqOO3WFQ6HrLCI1bqqTSLz7/g8Z1eVkzQNNW+R0EbWa VBl0zSGRpcGZKJ/kKe6Z1fuWUR93UIY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608621; a=rsa-sha256; cv=none; b=CgJRpfw7Q5+tAGwAFMld8O9ENwnVAgXP1tLK7HGwTPE9J6s3HmUPZqsYL0bSIAnfItJDIr 1OqdDaS439kVM3nGdTkVIDljOVTWSABK2EfX7jt2TWC1CqDUk/9f8KYczV3ceByj6wod2m OywyLDBre+/xy8N+k44jaVLzln+KMqE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Ed+Zv3p6; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=roman.gushchin@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=1719608640; 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=7SlGJox9o6WayxiPYLup7HEpqh8S+qxFa/JeE0i8vpE=; b=Ed+Zv3p6n3UBjF4sV/5LuICPBPcAFb8qH5jp86026JaxfP594YrwBi2dcypRMGgQFg8Mu+ c27SEgkKYtawry059CYJABt50s2pFEjK5BW0m5whL6fa2rAn7uDZBhJ2lbl6T+/4052ttj zSrycuARVaEHJzpFWNaLgkje4URL5+c= 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 7/9] mm: memcg: guard memcg1-specific members of struct mem_cgroup_per_node Date: Fri, 28 Jun 2024 21:03:15 +0000 Message-ID: <20240628210317.272856-8-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5897D40013 X-Stat-Signature: gc6nou8dyxxpqehb5g91mae3ju9mendi X-Rspam-User: X-HE-Tag: 1719608642-508830 X-HE-Meta: U2FsdGVkX1+nCOMj4Rcj5t5EPu1YIYlNBl5ras2RT+KFCnRFxE28MCMsBHtbK7uYRSM15Q554vZ7EiP/lQ3n0dcMcXr8VatiBXvr1fqLZVr63fPeEdBvZ2DEly1TS4KNeOY8HDuDcBRmKR15tHqZ/j+cXZ0k7xH/GDRvEpPIYBGWJHc8N5Y92PLItz706AjVlygSqzM/7HPWb/G6Exkk/PqXP9tN8zKlp4vQ0l58UAraHebj+xpYNca8PaqKuywXzpNhsrS4mpkGELLyLqpzhksAwiEzztSC3dsd5UEgZLaB7UDV6f/xGItIgyuNr88Aw1wdivKCoSXo9mTICCz4po9Stt6WBMDOAcVFb2QeUse9t9zPoED2wQTSWRcSPKWCT1/77xpz56r7hFgCBzSfcbQlw33EJG192VvXR+FPuEl6/fM+qOv0r8Goo33dXRkQLp8811GjHQW+WqQe1Io+5KyrtQqWn67nULtCRLTfHrcF51tlxpVm3q9Y+pvST4cQwR0E4oqU6JPefebxoFNg9sVdKso9NnVZdzR3GQ81BUNj9pyoh7ktMVrH8OP6Cy1eMxql7zHlciU1YgFEb3u35807X/5Uv7QyulmnDYrYza7E1rHBdehV48E0SHJhO+gss5lQKSh5LyBID+4hL5JzQxrxD4nRw/IiZ3nI2rpy5KC36OKXIPsFJi7+1APDRnUhDWeXb7Ie8w14uM1kV5DR1XeEPs2VoSe5haIyKA0MtmtgM+BXe2ByXBw8zh7L0KACTXr8603DND08iIrljG77slnn3esmrQOLBbbIQnv0iPxZdPOGnb9FjeNIzPIOZOGAAa+F4ah+rMxrdhN6W0ECJrLZjZRI469agc/tUes1/UTtp8kE2cDwVbtjhPHCOdVzFyrsMq39Y3WW/aPePF+qnqUXG5l4WUPAq2ue6UJWiUzwTNzrM1R6VdjMoKZlqBBlnn8Y5qI7mprtkbvGlnB Z59lbsoc weHwcQfkohhhUzzB7nEhCo7Ue+xp1Cppliv0TCgcAb2Xvtf5g0EXaztwVFJiAxmKJjVI0Zgihcsfl4YCgQYu3WC1pwDP9JUdjk8E8P8pDg5WzfqL0S46a12YNURH9rhmodlMzV2MlgvvoSMJXclTnA8+eG3Be7JUlMih9fxTRVBvEVAczbdfm9gzDGA== 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: Put memcg1-specific members of struct mem_cgroup_per_node under the CONFIG_MEMCG_V1 config option. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- include/linux/memcontrol.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 107b0c5d6eab..c7ef628ee882 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -92,6 +92,7 @@ struct mem_cgroup_per_node { struct lruvec_stats *lruvec_stats; struct shrinker_info __rcu *shrinker_info; +#ifdef CONFIG_MEMCG_V1 /* * Memcg-v1 only stuff in middle as buffer between read mostly fields * and update often fields to avoid false sharing. Once v1 stuff is @@ -102,6 +103,7 @@ struct mem_cgroup_per_node { unsigned long usage_in_excess;/* Set to the value by which */ /* the soft limit is exceeded*/ bool on_tree; +#endif /* Fields which get updated often at the end. */ struct lruvec lruvec; From patchwork Fri Jun 28 21:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716630 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 39656C2BD09 for ; Fri, 28 Jun 2024 21:04:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A3376B00A9; Fri, 28 Jun 2024 17:04:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9542D6B00AA; Fri, 28 Jun 2024 17:04:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C85B6B00AB; Fri, 28 Jun 2024 17:04:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4B2C06B00A9 for ; Fri, 28 Jun 2024 17:04:07 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 08F9D40760 for ; Fri, 28 Jun 2024 21:04:07 +0000 (UTC) X-FDA: 82281524934.06.3D565D8 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by imf12.hostedemail.com (Postfix) with ESMTP id 0ADFD4001F for ; Fri, 28 Jun 2024 21:04:03 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=AxQxHOwo; spf=pass (imf12.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.185 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=1719608630; 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=shh94uljBJBAw0NmdKQ5/8JVCufhJ/PY7mLMRWfBY9w=; b=dz17Ru4ETgD8D5gAWv2hcV592BqV4y5Cl17RixOrDw2g+Huj7OSWzA++mfAY7YFars6weI 1aqFTwZIYxGqtesme/+q/XEPmqmzyOejhU8E9571LSzT9ZXSOW7BV6sv4Bh4tD/5PzIa+Q fVvAHvDhpWGQkytXkwX/qehpt1vpxd4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=AxQxHOwo; spf=pass (imf12.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608630; a=rsa-sha256; cv=none; b=il/llT+8JogRgAxAn88WpH46vSB8g9QTTRNzH/dKdJDN9xiLkgM3TWsTYVnV8jmzuBvIpZ 8fzoiVXc11ElpO3bJ9Uo8v+5xlm7UaOdaPNFN3tXzuAlZZX9q/d2unZdntRi6tCyVfBREx hE4uo/37ajvP/+6aXEJXNUecCu+jIcc= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719608642; 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=shh94uljBJBAw0NmdKQ5/8JVCufhJ/PY7mLMRWfBY9w=; b=AxQxHOwohJvObzrg/JOuI9tKWrY6KLKGsGTTTeEwGVNcVD4DZmeJulWmaac1Kf9yRId4z0 4XilmuxIQnejQP1MwwDkF3W66UDLjc+GL8hRoRpgS0BbSZkbvujnqJRtXQx4N+4rj0jb50 rWGud2F7XVsBx5xOBoECY2lou0HhDuo= 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 8/9] mm: memcg: put struct task_struct::memcg_in_oom under CONFIG_MEMCG_V1 Date: Fri, 28 Jun 2024 21:03:16 +0000 Message-ID: <20240628210317.272856-9-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-Stat-Signature: 6r4aj6m37nuyxqa9oge1sdxuq8jjote1 X-Rspam-User: X-Rspamd-Queue-Id: 0ADFD4001F X-Rspamd-Server: rspam02 X-HE-Tag: 1719608643-895570 X-HE-Meta: U2FsdGVkX1+80ZABB/01+dcGdlwUNqnYQs7/h8+y2X0gg5kchYa5JyKpejXpnqp6IzfkChsdpOcCdfoDPUXSjo3bxyGI+IL+A9LdTyVJXcq2dEx7DcBS3JFthaRqFwlBnYAABf24bse/YF75gAgaFARiO427NYxSvHRmqmTYLVMAgqQ8O2vIn1CBXw3rp3YYd9WJoeGhg2ExfpVN4giqz7GkI6RECnU4ywpg1sM2h9DQ47elKBXCDm8jxCXt2NK8rf8B0UwBN9nLKLPu+qdsxEXAqnN33cgdES6DR1D4FsEtXfd7BF06QYPojTBz7RtbYoHqmslVyMlJY6nTGVPyE58gj/2JI708cp12zXHwGJOTwKJgwwnWyqO1tALx2+zvEuxO7egItE3bWQ9bVbWPPzVey2Xp2z7XpxVmP2Iu5EsYtbbJrKlLI2EeeV4vz/nf1lJ4ZtP+2/zZ9EZz/7yc7aKr8D1eF53Ize876Z3WGNXuA0fRs84j3VZOdpBX0zdMQG7m9WwcLMdyRher0Z8qgJkHhLSb3CnnV8DllrcvtoFeQfX2htTumwLs+S+0Rzo1YY0ij37i1nsrkHvqL0rQT4SSrnhLJeK52wBa2D1yHp4xQynUgsd+9tj7VCxFNvmupU4DiSi2Sdf+3FzyGgfd4SWOLl+Om8jr3svFh9Z8hUOy9tKUEU443n0GPdQX/sosC3hv4XPEEsd6Kkz0pgPj578HjI9sddyXwtc8mFzQm2VrNUk4H3l2OflUEH2yBXmqGQw7TQsf6XJBVDOdYgsKb8587UelQSMX/tKVUbvh3p+LKeBk9wAxBqWnFerMr9ZzCvyCiLdDyd+cqbk6O73q7H3mhvsznUs2iIsbdAuicI49/MLaImov/7QxYlGuRKqBOpWP0J906VSZ7msjrP+x5GaYP7w6D8xPE7vR2GvixdiVJX5xzL8YBtO6LyfRf0BrOL8qJ6QS31yPGpDs8fU Ud0m+ILS gHWNGXbAR89bNMzhT1Rtcr3AXMfwmusz+/NowAx9zH9Ga9Axfv5RQWjg0t049+OsopiWGxQEZ4kGuFqwlOb9qp/0jIYmvj4pKSYbgOzBlJCapcm0mk8AGAfAozVw4Me77hFCjG/fdcXQfgJ8GZ+nbCW8gpRISvM2XWQO4 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 memcg_in_oom field of the struct task_struct is not used by the cgroup v2's memory controller, so it can be happily compiled out if CONFIG_MEMCG_V1 is not set. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- include/linux/sched.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 61591ac6eab6..2a16023e8620 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1447,9 +1447,11 @@ struct task_struct { unsigned int kcov_softirq; #endif -#ifdef CONFIG_MEMCG +#ifdef CONFIG_MEMCG_V1 struct mem_cgroup *memcg_in_oom; +#endif +#ifdef CONFIG_MEMCG /* Number of pages to reclaim on returning to userland: */ unsigned int memcg_nr_pages_over_high; From patchwork Fri Jun 28 21:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13716631 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 418AEC2BD09 for ; Fri, 28 Jun 2024 21:04:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2AFC6B009B; Fri, 28 Jun 2024 17:04:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD9016B00AC; Fri, 28 Jun 2024 17:04:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B273D6B00AD; Fri, 28 Jun 2024 17:04:12 -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 8C0EB6B009B for ; Fri, 28 Jun 2024 17:04:12 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4296F4074F for ; Fri, 28 Jun 2024 21:04:12 +0000 (UTC) X-FDA: 82281525144.23.B036573 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) by imf14.hostedemail.com (Postfix) with ESMTP id 8D3C3100013 for ; Fri, 28 Jun 2024 21:04:08 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=QpsayaNI; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608633; a=rsa-sha256; cv=none; b=oncBb0JY35QdF36NSCb5zX5ZaOfe4k4CztjCxok5vd5KgcXuqizH1g1AbEBZBo8v+Rhgjx m7hCOarVU27oTxef7v5G9rp3RtQqDpTA52dkW9C9FFGYN1tSRGVbhzRmzAdd1zJf86evz7 H835G0GLKfnk6NiqDS4WhLZm8t5AWmY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=QpsayaNI; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf14.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719608633; 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=oh6eW8o5ezSHh2B9Y0288jMuerKh+JrpdW4rG/niw6g=; b=bAMsC8FGALInIQ2YqMQ3GNTreiXJcfjbnDIKGxwtnCAAl5azg6PZ7u65z0YR2W87VKXawY HhT5ws0pnJMkT9/3IcH6shr3KyU2jWU3B2XUbWsB5kAjNyGvzHnP9REW3WmWLzBJ8OozAt dLehyhsoCwQj9/DjqmtLd57PD3m0m0U= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719608644; 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=oh6eW8o5ezSHh2B9Y0288jMuerKh+JrpdW4rG/niw6g=; b=QpsayaNInZKUdJVZpy1kkSsroiwMuaPQfyxm5rAk+pXTVr8En9fFyYvIwTr6R7dJ33uiKM 1AzxHnAG8Ddl6RthYG+usN6D76Fxc8a0sAv/JKBzlZOI8QTxzSeg84AglcBFGF+h71kNIF DTcfQi/0cnTValmfFuaVbPpyxydd07g= 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 9/9] mm: memcg: put struct task_struct::in_user_fault under CONFIG_MEMCG_V1 Date: Fri, 28 Jun 2024 21:03:17 +0000 Message-ID: <20240628210317.272856-10-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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8D3C3100013 X-Stat-Signature: cf8ak3djgxyho9kmeztzk3y98yz6sd5a X-Rspam-User: X-HE-Tag: 1719608648-656609 X-HE-Meta: U2FsdGVkX1/rDK3EBUbZgBk2qZDlvhNseaHDJK8sbNV8Id5BqZMFF5CGIbnQMJw3Olay/y9eA1wmzvhSkMijZeaj691vA+nTzw4SzYmfYz7O2YBDwrxvuBIuMUasWSCDS11dDZQIFgwQCSKi+gNi9dHcHpKx3cTPzxc01CBIqrjmRU6I8jEG1ISCK08MDPpi5BEchZtxbDtfwacE8z3cvYOi/Y+V2yTJgyoQ1ZHxIOXCo4cT5BCx8yE0/141htvPSpALIszy2nCJ2+mecr//Jxa+b/U9ERcENoXdGcQkgcOLEufr7hI1hdWgfnQuq8WOCLm20iLXTyB0evEuzKp7jYaScExAErNKJ9cyiCF2qA19EI5vtti5k6eTRP9qGoNsz9iHPC7nodKPVG2PVQ5RWQ48EcOFe/GY0TEbVqZbX4mgfKmI14+kSPy8WaDM5VfXpIGOl8I+tSFD+Fg6Nq0QmU4sXE0bluDqfRxmyasg1gCe1FLFE0tfpCGe3gw+SuaGJ2J+3cOHjX9+8vSWAYyvzOVwzzVWPqmD9J3udiWg4Bz8aGpW49RKheMCNJxCtwO3MpNymC8Mq69HLK7mM1VhzYSaFnEkMoriyikQST8knTcSpGgWyM4rMQb6aAZOp0/HkC5SBXyBpBR4bOxSPtlbHiU6Hv9H79fj1qk7LNOavPyLlZfbMi5pw+JgsPopp+avCaoAveJJs0b3a7/Ft3Gb1uqlIztf4g11pZ4SBb46HdsSQRveiqcZOJVZUedGqJbnp0KW8tGlyqysLWTF1QBRCyGOIlPZqMw03NIhwfAbQRfS9ibW5N9iOBPJNHB33Z/crpHgsd+H7qWHU/B7hSrEB2+NG28EXbIUMwiILsmNbl1CKX74U5T3HEvJhpe38OW1cA8kI0Kvo7oeP8oBDz2Rnh8uqExstA5DX8v3j3s5YResEWfqeFACZXe32ipDx2JrGlWJdArRF/eDbkllrYM h5WFyTZW 8AQEXZ89YP2qovqugd0OurS36yNfTaCxtn/P/265YEzWrgaPVgyD1UrYwlqoQQuY2a3hvNgMaA3lZzm5bWilohLI6uQdsLUyKQzTH/VYb21KRwDr4nOELoaALy2vPIkY8na62kpLlYp1J4l2kfWI+1TlKrxYGZBYONR6g 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 struct task_struct's in_user_fault member is not used by the cgroup v2's memory controller, so it can be put under the CONFIG_MEMCG_V1 config option. To do so, mem_cgroup_enter_user_fault() and mem_cgroup_exit_user_fault() are moved under the CONFIG_MEMCG_V1 option as well. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- include/linux/memcontrol.h | 40 +++++++++++++++++++------------------- include/linux/sched.h | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index c7ef628ee882..d0c9365ff039 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -943,18 +943,6 @@ void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg); -static inline void mem_cgroup_enter_user_fault(void) -{ - WARN_ON(current->in_user_fault); - current->in_user_fault = 1; -} - -static inline void mem_cgroup_exit_user_fault(void) -{ - WARN_ON(!current->in_user_fault); - current->in_user_fault = 0; -} - struct mem_cgroup *mem_cgroup_get_oom_group(struct task_struct *victim, struct mem_cgroup *oom_domain); void mem_cgroup_print_oom_group(struct mem_cgroup *memcg); @@ -1402,14 +1390,6 @@ static inline void mem_cgroup_handle_over_high(gfp_t gfp_mask) { } -static inline void mem_cgroup_enter_user_fault(void) -{ -} - -static inline void mem_cgroup_exit_user_fault(void) -{ -} - static inline struct mem_cgroup *mem_cgroup_get_oom_group( struct task_struct *victim, struct mem_cgroup *oom_domain) { @@ -1890,6 +1870,18 @@ static inline void mem_cgroup_unlock_pages(void) rcu_read_unlock(); } +static inline void mem_cgroup_enter_user_fault(void) +{ + WARN_ON(current->in_user_fault); + current->in_user_fault = 1; +} + +static inline void mem_cgroup_exit_user_fault(void) +{ + WARN_ON(!current->in_user_fault); + current->in_user_fault = 0; +} + #else /* CONFIG_MEMCG_V1 */ static inline unsigned long memcg1_soft_limit_reclaim(pg_data_t *pgdat, int order, @@ -1929,6 +1921,14 @@ static inline bool mem_cgroup_oom_synchronize(bool wait) return false; } +static inline void mem_cgroup_enter_user_fault(void) +{ +} + +static inline void mem_cgroup_exit_user_fault(void) +{ +} + #endif /* CONFIG_MEMCG_V1 */ #endif /* _LINUX_MEMCONTROL_H */ diff --git a/include/linux/sched.h b/include/linux/sched.h index 2a16023e8620..a7770c566c4d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -934,7 +934,7 @@ struct task_struct { #ifndef TIF_RESTORE_SIGMASK unsigned restore_sigmask:1; #endif -#ifdef CONFIG_MEMCG +#ifdef CONFIG_MEMCG_V1 unsigned in_user_fault:1; #endif #ifdef CONFIG_LRU_GEN