From patchwork Tue Oct 24 13:46:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13434598 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 6423CC00A8F for ; Tue, 24 Oct 2023 13:48:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79E276B028A; Tue, 24 Oct 2023 09:47:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 725A46B028C; Tue, 24 Oct 2023 09:47:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5533E6B028D; Tue, 24 Oct 2023 09:47:49 -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 38AE56B028A for ; Tue, 24 Oct 2023 09:47:49 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0A238B5D8B for ; Tue, 24 Oct 2023 13:47:49 +0000 (UTC) X-FDA: 81380483058.30.D035E27 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 3A4A740009 for ; Tue, 24 Oct 2023 13:47:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TYv+xcNM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of 3Ass3ZQYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Ass3ZQYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698155267; 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=QaUscnVR3A9ivKzFSXLwhZ9WVAKd01wEmSHK760WXQ8=; b=UXFyWZul2wTchgRMqA+84eiTccbfPLHhuS7gYExcxp35Ns1m6yTW/jhPHBxNDY+88dnSvF /5z0JCnNRC8VxoHU7cifhmOAVMikeM+TmuHaHVGLkdGK5ujX6Q4XWlT9i1fkN7ckq2W1XY 7mnsdzr6+TUEQFFGXNWnC/x4h8chMWU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TYv+xcNM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of 3Ass3ZQYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Ass3ZQYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698155267; a=rsa-sha256; cv=none; b=ZOPfyuQAwbKKwcqm1SW5HdObyFH50yilsLQ3yuSCy8xAOZqDkarTGTVL64F2AzyZ6IEpGB LUf/+fcNMmhPeoHQw74+Xrlk+lsw4sqLlL1MLKCie8HpVK5s8fNMd9Ff/O4rzMYsAMR37H 39AE3WmubJb93JaDq3UH4Origrt+C9I= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5a7d261a84bso61833407b3.3 for ; Tue, 24 Oct 2023 06:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698155266; x=1698760066; 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=QaUscnVR3A9ivKzFSXLwhZ9WVAKd01wEmSHK760WXQ8=; b=TYv+xcNMN+69dRJOSeOZdX4R+RKtLBuf4pquIcta4LPBr6iahymeEp7y9NpO28zHMO 2uzow1gLnoe7QDY3S+WTzMdCh/eP/jlicJXYAKEhDWPJeCBoIMED8ift6e9rIF0X4jCI FmmyC6qkrPWvPkdg8+DPauJO8XcOz3PwtlppnvwuhVJV04MIJX4Fg44FLDfHWUXZ5g/g uHxoeuGO1D+hJWHbHmTBNS2mEg7uYD/1YFJuIYuFRpEyH+Maia3/ArGga8tLDKYv4lr3 QReDRF9hbX2iB2V/ICB9KEp8dGqsaOLeEYbUcA8IYnfQBCIxzsKXJKWOAIPjoGXJHLpy UjJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698155266; x=1698760066; 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=QaUscnVR3A9ivKzFSXLwhZ9WVAKd01wEmSHK760WXQ8=; b=JmfD9uRK1CeKyyfsIooTdOXYn7ahd3dgf9VSGlmDcX3BeUaCtiGjfPMkHvazM9Frgu v6L0lwekogPfBRui39UsbG3wpPVuddOMQIJEM4fFOXU3VQaR3MCPeBVN+36V0/+Qy6Rm O+f/0mstiSei+NDLhiUAXXpxXnuy3Gz21vCwAVoo6Kcchc1/bIna8SBU2mn3wtARvewr Mi7HbIzQj9xAFJetmDOYVhuH0bNatysBnkPjmt4r2ixr0xo8PjBbI/Dp7BEa3smxjPPQ s/lLlXZzhsRD2SNp7bsF0XNmw3tNsu/r5nl9v5RfJicNQEH/f1P6wITfs9EUlxv07Z1A 09ZA== X-Gm-Message-State: AOJu0YycWA91ck6XyOid3JzUr0ouTrR9Br+Ac0U001tOStiApTm2DHAx 8loJRfhvfo7WmKA7rG7K35wMaRzzCpA= X-Google-Smtp-Source: AGHT+IH1Lkjv7kiNBXwNvQL565BH4DAdvvh1g2aWFQE+hKVCSXY8/YuVaym3f5veoHBOTW82zGAoDjJNWeM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:45ba:3318:d7a5:336a]) (user=surenb job=sendgmr) by 2002:a05:6902:105:b0:da0:3da9:ce08 with SMTP id o5-20020a056902010500b00da03da9ce08mr35592ybh.10.1698155266214; Tue, 24 Oct 2023 06:47:46 -0700 (PDT) Date: Tue, 24 Oct 2023 06:46:26 -0700 In-Reply-To: <20231024134637.3120277-1-surenb@google.com> Mime-Version: 1.0 References: <20231024134637.3120277-1-surenb@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024134637.3120277-30-surenb@google.com> Subject: [PATCH v2 29/39] 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, ldufour@linux.ibm.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-Rspamd-Queue-Id: 3A4A740009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: p577tro81n7z75ke9s4fh5yrs3ibe1bn X-HE-Tag: 1698155267-846924 X-HE-Meta: U2FsdGVkX19/GDp/wqad6VYNqhaKFNyI4O1fBC4r1I2BzXynvoN71tl23bwfw3SYeB77BLCbA0h83wKeygwxHdFj1y3sv2pEkWf7+BCj712eYZwzTRV/6DGsjUYRHoLC6E7k0xZ0MDVsogtUsyOkk1GJgF4l8I5Yxogzs/6KAFdEXmd8Fq5F2WwMIkVAQQ6CN/tpQyTBRBeZSLtzf6TaWFjN+XqsMEZ11mct2Blc1tZvMq43dVPpHVVP+oY0lM7GSKdaZEVCDB0MQnlH7EGOaiVYgXkKTN0weWSZjFvCLlZpAbr2i4qOT0szDnq4nWUOQwaRcuQqXgsk9dkRicLIdQkK4FG960LCQC77543jTqO9Pw2xNDV2DNg7/C8fkFy/yGMUFN4+fFENoIgzIrNmvnkjEhAy5dOSE4qkhigrRjUGxuG1RlOGVbVBBs55wtp6cqt2rAM7GMjLf9hFhMkb/9YMKt1O47tig3GXuUTrqycZgjgqm9Pil07DRbc0tqquLGySHAxb99kTBq3PjrdlV1q7bn/9BAvQDxRtokCBy+66/BrfO7UAvc6YaSmIxBGPDDLWX/MvaV0yLeYSl210+ADDeV90tx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QLSHIc2F6s8+/jtSndUT4Ltrd9GczFFst9i0B/GcTaetd9GuSmGHn32wMoMeZyYU6rgRu/RvHdSHROrs9IDitBAf+008WIyU+eVJmnY8nwtIoigJDog+vuz9k4Raw7ltA6dxStKg9IePCWE/Z89QPTsqKIqkOayy0iselvYoJonj4sFt2OhhbfPIK+M2BenqAh96CnISA+cHnHCz2kTxHiBJLfiutei63VxbuDvis0d9CPZJne/7J7ao/nYcGn8ykA+l4iMff3eT251zAMchT8s= 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 a7665de8485f..5a6202acffa3 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); @@ -1648,8 +1648,8 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, if (!objcg) return; - if (likely(chunk && chunk->obj_cgroups)) { - chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg; + if (likely(chunk && chunk->obj_exts)) { + chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].cgroup = objcg; rcu_read_lock(); mod_memcg_state(obj_cgroup_memcg(objcg), MEMCG_PERCPU_B, @@ -1665,13 +1665,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));