From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89857C433ED for ; Mon, 10 May 2021 15:04:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B04046147F for ; Mon, 10 May 2021 15:04:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B04046147F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2672A6B0078; Mon, 10 May 2021 11:04:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23E246B007B; Mon, 10 May 2021 11:04:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12DB58D0001; Mon, 10 May 2021 11:04:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id EECDF6B0078 for ; Mon, 10 May 2021 11:04:29 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A84ED68AA for ; Mon, 10 May 2021 15:04:29 +0000 (UTC) X-FDA: 78125642658.03.63CEE72 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 1D8B7801939E for ; Mon, 10 May 2021 15:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=kHD9RnNrF8GpPbctye1LyjZjhZr0VffLuv5Z+yA+EYE=; b=S6W/SVlwjOAQOqfym74Xm7P+0K 2MVAfrQiUGUlNKdRu+uNPStipNk6oWOlH2G8anSXcYKSxlF5DdHFwVF+8AkzY3/Wko/PxrEnrKRRs m2rqH65eprtqqOuZKDV93qRadDtDY/zHAUXqOtPtJqi6a3a66BVC12i9hOFpXnGmp95Bq9E0cFomO iVhOTs6SRdZ2pxhYgwcFTY9zydP+PI9k2eeRePvGURGAbIa1za3NTMPlZifdTmaPrGrkkW/B4WTZM hfVLQstd7GYjLZjctmyUTe1Dd8Im/OMYv8eA6QwQozNprbwmZH+TkPVn/9Ja3vOw+0DBdJ1bO6IWD leI/0Jvg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lg7QZ-006HN5-5x; Mon, 10 May 2021 15:02:45 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , David Rientjes Subject: [PATCH 1/3] mm/util: Add kvmalloc_node_caller Date: Mon, 10 May 2021 16:02:31 +0100 Message-Id: <20210510150233.1496689-1-willy@infradead.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Server: rspam01 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="S6W/SVlw"; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Stat-Signature: s8btmfeoqsnp6k6t1u897wcmkyr3dxsq X-Rspamd-Queue-Id: 1D8B7801939E Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf08; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620659042-708571 Content-Transfer-Encoding: quoted-printable 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: Allow the caller of kvmalloc to specify who counts as the allocator of the memory instead of assuming it's the immediate caller. Also reword the kernel-doc for kvmalloc_node() to document the semantics of the function rather than its implementation. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Rientjes --- include/linux/mm.h | 4 +++- include/linux/slab.h | 2 ++ mm/util.c | 51 ++++++++++++++++++++++++-------------------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 48268d2d0282..4f9b2007efad 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -798,7 +798,9 @@ static inline int is_vmalloc_or_module_addr(const voi= d *x) } #endif =20 -extern void *kvmalloc_node(size_t size, gfp_t flags, int node); +void *kvmalloc_node_caller(size_t size, gfp_t flags, int node, + unsigned long caller); +void *kvmalloc_node(size_t size, gfp_t flags, int node); static inline void *kvmalloc(size_t size, gfp_t flags) { return kvmalloc_node(size, flags, NUMA_NO_NODE); diff --git a/include/linux/slab.h b/include/linux/slab.h index 0c97d788762c..6611b8ee55ee 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -663,6 +663,8 @@ extern void *__kmalloc_node_track_caller(size_t, gfp_= t, int, unsigned long); =20 #else /* CONFIG_NUMA */ =20 +#define __kmalloc_node_track_caller(size, flags, node, caller) \ + __kmalloc_track_caller(size, flags, caller) #define kmalloc_node_track_caller(size, flags, node) \ kmalloc_track_caller(size, flags) =20 diff --git a/mm/util.c b/mm/util.c index a8bf17f18a81..ee4422be86a2 100644 --- a/mm/util.c +++ b/mm/util.c @@ -539,26 +539,8 @@ unsigned long vm_mmap(struct file *file, unsigned lo= ng addr, } EXPORT_SYMBOL(vm_mmap); =20 -/** - * kvmalloc_node - attempt to allocate physically contiguous memory, but= upon - * failure, fall back to non-contiguous (vmalloc) allocation. - * @size: size of the request. - * @flags: gfp mask for the allocation - must be compatible (superset) w= ith GFP_KERNEL. - * @node: numa node to allocate from - * - * Uses kmalloc to get the memory but if the allocation fails then falls= back - * to the vmalloc allocator. Use kvfree for freeing the memory. - * - * Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported. - * __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmall= oc is - * preferable to the vmalloc fallback, due to visible performance drawba= cks. - * - * Please note that any use of gfp flags outside of GFP_KERNEL is carefu= l to not - * fall back to vmalloc. - * - * Return: pointer to the allocated memory of %NULL in case of failure - */ -void *kvmalloc_node(size_t size, gfp_t flags, int node) +void *kvmalloc_node_caller(size_t size, gfp_t flags, int node, + unsigned long caller) { gfp_t kmalloc_flags =3D flags; void *ret; @@ -584,7 +566,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int nod= e) kmalloc_flags |=3D __GFP_NORETRY; } =20 - ret =3D kmalloc_node(size, kmalloc_flags, node); + ret =3D __kmalloc_node_track_caller(size, kmalloc_flags, node, caller); =20 /* * It doesn't really make sense to fallback to vmalloc for sub page @@ -593,8 +575,31 @@ void *kvmalloc_node(size_t size, gfp_t flags, int no= de) if (ret || size <=3D PAGE_SIZE) return ret; =20 - return __vmalloc_node(size, 1, flags, node, - __builtin_return_address(0)); + return __vmalloc_node(size, 1, flags, node, (void *)caller); +} + +/** + * kvmalloc_node - Allocate memory from a particular NUMA node. + * @size: Number of bytes to allocate. + * @flags: Memory allocation (GFP) flags. + * @node: NUMA node to allocate from. + * + * The allocated memory may or may not be physically contiguous, and so + * is not suitable for DMA. Use kvfree() to free the memory. + * + * Reclaim modifiers - __GFP_NORETRY and __GFP_NOFAIL are not supported. + * __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmall= oc is + * preferable to the vmalloc fallback, due to visible performance drawba= cks. + * + * Any use of gfp flags outside of GFP_KERNEL is careful to not + * fall back to vmalloc. + * + * Return: pointer to the allocated memory or %NULL in case of failure. + * %ZERO_SIZE_PTR if @size is zero. + */ +void *kvmalloc_node(size_t size, gfp_t flags, int node) +{ + return kvmalloc_node_caller(size, flags, node, _RET_IP_); } EXPORT_SYMBOL(kvmalloc_node); =20 --=20 2.30.2