Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp80955lqi; Wed, 6 Mar 2024 10:33:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVK0hxVE5Txr4BkcNF5rQsMEvCHlYs6axvXtdHOSr2fGwD10FBjA+UU3Q4YkrJIzgmACLDHq2UL/2w1tVCPF0VATyOfvXySG1EV7mwOGw== X-Google-Smtp-Source: AGHT+IFixol9c/jD26xEbzNtvJisLy0wBp4HcUEwQpt4vScS6FsQIwGPxHT15oI22hX+hDcn/EE/ X-Received: by 2002:a05:6870:e813:b0:221:69b4:ad70 with SMTP id o19-20020a056870e81300b0022169b4ad70mr528548oan.8.1709750033928; Wed, 06 Mar 2024 10:33:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709750033; cv=pass; d=google.com; s=arc-20160816; b=BN0BCmxewvwCS1uAO7eMtRCke/hj53CW6fDHBJqKN0W323nb7sopKQ5Zxv92slnwSB OITZnEGs/YbDIs5HTQu8loFetkkd3Em5erVDGdCtXeIC82hDoMgJagal6t7t1LZjPkb0 rYgI8/IzGD/NOwt5Nj1OVuQLYBVdWDkNvz8Ny0Fwcwb6mEsDDnphe4JIcuA7Tr0iFSr5 6iyLmhBrQCfTA8ofwVvxNEdQ2ox56r0fjZuqdybj8XxcDby8yNSx6OmrArWBwZGglqc7 Jktq1K9kigp4PzosXLzhk4DJsXw9HltJcXqv64FTqfduQ+S7n88ESKfRjhPk7VzuAit/ 6Adg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=vneHWg8klAgpjQ629hDbHaGhEsZ8DTv1BUkMhsSVPcA=; fh=/tem+hn5UKkbUShswEaotPrP76qMH4mTXuSkj3ykjN8=; b=b4LhLSA5Ah9+z1nOktL/mSHOqpU2dgbBbBn+ZO6CQIKIefUBWnIgzTapGxsmElAtRH fgy0XfUGgIF2d/MD+/MASKBFiN9Uh8tt0utbdIHoMekbSNpJ32b4cf0In3222jBjV5Mi diU8goUq+a4sZW6fGmy33LTbPlpR9erwwFZwjVYRM6d/wDMKzXkqbdtWwVNdSWfJ+tlA eUCLa71CQcI2tnIlEW18dOYoaXU8VgIa635MaZ9jrNeCqYH4oDUoZ3uaKsZprEEMk4F+ Z2vxtsj0xi3XaMnnK3BZvgHObP6xpV2udju25iQqnsGeJ2MQGT8x7wM8ZZ073j9hkPh9 qNFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aOi5h0dQ; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r17-20020ac85c91000000b0042ee06d6933si9716242qta.547.2024.03.06.10.33.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 10:33:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aOi5h0dQ; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8C28A1C20AF7 for ; Wed, 6 Mar 2024 18:33:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96E5814EFCC; Wed, 6 Mar 2024 18:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aOi5h0dQ" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CC74140E2E for ; Wed, 6 Mar 2024 18:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749547; cv=none; b=QidqrHIm+tT3WKhcpzqr57VUZ1K2i9WjUD0MSuNi6/cjlXDTerlCMxcpIClPmbqKlYLZAWuNhFsgmABku43BMvzgBduk/O/VZNFPCgaSxWopzhwa+N15Ec9CKvuiLQXNPy3/y4K7LctnwjHtzIZrt2+bH7kWWUQxI5awNuDB5o0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749547; c=relaxed/simple; bh=0vSaengyexKBTo3wItvJwQbhER5opgTv1nIBe1TA5GM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fKvF332U0JjYsEONqRT7ZbVcrvc/oMIfvHPdrZokXqhDclj6zIzrgMu1JOaExSPBEhVpjIzEX2eo3zYTKne2gzth0Y/1fUHfdu8wPb5wd1dRSKeylWTZR/ou6T7q7T280OQjdV/+nusoOSyv3VI6Hqh+Pwii4lnFyNsf3Ury1DY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aOi5h0dQ; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcc58cddb50so12489839276.0 for ; Wed, 06 Mar 2024 10:25:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709749543; x=1710354343; darn=vger.kernel.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=vneHWg8klAgpjQ629hDbHaGhEsZ8DTv1BUkMhsSVPcA=; b=aOi5h0dQElXTTrHsTdDmcarIbd+PJ9iSb7VJolj/id0R0ownpQavbAJfJeNSaBe4mi ZqhbScFhQZ1/VlL9GIBlHsNgz+e5FXwK3iepgSVtxBOyhCXf+isgH1bemzsrAOWrR5DR lBQuwv9YRBqsQdh8Akox34P8u/a4P6f89oTPE6r7tSDptOJ04v+BFxX07BQIr5rEq4u9 Nap6M4sjp+BcHRsHq9sMKKz4dnvvCOVtu26sCl8ykq1sTLpGfJX7TvyiCtyi5SsZenW0 mSM77wQxctILGfzUQn7oj0zYJZsgCH++0f+IcpDv7DebN4yF7nWFbSQiV8kFx2hmH8VM KBig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709749543; x=1710354343; 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=vneHWg8klAgpjQ629hDbHaGhEsZ8DTv1BUkMhsSVPcA=; b=la4D1qH0bSqe407C/xRQpV9oE8E6PMZx2YfffMEqLTvuzGsp4mu06pHD93rk5XCz7b TDsXGhBzpmi+3/GR7JgkJeSEkVV3xbhKBUjpblLEGVUPMtZmeClbtSER+5VYlOU466AC uWvfI+yW5idHF/jdTgX2ulMmTqo/7kdVVSGKOVMBQ7HS3w5uqZhdmbAv1UCsUZAld31O zs391gWMR4eHOp2rR6pYWPxf864VyNt6SeBUjUMhIVBMIRYQU+xicHkvZDegwairLDNV BvXpEOb8fzlcgawddZMyRiAIK3paxuRWnZxZtjpYwnqgl1XfQNeg2gEh8ZUOhOSv3TOm VrdA== X-Forwarded-Encrypted: i=1; AJvYcCWcnd7kL34TW6a1ce9Z4SbI2Puh0sbHAzmynSHdwTivzgFl4aweyIoLEbkTgIUtlHIL8lmMQegoD74vmVbtwSNxzI9TEaR2qmei7PLu X-Gm-Message-State: AOJu0Yy761uYbw5Gbs9Ry6NclebVphB6LsI+TZNBeIWF1VU5HjjOmSQh 1cOYN1lzrvv7bpv/58LJEVnj3qo/dCKPwskhM1FZGr9yH/Ob9erN2CaBGdO+y6pJErcHGLGDbun e+w== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:85f0:e3db:db05:85e2]) (user=surenb job=sendgmr) by 2002:a05:6902:b1c:b0:dcc:e1a6:aca9 with SMTP id ch28-20020a0569020b1c00b00dcce1a6aca9mr3819417ybb.9.1709749543321; Wed, 06 Mar 2024 10:25:43 -0800 (PST) Date: Wed, 6 Mar 2024 10:24:25 -0800 In-Reply-To: <20240306182440.2003814-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240306182440.2003814-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240306182440.2003814-28-surenb@google.com> Subject: [PATCH v5 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, shakeelb@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 Content-Type: text/plain; charset="UTF-8" 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)); -- 2.44.0.278.ge034bb2e1d-goog