From patchwork Thu Mar 21 16:36:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13599186 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 04099C6FD1F for ; Thu, 21 Mar 2024 16:38:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AFD46B00BD; Thu, 21 Mar 2024 12:38:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 437F16B00BE; Thu, 21 Mar 2024 12:38:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28BD46B00BF; Thu, 21 Mar 2024 12:38:16 -0400 (EDT) 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 0B75C6B00BD for ; Thu, 21 Mar 2024 12:38:16 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D84288168A for ; Thu, 21 Mar 2024 16:38:15 +0000 (UTC) X-FDA: 81921603750.01.F99D592 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf20.hostedemail.com (Postfix) with ESMTP id 0DF851C001D for ; Thu, 21 Mar 2024 16:38:13 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1YKb+UJq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3dGL8ZQYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3dGL8ZQYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711039094; 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=TkCDMNHfK5xLLlYY223eXbm7c73NL7RFva1BQ3rh7WM=; b=FZxR22JHn/U3yw4YBTheFeqOfL9lnzG3TZjTmaUDQVbV+j8+jXi0Hp8sSsWuaMKIRVebPJ OV5C8DanafsSOwPnDAUxgZYPr+QzsI6DHRNO/u4n3jDfdwD6N5CjmkigAhDotkF3v2Z+bL jqFvv9/vqucJSX9SEasY7OgmTcwK0gc= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1YKb+UJq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3dGL8ZQYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3dGL8ZQYKCGERTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711039094; a=rsa-sha256; cv=none; b=mYMPjVq7mkI62odqpg0pgCeQSkKHcMXF/L5ju+6vm48hJzwfouovUzxNoJjhrMKFcmIFxN tbE0u1LODLkVfY7igSYAujxdOXqwy2BC1XAJXeeEAd4C60SYVrr0DHlhMLPC2HQ/gdeMvb Owome7ho6ugzPh/oc79dBfHcI916DY0= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcbee93a3e1so1861543276.3 for ; Thu, 21 Mar 2024 09:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711039093; x=1711643893; 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=TkCDMNHfK5xLLlYY223eXbm7c73NL7RFva1BQ3rh7WM=; b=1YKb+UJqI1WRoUAhazFGjJj57QO2k/qJ2nUEyMnG72UEA0qK3PkHN/M1hB0YOGlMQ9 LvyuZKc1o+5mXkTtt0qkYQK/sNENsa1mWOdXUkehsshVBQFgkfFG/TUZOUiX8dWtSwGB mkGpq3cel0/JifUA+Desrl0mNlLWIcj3en6QPVL3cQazvxfQ+JilhWAshTqwYm+Zk7Jo 1A+z/d8UESlX4iqUqWGWfCe3JlKYGhHQkWjX6Sm7/inUqR4Q9pSsBHfl91ce4BtUtxJK BaxnA1WyYNWaqa0NHFwmvvjNINED5BPVeavLpqpiEdIg5EnmGjhbKfQwOZLyyuky6H4d 4dvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711039093; x=1711643893; 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=TkCDMNHfK5xLLlYY223eXbm7c73NL7RFva1BQ3rh7WM=; b=wydvTy70yNTSV5IJnq1Da78V04TeDqkBphkOacrPLp1w0A5FKb5aMn4M5TC5gr1Qe5 a5JJR4Nq85XzqS7wUewkd01KcL0RLUDGECzMd0WjRyXl62a+A3JGcS9tZotDVKK8Iwoe jVy2Q5qinHe7VBW2DmmRZLWhzME32qB4yr8olD7Oo1f3KwAISXAhz/PflvHLNBc4Hq8F WHLEVDc1xad4Xm1hMqct/cdMH3kXSQoV1D9kFHO+CoEufZdRzOFcvuyC+xT7W8gLAIjl iYH8VZ7UdcWX6FvUKeP8P+cpMKzo7tjNRko2TtmkaOQ2uR7yj1swdmcBqsWO1wICU3Q4 T17Q== X-Forwarded-Encrypted: i=1; AJvYcCXy4qwlgre6iOYQMCGSAvlBxWUFzKtQ5iqWRRx1AQg2iERv3NPGDHNsd0xDbXqPuWsBNMT/ZUgPcOtdFVAVPIOC/SA= X-Gm-Message-State: AOJu0YzsiDKxOcyFY4V6wB9eoU+u3YBFfpnICrrJ4uV8F3yIQnGDasIA 6aJhG0nwhYqHKYQzu1Upf4oQV5cyYcoNsJYmWEQdLpV2hNNd7t2vhz0xZTAYXbujFkn94Q+tN2K cFw== X-Google-Smtp-Source: AGHT+IGzAh9FXKpWdDvxkKjPGrkTEo4AMtUaoBAWJZd0ISNFCDPA2abbhqSo0+lrHGU23eGRJRqbHufH5vQ= 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:1a48:b0:dcc:8be2:7cb0 with SMTP id cy8-20020a0569021a4800b00dcc8be27cb0mr1175240ybb.0.1711039092976; Thu, 21 Mar 2024 09:38:12 -0700 (PDT) Date: Thu, 21 Mar 2024 09:36:51 -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-30-surenb@google.com> Subject: [PATCH v6 29/37] mm: percpu: enable per-cpu allocation tagging 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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0DF851C001D X-Stat-Signature: nn3ibuuimzd8oa9t63ijo6wff8md3sxg X-HE-Tag: 1711039093-951120 X-HE-Meta: U2FsdGVkX1/C4TpfXTYGAo5AORDsuIIapDaVHSkfMCA4NxpbaNPr790KTix6Dhgsjd+xDP2nN2ZsoBU3DKovM7vhPoY7StF3We9B2aMgKfLB481ZYjwbfl4vsdIJiMKyhsukjsImV2f1HAxKwPzjeJQbn7R7QsvNSyCFgA1kP02ZIFEAOOaD5AUxdy7B30JNxjlPniAm4wCtRwrkZfxb+ndwPEeYgDjQO8uj4XfMC628PF+kB/o/lZmrXSvPfn+OLpYIaCYUM9ln/fp9QIZgy5HpH5GqBfyGNb2L10FWaSC6z+DL8+WLeuaNV6742iEPRrLZdKHNlPcjbuQI7+Fx65i8/s75CxG1DNBPiDOHOqA0pFzqepK5QyL0Sx+rZD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QU+biLP+AEaI42ro0/NYMmo/zVIfU9uo2AtX7E/LqbR1ZaniCWarEkJlgH/jWvyvb7E4RA9AoJa/0/9ujmvdPegMT4kBYmBlByD7foP1+jttuDnUdq7jfL6X8nd5ktBTp1nUjCwV3ZtgyOJbSgbLQM3YT9CzQRsHyGg0k7pRb5a2n/18ueO8O8PZ7oadEn87M5ftQ0V8Bg= 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: Redefine __alloc_percpu, __alloc_percpu_gfp and __alloc_reserved_percpu to record allocations and deallocations done by these functions. Signed-off-by: Kent Overstreet Signed-off-by: Suren Baghdasaryan --- include/linux/percpu.h | 23 ++++++++++----- mm/percpu.c | 64 +++++------------------------------------- 2 files changed, 23 insertions(+), 64 deletions(-) diff --git a/include/linux/percpu.h b/include/linux/percpu.h index 62b5eb45bd89..e54921c79c9a 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -2,6 +2,7 @@ #ifndef __LINUX_PERCPU_H #define __LINUX_PERCPU_H +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include @@ -125,7 +127,6 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size, pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn); #endif -extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align) __alloc_size(1); extern bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr); extern bool is_kernel_percpu_address(unsigned long addr); @@ -133,14 +134,16 @@ extern bool is_kernel_percpu_address(unsigned long addr); extern void __init setup_per_cpu_areas(void); #endif -extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp) __alloc_size(1); -extern void __percpu *__alloc_percpu(size_t size, size_t align) __alloc_size(1); -extern void free_percpu(void __percpu *__pdata); +extern void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, + gfp_t gfp) __alloc_size(1); extern size_t pcpu_alloc_size(void __percpu *__pdata); -DEFINE_FREE(free_percpu, void __percpu *, free_percpu(_T)) - -extern phys_addr_t per_cpu_ptr_to_phys(void *addr); +#define __alloc_percpu_gfp(_size, _align, _gfp) \ + alloc_hooks(pcpu_alloc_noprof(_size, _align, false, _gfp)) +#define __alloc_percpu(_size, _align) \ + alloc_hooks(pcpu_alloc_noprof(_size, _align, false, GFP_KERNEL)) +#define __alloc_reserved_percpu(_size, _align) \ + alloc_hooks(pcpu_alloc_noprof(_size, _align, true, GFP_KERNEL)) #define alloc_percpu_gfp(type, gfp) \ (typeof(type) __percpu *)__alloc_percpu_gfp(sizeof(type), \ @@ -149,6 +152,12 @@ extern phys_addr_t per_cpu_ptr_to_phys(void *addr); (typeof(type) __percpu *)__alloc_percpu(sizeof(type), \ __alignof__(type)) +extern void free_percpu(void __percpu *__pdata); + +DEFINE_FREE(free_percpu, void __percpu *, free_percpu(_T)) + +extern phys_addr_t per_cpu_ptr_to_phys(void *addr); + extern unsigned long pcpu_nr_pages(void); #endif /* __LINUX_PERCPU_H */ diff --git a/mm/percpu.c b/mm/percpu.c index 90e9e4004ac9..dd7eeb370134 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1726,7 +1726,7 @@ static void pcpu_alloc_tag_free_hook(struct pcpu_chunk *chunk, int off, size_t s #endif /** - * pcpu_alloc - the percpu allocator + * pcpu_alloc_noprof - the percpu allocator * @size: size of area to allocate in bytes * @align: alignment of area (max PAGE_SIZE) * @reserved: allocate from the reserved chunk if available @@ -1740,7 +1740,7 @@ static void pcpu_alloc_tag_free_hook(struct pcpu_chunk *chunk, int off, size_t s * RETURNS: * Percpu pointer to the allocated area on success, NULL on failure. */ -static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, +void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, gfp_t gfp) { gfp_t pcpu_gfp; @@ -1907,6 +1907,8 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, pcpu_memcg_post_alloc_hook(objcg, chunk, off, size); + pcpu_alloc_tag_alloc_hook(chunk, off, size); + return ptr; fail_unlock: @@ -1935,61 +1937,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, return NULL; } - -/** - * __alloc_percpu_gfp - allocate dynamic percpu area - * @size: size of area to allocate in bytes - * @align: alignment of area (max PAGE_SIZE) - * @gfp: allocation flags - * - * Allocate zero-filled percpu area of @size bytes aligned at @align. If - * @gfp doesn't contain %GFP_KERNEL, the allocation doesn't block and can - * be called from any context but is a lot more likely to fail. If @gfp - * has __GFP_NOWARN then no warning will be triggered on invalid or failed - * allocation requests. - * - * RETURNS: - * Percpu pointer to the allocated area on success, NULL on failure. - */ -void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp) -{ - return pcpu_alloc(size, align, false, gfp); -} -EXPORT_SYMBOL_GPL(__alloc_percpu_gfp); - -/** - * __alloc_percpu - allocate dynamic percpu area - * @size: size of area to allocate in bytes - * @align: alignment of area (max PAGE_SIZE) - * - * Equivalent to __alloc_percpu_gfp(size, align, %GFP_KERNEL). - */ -void __percpu *__alloc_percpu(size_t size, size_t align) -{ - return pcpu_alloc(size, align, false, GFP_KERNEL); -} -EXPORT_SYMBOL_GPL(__alloc_percpu); - -/** - * __alloc_reserved_percpu - allocate reserved percpu area - * @size: size of area to allocate in bytes - * @align: alignment of area (max PAGE_SIZE) - * - * Allocate zero-filled percpu area of @size bytes aligned at @align - * from reserved percpu area if arch has set it up; otherwise, - * allocation is served from the same dynamic area. Might sleep. - * Might trigger writeouts. - * - * CONTEXT: - * Does GFP_KERNEL allocation. - * - * RETURNS: - * Percpu pointer to the allocated area on success, NULL on failure. - */ -void __percpu *__alloc_reserved_percpu(size_t size, size_t align) -{ - return pcpu_alloc(size, align, true, GFP_KERNEL); -} +EXPORT_SYMBOL_GPL(pcpu_alloc_noprof); /** * pcpu_balance_free - manage the amount of free chunks @@ -2328,6 +2276,8 @@ void free_percpu(void __percpu *ptr) spin_lock_irqsave(&pcpu_lock, flags); size = pcpu_free_area(chunk, off); + pcpu_alloc_tag_free_hook(chunk, off, size); + pcpu_memcg_free_hook(chunk, off, size); /*