From patchwork Fri Feb 10 15:49:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13135962 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 DA422C05027 for ; Fri, 10 Feb 2023 15:50:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DF826B015C; Fri, 10 Feb 2023 10:50:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68ED76B015B; Fri, 10 Feb 2023 10:50:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 530776B015C; Fri, 10 Feb 2023 10:50:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 40C766B0159 for ; Fri, 10 Feb 2023 10:50:01 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0EA0E804F6 for ; Fri, 10 Feb 2023 15:50:01 +0000 (UTC) X-FDA: 80451818202.07.6748E97 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf23.hostedemail.com (Postfix) with ESMTP id 4673E140026 for ; Fri, 10 Feb 2023 15:49:59 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=aUjBQy5W; spf=pass (imf23.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676044199; 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=V/3eP0qFPMr01f2VkyCJ3cGQxdFUqxToYhxn6CaDvX8=; b=RoN3q6jG43+3DETX/S4/Z0cwN+6y9nCZrauaecUlRaXHSyMiBCT7Q74ZUIx3r8JHTJOdBp p5HHDEN4CNp/sJmbD07sMjRSfOaAM2gAZWaziN9TD4Vpu+vJm+SpeRuLYnLhU905sX8SY4 CwXpvO+V45TufGhOuknDXGkuVPZpB2I= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=aUjBQy5W; spf=pass (imf23.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676044199; a=rsa-sha256; cv=none; b=WIH+lv1ukGEudZ255PuHZbR8s0d519h5xKW1+QXHc2o4v7HDSAmxtFL1vumiEH45L01Jwu y/3TA5PQuskrwjI0kKJU5911tZyhSD+9XL82exPe2gpWZPHpH9HzyV1lVqX7YIl134WRHi /buj5lGNpBQdEBveVuMdUSjFbtFMXbY= Received: by mail-pg1-f176.google.com with SMTP id 24so3977282pgt.7 for ; Fri, 10 Feb 2023 07:49:58 -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=V/3eP0qFPMr01f2VkyCJ3cGQxdFUqxToYhxn6CaDvX8=; b=aUjBQy5WuAuehXzrf0PmfurSNp2HP8ssDKIMhtmZA2Q4gLLdIojPVGvJltlfS6meWB L5EujQ4j1DsIAXtY/M5/V6OXxbo5uIWph1bwnjua9btFr6FqWjdUBCzGPLAcyjq0uvLs SB3zCtKvEPGj9T78SvojSSo3/7LHKKXPuVDeCcSNmOImBkcs/KVlFb0CT5/kjMnmxesb H22e1cK1gtVMpRLZ18wFu+BX62G0ggLiPOd8S0thYDDiOHl4JKu+SF3MdJ0J8xrwp+R4 zwygxOj0HfKC3f//5EuQ6xAR+akOBn+Hb+37ckkK5ErMamu+q8J2uIiJr/B5dhvIoqWH sdHg== 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=V/3eP0qFPMr01f2VkyCJ3cGQxdFUqxToYhxn6CaDvX8=; b=ru4qErsV1jBkFgS0wnPbHej+EyULKp/xQUcuNwgefDyWUlFswU86dwQ0jqySGNWK3d yr4/xIfFHH6W03XQfL4GrUwaxfcNgvxLywW6mIwcQ40yb9RNDyg2zrE4Re9m1KMW/8an nNAcDemUMnPeVE/2gobSibgZZNzWDy76IejGn/Xm2wEjUOy7ojClXePYpg0ZWZIYNUW4 2Ur9LQ+ajJ8xEHa/S5rJZdRB9Itro8Kb/5izZ22QloS50v7MLUqP6i5+Pc+JcuB8o6r/ 0NooznyQ06cxKSuNbLZ/YXK/2HS+PhWGa4axLZCW3fykhzyI2k8CVqfFtXw2Ln2ReyBT zvtA== X-Gm-Message-State: AO0yUKVJUd7+8BDylJ4prTgezOcIa/I4XwBdIQV6oghGA8r+V418BbMR 1gU4TaJVi0/SH7OlxlW53CfNtBMeNdKLImt7gHc= X-Google-Smtp-Source: AK7set/YaqH9n12I0heF9pegETao5G0EOCs8BxQ2hWKWFDIB4WmT0D8uobvBXe7NOP1eGZiDbBL2hg== X-Received: by 2002:aa7:9714:0:b0:5a8:5516:22bc with SMTP id a20-20020aa79714000000b005a8551622bcmr6063417pfg.23.1676044198157; Fri, 10 Feb 2023 07:49:58 -0800 (PST) Received: from vultr.guest ([2001:19f0:7001:2f6a:5400:4ff:fe4c:e050]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b00593cad8566fsm3453901pfu.132.2023.02.10.07.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 07:49:57 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao , Dennis Zhou , Tejun Heo , Christoph Lameter , Roman Gushchin , Vasily Averin Subject: [PATCH -mm] mm: percpu: fix incorrect size in pcpu_obj_full_size() Date: Fri, 10 Feb 2023 15:49:47 +0000 Message-Id: <20230210154947.4460-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: epxjxxnw7qoro7og5istxzhzabbr5w55 X-Rspamd-Queue-Id: 4673E140026 X-HE-Tag: 1676044199-158374 X-HE-Meta: U2FsdGVkX187KpGqdRzyikbgrc98FPWtxGJ9nnzQausm+03H8e2AFuWHob0zGA/xcb0360f4MCLJkLh7LEzf71P3ZI19ABxKTlxR6xn6/E3oJc7244Hr4Z5xgAj1bWxnuKM9zA3DxiLQMb5r2RcDoOgWvLhd288hMB0MAfJachdkV24pX/RFNiXTMs4dLzlQT7FkxEyTzCEYvMSgeQO6CxK+G+YO1iB7pQ+Z0q9pvOzkSlvjDLI4BjI1OHfNi1O2gB0+LC4jABsOG5AtYXTeQKLop8yX83PTmclUUDZH5NqEnRbH11TGaXjXrf81OOHZOkM2PriIOOOEk6U7p+Vh5kVFltPH2hYZYqLk+NhZPw9I477ZDUECPYe4wK7wrn/C+0HplPAyEPBZg+kr0sanRx16LWjWlNUVyr5O1KEBTlPlWtkZDUu/R8imLisjPLIa+a0y3L217WQRbEEneuCUejHZzkIgpZ8tye7Xrn0jgtNRUM+oHdwj7BWqvvM/YYe4GBuZjzvrzudn+jOzw9e0pOGe5MZkk2wOvtsoRNhzOItW8/IugJpEROvmZ41yWZ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gLfArcgmdgxU/8CZuSArZrB6wTkBjJY0WqlBbeEoZskQbB1tMZ76oNmXxfpmuP93jZ6Y3YHa8ZHfLS9K6iffPA6lZFwpgA5gnkWWyFoRRb28TBOJoY1gf6WtVt6nTYDCQzR6mHOHLmSa5gr1YZv4VuxU1GKnZLTGCBMpqllXu8d5vTa4fCMB96YIA= 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 runtime. 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 Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Roman Gushchin Cc: Vasily Averin Reviewed-by: Roman Gushchin Acked-by: Dennis Zhou --- mm/percpu-internal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h index 70b1ea2..2a95b1f 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. @@ -125,7 +126,8 @@ 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;