From patchwork Thu Mar 21 16:36:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13599184 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 E31B7C54E58 for ; Thu, 21 Mar 2024 16:38:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 266716B0085; Thu, 21 Mar 2024 12:38:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F0026B00BC; Thu, 21 Mar 2024 12:38:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0E076B00BE; Thu, 21 Mar 2024 12:38:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DB63D6B00BC for ; Thu, 21 Mar 2024 12:38:11 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AE3ECA0278 for ; Thu, 21 Mar 2024 16:38:11 +0000 (UTC) X-FDA: 81921603582.10.9318202 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf19.hostedemail.com (Postfix) with ESMTP id D117A1A000D for ; Thu, 21 Mar 2024 16:38:09 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4Ty7kFCX; spf=pass (imf19.hostedemail.com: domain of 3cGL8ZQYKCF0NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3cGL8ZQYKCF0NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711039089; a=rsa-sha256; cv=none; b=zGtqxV6IpNrzCd8S1VI1+06ryf0G7QcmGspecoWbMIfEqYRqBS0CQuTDzAzjr51EjWU2oF 4bgES7Oe4ezCQZPqALt9lq35/vGMoHAqoXMa1WmgOG53ktb4XmUeCoLptTgPxAueHCjtQd UssRCeWekLvCH4DiccN4mONACxMX6SQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4Ty7kFCX; spf=pass (imf19.hostedemail.com: domain of 3cGL8ZQYKCF0NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3cGL8ZQYKCF0NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711039089; 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=DhlVYTL0Ii8S3ZK2BTRjXFWA8z6FsoYkfvkLJwCmND0=; b=zz/CdzJ5y27Gy9jzOb09xEKWH6VYHPC6znGsiiuoC2QwBCD3yo9BXgy2k987GsJ5Yjd9Qy TOBbJUe8BKzcVAa/6KKKxeIJHz3VfDlYspOkq33B2oTQ7JXdJIOqxvdayOdBBFGfG9uqN1 eW1VUEcwa2wyU/tdRgTsYrTuZgPdSKY= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd1395fd1bfso1868871276.0 for ; Thu, 21 Mar 2024 09:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711039089; x=1711643889; 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=DhlVYTL0Ii8S3ZK2BTRjXFWA8z6FsoYkfvkLJwCmND0=; b=4Ty7kFCXS6+32k0edq6Jh3bOQnQAF2dO8+4LDphQjvw+6IYBIz3bJt4bRpMHfW2Cpj 32gY+UvX0D4UFLBTgFlRbwvM+47PeAzlHO2SGrfzPLDp4z3i1Bi7Lb3Ql6OsRr2VhER9 CROgELONXID+Uzx0XlutXH/fwKIuMuEZtZkNjGy3AjSBPiZz8fMKXU66JmDSKYTexIPl Msdhu0roGSPZeA5SuPuGrnP+oI342o0XT1JZEwmnpF13jSoNAezy2IweXy+XXKdLGo1S oD1wIvMYOhecPLWPXLly1QeQjulD1RggBFhDxkb629Frodb4rXCkBEC69Uk1Jz+aUreB gWGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711039089; x=1711643889; 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=DhlVYTL0Ii8S3ZK2BTRjXFWA8z6FsoYkfvkLJwCmND0=; b=MmL8n8+Qwqmua/M+qHrm5wu8qJEE+FHoOP0UYREsEfNYvgek4PzMnnZqJJhWiZC6Hs q1/O0OEjcIoPa8AQKr2tu7Af1SH/BHrsv+Fg9E65dNO4jkccC9YYZIrgd1Ac7wlsUtnn S6dvbzorfljDORjNcjEL9q9GdcJ0dPM7gMfdoQbiEhzgvZ8ED9pFz8T2G0gGOlEOfjeC g7Gpy/lfaG+VxKjmXm24nrSgjleBCm7jt4GSHJIsS2MxVxdp/jEODDDv87LXeTVLJmk4 J5yagwKB9j8TMX4RGQNrACK8WK1UeKsfau6eXAr8wqwkA5PjP09rInF2YapnXd7uG6OT KO2Q== X-Forwarded-Encrypted: i=1; AJvYcCV76fv94MKeKkLW41gm5GD3Jl4fG/omRkskDVHcpl5P3jrW2qPb2WHMIod27l8Hb5we+u4Jbg/C3AiuJ2lSknNcEBk= X-Gm-Message-State: AOJu0Yw8x0mfbx+EiAAW8pqXzkwCceIqvBHD971mEDExLNi51swMXfZ9 oZKJy2bOSOf47J6sIVWTkpQwIHiE24Vh4lxGJGf1oeZ1A5xC7ehr6Zw7GP9cl1RPeNSKcESQ6RB 3ZQ== X-Google-Smtp-Source: AGHT+IFC+oFCb8HvR8Vt3k92TqGML+O+aM2nK5Ub8xVAQ3egP3eKpX1Sre3j/wPk5Gz2RQOGjx8MvWsloBo= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:a489:6433:be5d:e639]) (user=surenb job=sendgmr) by 2002:a05:6902:2689:b0:dcb:e4a2:1ab1 with SMTP id dx9-20020a056902268900b00dcbe4a21ab1mr2382761ybb.11.1711039088572; Thu, 21 Mar 2024 09:38:08 -0700 (PDT) Date: Thu, 21 Mar 2024 09:36:49 -0700 In-Reply-To: <20240321163705.3067592-1-surenb@google.com> Mime-Version: 1.0 References: <20240321163705.3067592-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240321163705.3067592-28-surenb@google.com> Subject: [PATCH v6 27/37] 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, penguin-kernel@i-love.sakura.ne.jp, 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, jhubbard@nvidia.com, 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, songmuchun@bytedance.com, jbaron@akamai.com, aliceryhl@google.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-Server: rspam08 X-Rspamd-Queue-Id: D117A1A000D X-Stat-Signature: wancai3yiphdiw35eyi3zeyey376pird X-Rspam-User: X-HE-Tag: 1711039089-502926 X-HE-Meta: U2FsdGVkX18WMbcP6jaH3G4VHFsoOav5xc4qWJQk6eb1jTfGXu0UnBd9HsIAJd1orjNkVxS+K0OUaLCAL93SxEDBOGuVzzG5qchlz5pWkY82TPRh8v7TwzTdBxvdnhe8YZUzprdn+8QocLDSGfjA3UG1eEP3RtkuUjuWFQX1aHsLtbQ/H75rfotjJzmborYOQqNDIEan4dSAFpDTpUZq1QJ2tnZBlJe/1CZyg+nu3Vlya+1HVNXf2NvzrcEiac1i0QbkeMmtAXWiNz3LuphpxASoyGDuXJk2IBML+pxq7JWtyaYiSZYW0TmoE5oHtyr78fNwJEX2VqdVmO+/9PI9UZiuLMjZIEh3hbg6sp5uz8esE487Xe6NRyQnjFz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yE7YKEqkDtQIUbhg8GPSOB0awYbWkPVL5N4H3vTPRAMPunksXGlLIIJhxELZT78wBIIoBo2lJYZ9cP7o7dJv6gZpYpq8W2mLVLSo/Zzk7as9uHumr9g5xketI/o6Q2rXIGymzBnp8L3AELYuHF4+mrC3KM8xagdoWQlPbDdjbkrW/J5ZTbUCRQP1Td2R6MUPXJ8jg6Au7IA4obWLEVCO8PvZHFJPwNb7iqGyB+Lwpz7mL9eloFTGedSAv0lYr3GrpyjLeY8zPWZAATj6swNCjO7WYuiZCsW+f/anciWJIf3QDkC+TGCOpRyKHxoFDe/LJ15SayHJIBQrk4aOHS/Ia5ovI0fpABd1NN3JyZuxsQfmWP2ubc7aPvC2VjygvK2CPZAyo4XVRktA23lhdU5y1ojcRVBHqO6jo/1giPLXaYr7h1WLDuy/UJtCfqahqpYAX00s/Fr0yWIIzkT9lvdlQb9LnR/ZN72JO+dVL4FS+tELQC/m970cWacW+w5+z6r/juOEdreA== 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));