Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp612362lqp; Thu, 21 Mar 2024 10:11:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXEtODEBwMhRKwsyvg1cVM6g5QhB5STjjnHdVx3NrXgCK11DuF66oMhqz2duGuUkSosBzibKh2LvwXlEu0VzbDXObAnwTv0ORPRLKuvmA== X-Google-Smtp-Source: AGHT+IEEX9YMDxp1PDDmJgC2FMM/24ZMj+xsDRk/zDW9M7CqHOJrhBo6yD4hf3F2i9RVkQdoqAzC X-Received: by 2002:a05:6a20:2d23:b0:1a3:6d23:30cf with SMTP id g35-20020a056a202d2300b001a36d2330cfmr128291pzl.42.1711041067672; Thu, 21 Mar 2024 10:11:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711041067; cv=pass; d=google.com; s=arc-20160816; b=G+KntMm5FBXp0Gx7uMPpO89DVedQYh6TLGnGzqybcvXKXSltcHB/fZtqOFFIYSydqI dBnyL7UjgdN3JF212/C5jo1NgtrqqtBeAxhaDLkH6ul/AWYMi+XyJnkwTyuqu4n6YdrF +3/WK6HCOb4DwFlZoGBSYpi+pJw+ZbVHiJSvHqjbjm3UN10n79Bp+pTSk/q6CDnJ2QNz og0cwM+SWPkIraMgUNyCWGD9bfttCPa5ztvqTVIRCGMRfpELBDjVmPHRuPbcW/NJcS+n p1+mHGIxmdxBVko0uTwZg3P5Blaee221pflDmfvsuBbL+E6EjU61K+7Li3ZPo0NR5yjX hQ9w== 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=TkCDMNHfK5xLLlYY223eXbm7c73NL7RFva1BQ3rh7WM=; fh=wPN3gcrLiRCcrhQo0py5izSVcT52vpt3CibtlYIx43M=; b=yXCNCKTQULyj9nHECbPZjIbqk8c8ngxovRIJpxUHLfURszBCqtSJ94aEMkiCwBH24I ciTA7VFaBuT++EYoA06MzV82o20VhLJ5HcSH1nZyI7PWXYgtUDtXiS29r2LCfZXsUw59 AsGbzzqK96Bkl+uiHOaWt495YpysRbimLDAORJRxbY2Krtl0fpOF3uZRcyj6wNzg/ets STMpWaKe2MHJqTJ6C0eA4Q4U+H1u8hlT+IqH9vCOuHcn6r6NJukurpiXYPoRUTe73ZpT GirpfOQjXEJSeMgsqmGXLiRxG2lwILjIDStYO+YEQgX19CTQ+Yiwm7m/8anozzuW0IFz pnJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FNLsC8Qe; 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-110389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110389-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k34-20020a635a62000000b005e43479dc38si139440pgm.495.2024.03.21.10.11.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:11:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FNLsC8Qe; 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-110389-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110389-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 15F4DB27FAA for ; Thu, 21 Mar 2024 16:50:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 781D6143C43; Thu, 21 Mar 2024 16:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FNLsC8Qe" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 E9897140380 for ; Thu, 21 Mar 2024 16:38:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039097; cv=none; b=E2ZBBOri9eh62YPqCXVZv2HRuNV93R7w0QYqZSQu5s55ftumWIHvkN/D1WFAeCKOQfHeq3gZxHA/fq2gNblz28HKwBWXUK7bMulNoaZVx3u9KCoJ5fqP5FWD6MWKjNjVEylbLRbI1ui6WlCkYg4ERXgyjfR/vTxVnMebGwzwb/8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039097; c=relaxed/simple; bh=+rk7yZUSWOGHDX0mrmq7q5rPH06+Gd8vsMk4q87rLEE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=r5PROW2hJDb1VN2yYZ1dZLunjtnRA+64eBDx3V0GdCuJhJETcRZc8ucHrR/+GKxYgZgK6W/Wa16qTta/wO1HP4Y6/G0v50jyzs6jXvbB+bG3qFBQqKyt9cZ6IsVYj4CSS6CshUSPKd4Eqv9NqxIueERbQV9jG5Ec+VUztRKUO3o= 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=FNLsC8Qe; arc=none smtp.client-ip=209.85.128.202 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-yw1-f202.google.com with SMTP id 00721157ae682-60cc00203faso19216817b3.2 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=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=TkCDMNHfK5xLLlYY223eXbm7c73NL7RFva1BQ3rh7WM=; b=FNLsC8Qefze4WFvDfgy8PNRrY/W+MAfFUq/pqmCvAeEWpFdUkXyoG6rG/GTVkanCio oKkpTN58YUyWCzaQDSQly3SjFhNPv7EiwGpOFUvdRsg5i/b+Q20ONZ67ZBbTmabe7E5X BbCWhyWvXozSZXWrAMSdb3NFnsoiIj7kxk56ion4m94p88OEZTqE2MxXZIbP96LfgzOe Th5l5EaPCh8FgQGtu0LW1n82Bp6tfoW538Npd8ie/Up3mWsjgKjOyAB46lrnkDAvDEyu G7CCKRtx+d5a3RjAcJ2VKIxAAO+TpCdyQzPH7OfSuC1OUZ+gjKlwBOr9dVRVWjqafYNM 0VJQ== 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=AdPsXxZkym4xKS4fuZG4WFoTrmVC1uFVwfPIOnaIMHhNitW9Y/sBuSpXhWK7An0aIq ccQfP4nq6G3ByU87+KU8rbuk1w0E9q+4mTmLB70nhcMHdg5qtRj0fG4m4Fc3Zw3HVKQw 8TjKyPffIrSXFAQVUe+t+THk4mvSw3dAoz2uKvUL5oFwBwEzq264YT3T6CLsfyMbV6rC nZkAZj8OiHKHC1fV3xPUZ2wpwSdWUDlexMEImEtJ7piv+11nwI1/1QKirAiaP73sqVaT lxFEGt43n2KXBP9emLBAXwZc9RBzQogWvjrUdqAVFsI4qUaczBpI09Qdm3PKZXtpCXF7 vcqA== X-Forwarded-Encrypted: i=1; AJvYcCWN85WIcer7pvvmR2Jh0914e6SLjAO/Z8GAHHLbUDM+/htlCnxvwH8l7vowoCNLNGV6PLAAODarJG8nFCkRixgRJ2HYzjGfV/9T38ma X-Gm-Message-State: AOJu0Yye92Y3sK7sFJ1bhyoRxRarg/E1FdUsZ1Viz61j8YYx57IynJCq O/z+I0dSENqS3kdBONf1KNDkXior6Oqi2gypaecfWJ0bK2RLcuRYaHRKvkrLH8z3yW52LB8bJm6 h+A== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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); /* -- 2.44.0.291.gc1ea87d7ee-goog