From patchwork Thu Feb 2 01:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13125205 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 35CD3C05027 for ; Thu, 2 Feb 2023 01:42:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B83A36B0081; Wed, 1 Feb 2023 20:42:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B34D06B0082; Wed, 1 Feb 2023 20:42:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FCDD6B0083; Wed, 1 Feb 2023 20:42:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 90E676B0081 for ; Wed, 1 Feb 2023 20:42:35 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6D741140DB5 for ; Thu, 2 Feb 2023 01:42:35 +0000 (UTC) X-FDA: 80420652270.21.9DB21FE Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf04.hostedemail.com (Postfix) with ESMTP id 940FD4000C for ; Thu, 2 Feb 2023 01:42:33 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=eXFJpIeX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675302153; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n3aayDdIilVnW+ECMQQHHSm0J0IUJbFKBuiVmS/NUpY=; b=A2AIgUzqgKJzNxNHqGftIgD+3bccg0ps4BaAxWiRkS2KhVVkeRMKs5GJVmyg+hd8Dv5Yj6 NzkXFmIsVG20MAWJYs/m+pHKBEAgQP9ztglUq0U9HzcFrOqFk38f4Qy+0XGQupza5hgJ0u LEp8/BDfgsaceJW+HEQ/9MQUE5qmKqk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=eXFJpIeX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675302153; a=rsa-sha256; cv=none; b=bdCxvCkkzxh4Cmr6ztphqVaEr949ZH8hFuLup+2AbFH604yc3kzbhUPBabAj3nzva8iTmY neGOoSuNUnd+w8BThWJEWqdTvhZPW99WA4uhraEJTBs8IHxT8dNwwwA3LPjI91VexobPMB suJKl/O+MhuA/pU6x//mD4vJ2yOYpkA= Received: by mail-pj1-f49.google.com with SMTP id 88so505938pjo.3 for ; Wed, 01 Feb 2023 17:42:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n3aayDdIilVnW+ECMQQHHSm0J0IUJbFKBuiVmS/NUpY=; b=eXFJpIeXYVUSPivkytSVbl5Cx+bVouw4PGsZHvBMRjAggVZwRnnFxImsPUSa20NFrE iQaQCSoHR1+JgPHA480wcfU17dzZ6o6TjbyiXSVZ5mNF78+C+MWigkULQtnu04SPA1+u cg6adFij+OS202omImD6F+tFUMNBlxcb9Rp9mqPPGl+5JGMzZO6SjgnQWEHtHToUrhWn jIGii/ALcIlvUnzD0Exx3izAAq1GKvujASyQhprQEQbd8Rk8OCjePs9KmtHRSEvOtp+e jU+hziToxxaaSZYcyDEDGzDbL20GWelRB54kK2WL+32kFgH54EfHI751dKUP6YwQSVl5 nrRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n3aayDdIilVnW+ECMQQHHSm0J0IUJbFKBuiVmS/NUpY=; b=FkqpBteqA8y25uFlD++yY00r7z/WYT0rvHa0l5caB9fizuLXQw6WKJ/YafBWq1Ga8/ Uup0bn/EMVdwFn2zSiWhKxJEKml1N0lX7vrXgM4QtmYU44hTLw3p9pApsOsuIxTuORK8 f+IjFQ60tUghmfccjgJLroVg2TIxIlaAJE/xGG9ZcK5xsyIsnwu5dDsUq386h22ZIzQc XoJ+GNp/xBo7l9A5AU/B+z+Q+sgPtabiYAP7XNGzwpEXPxCKI9K41pN3cB+LqXG8oqQY x5lFrBNNKyJr6hg7FEzoMaP9fvphyLQvYGIExS0Reb6Q3xvENXxuEbUuhhj3ydAearva CyLA== X-Gm-Message-State: AO0yUKWCyHoenVZmDkA2MGetr/ttU4cMPSj6Wk3FBHIeGXC5CBc2iVpp hPp4//QAbTrzuLy8eEw3EfQ= X-Google-Smtp-Source: AK7set+dNLy+KLgiWVd1XMiLsrgHNgux7c0+iUY8ZD/JtU9eRdmRWRIuCrfznCo3Dy7IZq+ZnnpkmA== X-Received: by 2002:a05:6a21:3990:b0:bf:8840:ffd0 with SMTP id ad16-20020a056a21399000b000bf8840ffd0mr1013419pzc.29.1675302152581; Wed, 01 Feb 2023 17:42:32 -0800 (PST) Received: from vultr.guest ([2001:19f0:7001:3f48:5400:4ff:fe4a:8c8b]) by smtp.gmail.com with ESMTPSA id t191-20020a6381c8000000b004e8f7f23c4bsm6594205pgd.76.2023.02.01.17.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 17:42:32 -0800 (PST) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tj@kernel.org, dennis@kernel.org, cl@linux.com, akpm@linux-foundation.org, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, vbabka@suse.cz, urezki@gmail.com Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao Subject: [PATCH bpf-next 4/7] mm: util: introduce kvsize() Date: Thu, 2 Feb 2023 01:41:55 +0000 Message-Id: <20230202014158.19616-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202014158.19616-1-laoar.shao@gmail.com> References: <20230202014158.19616-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 940FD4000C X-Stat-Signature: jqkcmga9kput3x64rh1ad5qw1kyxo7bx X-HE-Tag: 1675302153-80308 X-HE-Meta: U2FsdGVkX1/3K1e2EAjBEi8OSmFGyEZLMWDMC37M2M1Gk9xLCFmM5R3fmgw/9asC0WzH+mO1fX7hIq5yvuUGD5H8SyzWWGoGrardWqffGfxC2VM78ie9H2APYk+iXLOxG7dSJACzDORWY3VztaeDZ3ajzwnqjGKD2hONWImdbBN5zkNF1Kzpufgm/kHMRy2j718+U2WRpbCwcNTDTvW4Q5s4KK2WcbuFCEzI/l21Zaxmq/jhH09zy3Qa7yjlVybOIuhZr2JprekhecLmwE4MkGKGQp7S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skTgWrz7ZIhM5ypIjrRehog0OgxzcDKn2smlM1dU/aAqzkuwNvspTfkCa4XxGpvTK8+lqPxUYK0vYJzFqXgfS6AJ/28dJC34acmKNcjC0YRJvBasywCBQQgdERAUB6Xq5nqqqztcnwL22UHFj28KF6mtwJClT1VOFV0rnSTrKaBR8EVsi1EJeLlXpQ= 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: Introduce a new help kvsize() to report full size of underlying allocation of a kmalloc'ed addr or vmalloc'ed addr. Signed-off-by: Yafang Shao --- include/linux/slab.h | 1 + mm/util.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/slab.h b/include/linux/slab.h index 45af703..cccb4d8 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -762,6 +762,7 @@ static inline __alloc_size(1, 2) void *kvcalloc(size_t n, size_t size, gfp_t fla extern void *kvrealloc(const void *p, size_t oldsize, size_t newsize, gfp_t flags) __realloc_size(3); +extern size_t kvsize(void *addr); extern void kvfree(const void *addr); extern void kvfree_sensitive(const void *addr, size_t len); diff --git a/mm/util.c b/mm/util.c index b56c92f..f77d0cc 100644 --- a/mm/util.c +++ b/mm/util.c @@ -610,6 +610,21 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node) EXPORT_SYMBOL(kvmalloc_node); /** + * kvsize() - Report full size of underlying allocation of adddr + * @addr: Pointer to kmalloc'ed or vmalloc'ed memory + * + * kvsize reports full size of underlying allocation of a kmalloc'ed addr + * or a vmalloc'ed addr. + */ +size_t kvsize(void *addr) +{ + if (is_vmalloc_addr(addr)) + return vsize(addr); + + return ksize(addr); +} + +/** * kvfree() - Free memory. * @addr: Pointer to allocated memory. *