From patchwork Tue Feb 14 15:35:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13140424 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 3E35DC61DA4 for ; Tue, 14 Feb 2023 15:36:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5F486B0072; Tue, 14 Feb 2023 10:36:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0F8B6B0074; Tue, 14 Feb 2023 10:36:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D73D6B0075; Tue, 14 Feb 2023 10:36:07 -0500 (EST) 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 7E9356B0072 for ; Tue, 14 Feb 2023 10:36:07 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4BDD780E0C for ; Tue, 14 Feb 2023 15:36:07 +0000 (UTC) X-FDA: 80466298374.18.56D7157 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf10.hostedemail.com (Postfix) with ESMTP id 64D32C0025 for ; Tue, 14 Feb 2023 15:36:05 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JLDH1SpO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676388965; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=PJFJn+wnfQ93Hq+pyo5t03C8oJTj8P03Wec2CRPfVhI=; b=zgxHZz5ROcdmknJ3HBcCpuPx8VlGpaRpDUlXQaSu3fkRwdjTOf/g3m3I9UzBMv+4cLVqJ0 toIvLR/jSgRY54X6Rr9LyT2hIFNQT7zcUdSa408Xxu+CtKH5uyQzoFrz42G4qf0CzGvsHM 2DrnZDIy4IMRyTwIvvxhNHK9bUSM4iI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JLDH1SpO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676388965; a=rsa-sha256; cv=none; b=HHi6wqaVTOQ3qTm3S9rEyaNsWVdpgiSCWBSYE93FPpZvayTTiSYXM6v0Yhu2l/v70UHqpZ IYY+vCnM7/xdDYoPl95jZD5fScWG5W7z0S/2Sc4lPwP9EjluKN4hXbbIY6zGjRa/zH+ZIl e0tbqYlCI7NbTEjLShGu6Lywx/uX7XY= Received: by mail-pj1-f48.google.com with SMTP id d2so15437576pjd.5 for ; Tue, 14 Feb 2023 07:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PJFJn+wnfQ93Hq+pyo5t03C8oJTj8P03Wec2CRPfVhI=; b=JLDH1SpOizG4+aE+b/Fa0p4yl3mxgETBSdZ8FQOHvTSakYGweYTx89qiGFWpmluMQa MvpF0knBFvddXBWLV/CZOz2fDy3jRjYdcyYTv+XzQrcjgr7KxMCC6qcz2HuN0hQYzed9 +Szd/BFBDT9p66QEqgwJ+xj3YI6wdkEKlUNXBzC5zCFVviscfokdP9FCuiYt8UOESPeX /luTneIcvwihsaZYsrH1NUkLE4KvusdXhkdnLk80KYC9OtnAkK+YlDttE8nShHDJYFij 8agbbMmtpU3NHx28XuyP5OG4BoawXjZ9/SqMWxR0LrYZsQIoKzanHM6flW6MKseq/5fm yw9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PJFJn+wnfQ93Hq+pyo5t03C8oJTj8P03Wec2CRPfVhI=; b=jyIHacrOWr3u5zo4owZcsrbhBIkh9E9r19fDYhJTKhKlxnZswmB5+Hyw5kZWsfViSA 3OjtE/zFl6ws6BvsAbT+v+mdJ6V9v0naaigMC7SJGzGFIPuz8aOAdKTGJUTOrgTKVLyo UTtUqVMxzs17fe1aysiExA1rcWoLyv+DYj+sCcI/+P90HkN87geO8NszEpxyfJH5YRbm wQGllyuvDPwfLUc54QprgYA25vdjz8GKp+jhxsBLLL0rAMzRRlnbczD7qHeEK3RErCdZ 0PQB5tb1u94Gl6Dv3xHN4B9Hyr4XWIWA+JpAf5azYIvKAlvSRpDQw4w+CDlE4Sk7qXAi uprQ== X-Gm-Message-State: AO0yUKX3ItCeuLYd+I2blmE+nd/tArENXF8dK1IE2VX3OWgQXMjNRIHf 7JVN5SuuA/kcqOunNEhVtuMiMD854DfMVb41 X-Google-Smtp-Source: AK7set8nkVGOHdQUcCSbC5+91mWS+znDsajg6nTQjeL4MlrYv3Bq7dB7rVQv/ujv8MVMbDf7icQpXQ== X-Received: by 2002:a17:902:e205:b0:19a:703d:c1cb with SMTP id u5-20020a170902e20500b0019a703dc1cbmr2237382plb.11.1676388964122; Tue, 14 Feb 2023 07:36:04 -0800 (PST) Received: from vultr.guest ([2001:19f0:7001:5cd8:5400:4ff:fe4e:5fe5]) by smtp.gmail.com with ESMTPSA id h19-20020a170902f7d300b0019a86c610dasm6390951plw.20.2023.02.14.07.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 07:36:03 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao , Roman Gushchin , Dennis Zhou , Tejun Heo , Christoph Lameter , Vasily Averin Subject: [PATCH v2] mm: percpu: fix incorrect size in pcpu_obj_full_size() Date: Tue, 14 Feb 2023 15:35:49 +0000 Message-Id: <20230214153549.12291-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 64D32C0025 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: raeae8iagzmzpusxib9ujgxsdpbz8bmf X-HE-Tag: 1676388965-141611 X-HE-Meta: U2FsdGVkX1+AROSdPjlUx587c872N6AoyPCs4IiJDdrzxc73UOJu7ziersXbR1CUTB1aSQFBnJmqF3pSt23xJxWy4Fv3W7nT6XmbAh9AuaQUz9oJm652c6P3elnhj75aWFDL+IObcAEpQ7HY2+0tzPLen91OIqziA1mKK0/AbJEuNiPIK0hDbmuL5VOYnYlkHAvrUwTq5zPa8J/LyGMj6qyPT0dMOVPF67rJRu/qaOy+/N9h84djMjHU5jnLcVKPKxbYb3IrgUVFlIaFJpGMtU/htPeZarRvDe6+Zmf0Pha6oCd6Pxy8LvjyxuH1FhSzyRlSB4l3aXgXZx/AbNd3qFFyi0YGwBnvFJvvbVKMMQi92OTUjtRcwx3g3AHIk95arGJwHWfOKzg9ZdXewjvqa54k+oJKqk9L3AMuCrcgIeA9aTqyR6NG4EipelzpNyohbD45PuFRQNFeRI075Ir/l/4UgMAeH67rVIS6BDwgXXrnHGJZjNC03M2LLALFEBI/gPuuAJBIeWsuiMLO1C/JKCFEK3Hk8KQOAU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bfS+IC8W9xVBdSio6bEBNcXKgaF4I3FQeqoDo77lzvbiwsKsRl/zUtTTapURePeBLjuxMWIYmGXp5aSZa8nb/VdvqB/+s53JfNqQC3IjvkaeQ2DVmxfPPR4xIpsoVXzX/H2E1gkWpN+TweY9DGwUMn02HhAGviB7HLx/0axoRjm60aK8i30dhmxUmffWzGLQtIId3Ez0pDdSTkEIyuJEXw6tc= 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: The extra space which is used to store the obj_cgroup membership is only valid when kmemcg is enabled. The kmemcg can be disabled via the kernel parameter "cgroup.memory=nokmem" at boot time. This helper is also used in non-memcg code, for example the tracepoint, so we should fix it. It was found by code review when I was implementing bpf memory usage[1]. No real issue happens in production environment. [1]. https://lwn.net/Articles/921991/ Signed-off-by: Yafang Shao Reviewed-by: Roman Gushchin Acked-by: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Vasily Averin --- mm/percpu-internal.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- v1->v2: improve the commit log and comments (Andrew) diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h index 70b1ea2..f9847c1 100644 --- a/mm/percpu-internal.h +++ b/mm/percpu-internal.h @@ -4,6 +4,7 @@ #include #include +#include /* * pcpu_block_md is the metadata block struct. @@ -118,14 +119,15 @@ static inline int pcpu_chunk_map_bits(struct pcpu_chunk *chunk) * @size: size of area to allocate in bytes * * For each accounted object there is an extra space which is used to store - * obj_cgroup membership. Charge it too. + * obj_cgroup membership if kmemcg is not disabled. Charge it too. */ static inline size_t pcpu_obj_full_size(size_t size) { size_t extra_size = 0; #ifdef CONFIG_MEMCG_KMEM - extra_size += size / PCPU_MIN_ALLOC_SIZE * sizeof(struct obj_cgroup *); + if (!mem_cgroup_kmem_disabled()) + extra_size += size / PCPU_MIN_ALLOC_SIZE * sizeof(struct obj_cgroup *); #endif return size * num_possible_cpus() + extra_size;