From patchwork Wed Feb 21 19:40:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13566208 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 916D9C5478A for ; Wed, 21 Feb 2024 19:42:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93A0A6B00BC; Wed, 21 Feb 2024 14:42:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C0C86B00BD; Wed, 21 Feb 2024 14:42:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 712A76B00BE; Wed, 21 Feb 2024 14:42:01 -0500 (EST) 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 49EB26B00BC for ; Wed, 21 Feb 2024 14:42:01 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 19CC912077A for ; Wed, 21 Feb 2024 19:42:01 +0000 (UTC) X-FDA: 81816831642.26.63AFA36 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf13.hostedemail.com (Postfix) with ESMTP id 1A1F720022 for ; Wed, 21 Feb 2024 19:41:58 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dDWjvhoY; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3BlLWZQYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3BlLWZQYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708544519; 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=YEtQtrsg9A+6qi4G17OgAejNr2caNgy1uwZYQh9NpiY=; b=0mLjJxwp85ppzs+svTFgT7Wwhi7qe5qIrxdlXSGJWqMGWAel0vNEsAn0+YivncVXdU9RkX VGWxXVjlnEcSDNCJcJo2pcVzTH86mvKeHaGssgWiT4hGUlsFNyUyv6fcewr8A4zQxdhXiW WNY/WYCTIR8qJv7KVyOEPcz7lT75NoU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=dDWjvhoY; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3BlLWZQYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3BlLWZQYKCDknpmZiWbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708544519; a=rsa-sha256; cv=none; b=Mb/CzG8q98wUMUE38CTyBAbgStPArol5+CWqdyWSvp/GahfEydY7fn3WpyVthNVtbXswzK r3Q3I8EJg4uT+aRXGiz7edn2K2LK7yiyGsVu9TMfB8L22UK5p4/6wJwp0FxXGCDzRaav2u figr1fSWXtTTFmGfchBvggRbHXDIOaQ= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-608084ce3c3so17028587b3.0 for ; Wed, 21 Feb 2024 11:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708544518; x=1709149318; 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=YEtQtrsg9A+6qi4G17OgAejNr2caNgy1uwZYQh9NpiY=; b=dDWjvhoYrmcv4CexN9/PskwfX/JaO26JdSgb60bgNV3dp1GDNfJ49Xcpe6nhJ70FlK t6H+PjEIAcRqy59tPXJgexJ8yQjXjWpPJlWwrHvX80fNxGij+vyNh6rWTRTWvpTsYKUT F2+mZRPh/UxV/j5kcYp74m8VVRvO0m6CjxRzHSMiR+ZjcPWMc7ry7Nm9E4J532zvI3/A RxrDmVe+Plk7w2B2u8jvdrxgtnNojuFxYtmn2AM0T5BrvMmX5+xDv+kvBYWyhqQnbw3l jDNUMP2BSp4sDZJqUz37stD+L6g3sOOx19nocFeX6jaUS78vF6F5OkwyQQB/8EHeyoIE LoBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708544518; x=1709149318; 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=YEtQtrsg9A+6qi4G17OgAejNr2caNgy1uwZYQh9NpiY=; b=YANY1OA/N8NwtZkcYzrkkfxYH3ZTkS+vl4YQImwCSfSOUUQCsFicpH/eeLr3x0JmGj tbRwstg4XOy0Tty+bZ2yBJ3RzLTOkJkb11B+vKkqyJLDmaJ/TInHwOY/uIWFMwLLYu6K IgDoAC76U2g+mbQyaHzlBJ20tAo++GQ8Ik8PHHdVKmV34syAVPEjqlq8s1DWTyzC+Auv e4TUj2Sn3PGpJprnm1ySEL4A/xqKWh4Ftb5j9t/IewBIwEhRCLI4IRQz9lBjFEnyAdzP tix4lbDe6D5AKliR7X6lfa1UNRTF28yuA3bNVsjOiOh/UiRm/0sLk6E/vntLx4xI+Q5r E2dQ== X-Forwarded-Encrypted: i=1; AJvYcCVgnrH4RdHSUCw9YwNAPIEizgmP/yAgS2tExL66i/X7vnw4k9AteD+LvCTDMbFo9ftMvY8ubTLdnbiAhKz7xGGoay0= X-Gm-Message-State: AOJu0YxrnTsP8Pns0PT7iJSh9H8QKPgDxjXLLlu9pGLjcjb2+1koLXnB ZUIaHujVJUX16yOcylN/zs20xySPT9S1AI+DCqvE+FhU3b1oiN7Fo+6XC7t4+DKX4J6ElENUFms bRQ== X-Google-Smtp-Source: AGHT+IEnhHBEks36/xCu/yIm+JxPq4OifsOn0+nP+Rvhl9lD+QhdtqS+LgLqlaoHkRcwKrzKU7ev2mWoy/w= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:953b:9a4e:1e10:3f07]) (user=surenb job=sendgmr) by 2002:a05:690c:3388:b0:608:406d:6973 with SMTP id fl8-20020a05690c338800b00608406d6973mr2030736ywb.5.1708544518169; Wed, 21 Feb 2024 11:41:58 -0800 (PST) Date: Wed, 21 Feb 2024 11:40:41 -0800 In-Reply-To: <20240221194052.927623-1-surenb@google.com> Mime-Version: 1.0 References: <20240221194052.927623-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240221194052.927623-29-surenb@google.com> Subject: [PATCH v4 28/36] 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, 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-Server: rspam09 X-Rspamd-Queue-Id: 1A1F720022 X-Stat-Signature: bws3t338u6z51m7bwg6x5s8g43siwhtc X-Rspam-User: X-HE-Tag: 1708544518-485429 X-HE-Meta: U2FsdGVkX1/pa2BrCtFl2Zscw7L/w2TaYWTtbkzhaHGAroe5oxJz66mquGjDyPJAZDqgSJypAZhdREgxwlQrarD+Vo7eXY/0984tIjdSBXMVCbZHQ0WuChVv7FtCTbZ30aI1WMyH0VXfR4Xvtg+e+SXYSjgf5HsDdwdNdEtnd8iVGsPzXKyY2+VBwBxrkAzaquP3iFPWMlNoAdEtKUdmDBM053jhPUCjS0cnuQBmuDSBPlEAcb7+A8UptiquDiMXLvM6brZ7uG0Q2YPl+3BQEW+ayscaYhaSQDr1cnUAjBpItOH94PtHrf3ElojOVbb+xZ0jFUtnr6q/Cg6Tunx/Zw6/fuW+4NoWXtVUQ7mu4EA+211Ub9OmDg15j1MQmcXky8aeVPlj36FBY7VpnxfiDAOs6DTYHK8cRcR94vM9UMmz2S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2JfG0MRGWa72chn51SoX18Myri7O5tmxR6JXTa9tVFExV7snvjkLXNXyfkR76Gpzn2is5MbTUl8xdgkjKwtE95g7Ewq3A4Nb3yJIWVsi8tdd8bdRopKdiK34bIC0r6Iq0qTvPuWiOymjZHICGFA+1AFPJLI= 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 578531ea1f43..2badcc5e0e71 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); /*