From patchwork Mon Feb 12 21:39:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13554064 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 449AAC4829D for ; Mon, 12 Feb 2024 21:40:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C826E6B00AE; Mon, 12 Feb 2024 16:40:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C08636B00AF; Mon, 12 Feb 2024 16:40:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A34B66B00B0; Mon, 12 Feb 2024 16:40:31 -0500 (EST) 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 8FE046B00AE for ; Mon, 12 Feb 2024 16:40:31 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 51839806BD for ; Mon, 12 Feb 2024 21:40:31 +0000 (UTC) X-FDA: 81784471062.21.7BDB580 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 7108F4000A for ; Mon, 12 Feb 2024 21:40:29 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SBXMwoHi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3TJDKZQYKCMs9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3TJDKZQYKCMs9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707774029; a=rsa-sha256; cv=none; b=7U1L8+1auEUzvmmtYYYyN5f/hcxqWjMzxYx06RkLvxoac0ZGYhG8JwhKFEtShjnYTAqxtJ YtqMWdQ1lyUDM7+vzB6+v2pgo21Haa5S4t/2FJpQ57dYnQT1PDK9yTzKUGvlYnqfbTbR3D H1Am2FrSP36C+4NNFfylCyC0K78TaQM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SBXMwoHi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3TJDKZQYKCMs9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3TJDKZQYKCMs9B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707774029; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ATNLg2TqDpb+ESy76iaYpc/lOC/dJ7HcAs1g5FXdHcs=; b=sd+X9WgX8r/LMKAw35QfOg8PABMiBucwCuzZRhOiQnlsjSNNgmlfNtnz2MQP/wJNXX9MNG gHp+e5ABdx9C2ksGes9FeHD8roQdJJfdALzSIb5V8P/00qZBab3usMnjb0/WJm1VyoHo85 I1dFOmeajxnB12RMhPeb7dgQhhEfm0U= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-604ab15463aso4583397b3.3 for ; Mon, 12 Feb 2024 13:40:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707774028; x=1708378828; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ATNLg2TqDpb+ESy76iaYpc/lOC/dJ7HcAs1g5FXdHcs=; b=SBXMwoHiM6OyZaUyQIjqbxBTEVw1hFMrhVB6PbUhzhZGSVPVZfGRoSqyr1P6C+pv+5 Wg6xxn4tWwkW1SaBi293xpl8wyatcqpkpNiMmKbvs0xb3jS1NxleQ0eZvuGNDgZt/UTJ ercNjQFbQqBQ7MQmr5QwXhegO8fukHTUh6luYKjmejbo8n/hKvqzfniVmUs2oUU9zuhT IZEhv/Uo0Gg3huGq6SGGVlWJXGJZsYus1dLvH4DvAxTRSr//q4/vL/gKnSlNwB4IUT6K Hl7jdKOIsXPi3SzbkcrWhNkSgPdyuBPxv4+z2pz/xQvchkTR3XOgpRsG2+/5W8fucmh3 O57A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707774028; x=1708378828; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ATNLg2TqDpb+ESy76iaYpc/lOC/dJ7HcAs1g5FXdHcs=; b=EZq6HIIMpYdLv3YlP0OOvJ/eh+HX6kQ7IUQsMNUnlkj9QsxgBCXYRtgHAdV3l02sf6 hfuN9qvtt8v6BE5ommose5+9rHvKyjC6937a6Wm4mZ79DmYDl33qqfJpgGIJF/WzPDQ9 e4VMEop1EPgiyWs1+1Tn5g4g8bZUtszwQubucnsWUgpyjIqLyWdf0/AV8yU3c8beYc3H Flae9MwEMbIEzZ8Mr8shhYGVf+jRFHuKfNfk/scuFFVru5S8k0sKyWDFaJdkUbDa8dRK eGV/LBqkeJjdndCHaQF+6OlhddbhZ1R7p+y6x8QkGz6E5cGUQFEGYpLE3DfWOD4CPWll eudQ== X-Forwarded-Encrypted: i=1; AJvYcCVLOf+ASLuNO0PFr1q3m9eVswOSyQ9PEAAuxWbnp73R0t1qtCJ/t/tsYZC9Obq8B/CauTvIfA9SwJj4BaQI1SFfnMM= X-Gm-Message-State: AOJu0YxysEIjllO0P8AvX+hs5Pdw1kCnVXcp90Elf0TZFmqYAWe06Hmt U3acYDREatpS8Efq2uQFtYxR4YZ4Cs8rBw76Jkh1+XIl8yBhURblqSRsHN8rPNYedpoENmXmVMp Kyw== X-Google-Smtp-Source: AGHT+IFdaJ2ru42StbL1ZKAAjOQXI8b0LHOU1d1orFo3FRUTifWVI/lwUfEuIqH9ZjQMhzI7lKgTZH7BiIY= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b848:2b3f:be49:9cbc]) (user=surenb job=sendgmr) by 2002:a05:690c:884:b0:604:d53e:4616 with SMTP id cd4-20020a05690c088400b00604d53e4616mr1398151ywb.6.1707774028573; Mon, 12 Feb 2024 13:40:28 -0800 (PST) Date: Mon, 12 Feb 2024 13:39:12 -0800 In-Reply-To: <20240212213922.783301-1-surenb@google.com> Mime-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240212213922.783301-27-surenb@google.com> Subject: [PATCH v3 26/35] mm: percpu: Introduce pcpuobj_ext From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7108F4000A X-Stat-Signature: sakspewmotwst8qs9xomae8p6xht8jh5 X-HE-Tag: 1707774029-912802 X-HE-Meta: U2FsdGVkX19hy7/AXdsp6Lijp731aEsUdBAuRUiqgY+NKq8JRn2+/f7o1ZUNxOel7dGemEbLqsGMt7XkUm6IolhMjy9taOecyhCG28+mSu6EIzikPR9jHaqZmmrYWPWLAAW6F8H9KvIsSe/SLep9t69WxHA7WVvcw0Oa4W0FQmiuI7+en0GE3GTm33F9sBTs3sXqdYJ4QBvbWqL6OBDIsokG1L+ggkvnV1I3pdi08ok9TDs5xD9g5dn/eHWwbqwNzCLOQfk9fm6TSGaKwJP0asAQLlpNo3ovMDG8fMEPk3stNx4IMKG4kWtsTAXWjc2bhYL/KFMijYBaFs/vP4wP2d/hTBxPndhfefByBAT9+NV0Qyr1TXzKH7388Ox+EwAwiRMxf3hSSx0qygNkDSCEhcaGeO4ZJ9C77odG0+OhVilXyrs7qE6o530hxScYh9UQMKW2wUcbBO8Br8V1qbictDQkDM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gOSuyv6fLtE6egb15jhO/Bg0VncNAM+heMgwSKWTMVriNo6c3fhOzi6r1KOood8LpZLTOITm+u18sUowIbPvpCthTTVxaZqgiLfQ6Q/pBSjN6oqrOZkbSQJIHCCdaRGOxKGEgbfAWJJCyIwF4eySCKQ0Qa65JiLgd6pOPTux/YwokvTQ8wjtisqfA9Jy2d8JeEb90xgEkYvQQEzFBMYH1wHEcVXXa455tAydn97GfPjQoEONHyvn3jeWFFLRs1PfIP5Op9YeF+vBFffxxwU26ThK+qMrHi6jVgErpER5crNrKH+DtZgOk8tybLzADzeRX0n+r7NnjPJ5e99obLc6bPbbUwoFhUFeoWfKbW9LO3AWM38mga9AlzBmaUqGc5SmY48DU9hSYhw7nG 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: From: Kent Overstreet Upcoming alloc tagging patches require a place to stash per-allocation metadata. We already do this when memcg is enabled, so this patch generalizes the obj_cgroup * vector in struct pcpu_chunk by creating a pcpu_obj_ext type, which we will be adding to in an upcoming patch - similarly to the previous slabobj_ext patch. Signed-off-by: Kent Overstreet Signed-off-by: Suren Baghdasaryan Cc: Andrew Morton Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: linux-mm@kvack.org --- mm/percpu-internal.h | 19 +++++++++++++++++-- mm/percpu.c | 30 +++++++++++++++--------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h index cdd0aa597a81..e62d582f4bf3 100644 --- a/mm/percpu-internal.h +++ b/mm/percpu-internal.h @@ -32,6 +32,16 @@ struct pcpu_block_md { int nr_bits; /* total bits responsible for */ }; +struct pcpuobj_ext { +#ifdef CONFIG_MEMCG_KMEM + struct obj_cgroup *cgroup; +#endif +}; + +#ifdef CONFIG_MEMCG_KMEM +#define NEED_PCPUOBJ_EXT +#endif + struct pcpu_chunk { #ifdef CONFIG_PERCPU_STATS int nr_alloc; /* # of allocations */ @@ -64,8 +74,8 @@ struct pcpu_chunk { int end_offset; /* additional area required to have the region end page aligned */ -#ifdef CONFIG_MEMCG_KMEM - struct obj_cgroup **obj_cgroups; /* vector of object cgroups */ +#ifdef NEED_PCPUOBJ_EXT + struct pcpuobj_ext *obj_exts; /* vector of object cgroups */ #endif int nr_pages; /* # of pages served by this chunk */ @@ -74,6 +84,11 @@ struct pcpu_chunk { unsigned long populated[]; /* populated bitmap */ }; +static inline bool need_pcpuobj_ext(void) +{ + return !mem_cgroup_kmem_disabled(); +} + extern spinlock_t pcpu_lock; extern struct list_head *pcpu_chunk_lists; diff --git a/mm/percpu.c b/mm/percpu.c index 4e11fc1e6def..2e5edaad9cc3 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1392,9 +1392,9 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr, panic("%s: Failed to allocate %zu bytes\n", __func__, alloc_size); -#ifdef CONFIG_MEMCG_KMEM +#ifdef NEED_PCPUOBJ_EXT /* first chunk is free to use */ - chunk->obj_cgroups = NULL; + chunk->obj_exts = NULL; #endif pcpu_init_md_blocks(chunk); @@ -1463,12 +1463,12 @@ static struct pcpu_chunk *pcpu_alloc_chunk(gfp_t gfp) if (!chunk->md_blocks) goto md_blocks_fail; -#ifdef CONFIG_MEMCG_KMEM - if (!mem_cgroup_kmem_disabled()) { - chunk->obj_cgroups = +#ifdef NEED_PCPUOBJ_EXT + if (need_pcpuobj_ext()) { + chunk->obj_exts = pcpu_mem_zalloc(pcpu_chunk_map_bits(chunk) * - sizeof(struct obj_cgroup *), gfp); - if (!chunk->obj_cgroups) + sizeof(struct pcpuobj_ext), gfp); + if (!chunk->obj_exts) goto objcg_fail; } #endif @@ -1480,7 +1480,7 @@ static struct pcpu_chunk *pcpu_alloc_chunk(gfp_t gfp) return chunk; -#ifdef CONFIG_MEMCG_KMEM +#ifdef NEED_PCPUOBJ_EXT objcg_fail: pcpu_mem_free(chunk->md_blocks); #endif @@ -1498,8 +1498,8 @@ static void pcpu_free_chunk(struct pcpu_chunk *chunk) { if (!chunk) return; -#ifdef CONFIG_MEMCG_KMEM - pcpu_mem_free(chunk->obj_cgroups); +#ifdef NEED_PCPUOBJ_EXT + pcpu_mem_free(chunk->obj_exts); #endif pcpu_mem_free(chunk->md_blocks); pcpu_mem_free(chunk->bound_map); @@ -1646,9 +1646,9 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, if (!objcg) return; - if (likely(chunk && chunk->obj_cgroups)) { + if (likely(chunk && chunk->obj_exts)) { obj_cgroup_get(objcg); - chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg; + chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].cgroup = objcg; rcu_read_lock(); mod_memcg_state(obj_cgroup_memcg(objcg), MEMCG_PERCPU_B, @@ -1663,13 +1663,13 @@ static void pcpu_memcg_free_hook(struct pcpu_chunk *chunk, int off, size_t size) { struct obj_cgroup *objcg; - if (unlikely(!chunk->obj_cgroups)) + if (unlikely(!chunk->obj_exts)) return; - objcg = chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT]; + objcg = chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].cgroup; if (!objcg) return; - chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = NULL; + chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].cgroup = NULL; obj_cgroup_uncharge(objcg, pcpu_obj_full_size(size));