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);