From patchwork Thu Jan 12 15:53:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13098270 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 098A0C67871 for ; Thu, 12 Jan 2023 15:53:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 993C38E0008; Thu, 12 Jan 2023 10:53:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91C558E0001; Thu, 12 Jan 2023 10:53:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D21B8E0008; Thu, 12 Jan 2023 10:53:44 -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 51C718E0001 for ; Thu, 12 Jan 2023 10:53:44 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 056C5AB2E0 for ; Thu, 12 Jan 2023 15:53:44 +0000 (UTC) X-FDA: 80346592368.02.5223A63 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by imf26.hostedemail.com (Postfix) with ESMTP id 56BE8140009 for ; Thu, 12 Jan 2023 15:53:42 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YodB935w; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.160.169 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673538822; 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=uihgwx1T6nkcpHBqU4nGrP1KTt8QoN0fwfvzg1wucPQ=; b=7O6eUXKdyQMR37ogxvMqikJtwNqdSqhQzM7rJO76iYcB+2CubBqb0aakwyxMeaHjAOnPnJ vm9sdFXJUpIC298mnGEJj7XzfJ/i1ZqB9GtNbBMlKP88FmybkWjfinIAKHZve4BtAWPCWO fgIRIuWyeBrF0Qq5ljjAHbiAXcrcM88= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YodB935w; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.160.169 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673538822; a=rsa-sha256; cv=none; b=7auRiocTwMjbfFwWnIzc4DuoTM+xFd1VTVXHyMATH2YT8gzrVK3BjTwDC/tsoxq6E16sSK lHSN5yuNvodOoYfYKFQU37+yv2vuaYffb0HsIO6GsGVskbv/REU6Q8EotJAtqdyNfu7cVQ +ZqYWAueMc10yvgVmppN8k1ED7joTrY= Received: by mail-qt1-f169.google.com with SMTP id s5so12327087qtx.6 for ; Thu, 12 Jan 2023 07:53:42 -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=uihgwx1T6nkcpHBqU4nGrP1KTt8QoN0fwfvzg1wucPQ=; b=YodB935w9n5znFspbhXFeVSzFSE5JsGjdXO3T7QxM4mYUliNC+TPtRxw2JuS3qxGjU I2i8BfBS5PcscctdPUhc//YULRIwAZeg1mS5UNvHjm9u/Zq0t8pH/dyxAZz5micRnLjo e9u6Pz9RSOvxKChnvdrDNq5sufGnV3XuasdTaZw30pseNUm8v1DjX0A8FUR+KM2BkclZ qGgHThyqikGWYyWV81ZlED6FUAeDFbhe+Z7dvttH3V4gRa3OZMZhslzzSITLkPBaTLoy eMSdtv+WJhmL/l2hEXvVt+Aczvbpaz13WvZDnwvZLHETZHye1E7tiOLO2wLcwF+0sVFp wgmg== 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=uihgwx1T6nkcpHBqU4nGrP1KTt8QoN0fwfvzg1wucPQ=; b=PT/nmQdo+0pBtcJVD0RX8t66oP3Rgst7QDQrz2eawgBnSGeutpyus9r4koHodCHUAs BDIuQcjYDEogb+It72WvfPCbIifovOzkL3js05NCbYU3B8UAdPq3KOk6x846jeifk710 b+eRd4heS4te67D1pm0w0HbQ8uOE9mCScKszgsqerltTHzQZmyYF8Up4yq+MOAbaYqGx 33P0IN7oO8gVgDwpxX8KCyo/FtZ9CH/dkK1eAwrHddFcLFD92jtXtGxSySGEnOukTVBR o5JJwmFZXufnxuA/WnSRsOha5hzPmQMKWa0hBHQdhxlwrUPMGv+j5rObRlEA7+NHXZfk XPHA== X-Gm-Message-State: AFqh2kotB+/xr1qs6VXH7EFJzLajmTj5op2gX5UWmqbmNspYYS1AZ4tO m2jXBOx8ntKl9jVIt2XAj9M= X-Google-Smtp-Source: AMrXdXs0Up2USZyI0o43Vk0+bBMZSWgXv+eJ2HsxBP+9FPA9u+0LO7bceUcOwMvSq9Zd58JbXWCPBg== X-Received: by 2002:a05:622a:5a98:b0:3ab:8c3f:328b with SMTP id fz24-20020a05622a5a9800b003ab8c3f328bmr94053633qtb.4.1673538821529; Thu, 12 Jan 2023 07:53:41 -0800 (PST) Received: from vultr.guest ([173.199.122.241]) by smtp.gmail.com with ESMTPSA id l17-20020ac848d1000000b003ab43dabfb1sm9280836qtr.55.2023.01.12.07.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 07:53:40 -0800 (PST) From: Yafang Shao To: 42.hyeyoo@gmail.com, vbabka@suse.cz, 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 Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next v2 06/11] mm: util: introduce kvsize() Date: Thu, 12 Jan 2023 15:53:21 +0000 Message-Id: <20230112155326.26902-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230112155326.26902-1-laoar.shao@gmail.com> References: <20230112155326.26902-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 56BE8140009 X-Stat-Signature: jigmjwzbo6yxp1yob4n1qe5bq6a1gixk X-HE-Tag: 1673538822-127676 X-HE-Meta: U2FsdGVkX18ICzsXobZg8cDp5WQ51vH/SfSZ8E74bhSTM/7LwC08TdYhYkP+E2W/cUv8qjUqh77jbdZHpfpVEmxM9+mbxjZsNIZhJnaGIYDFa8MWH4k6lEdCQ2Bb2nUmm1+XOKvSMFbTqxSitMcpMAGlmH8x3Cw7XylmbxvDXskJaOx8Hpy3prnEbCZQQ8AjSadU8TnOks8TcaiV0dEbNLOBxdCqsMM/G6uAwQyUj7lf4UGnztInbR1hKTLkxPC11wkvq35bWqV7KnKIchalDxB+aADl9VCB9HA86Qb30u97PN8G1PRZQn235Aw2tvM9O2yqPCeg5nc8B2vcd/xIS0x84kfxOYeD/hAn3tyllJWP+1pittJh548mySmepLx8HO3IErGYVl7VXshYwpiWLBMUjTKACGpgqjXq0dG4kk+w0xtVe3tQvnZ2OO/pMirqmV83g3pk0Ke21+GVdzjb6zbyEMgFItSkgYuKFnQ8xbZpwK0z1MTZo0I+WSHBvdXELoqtdoxXa++87IaNEDkF5ky/uCkTSBVLs6i25XGryafJlOf0Q/eto+tNUKFw4oXgnr/jmKTkXka4hst+Q1i6fYBQvS8YKl6YZ/8otSyVyRhtF0Imu/rJeGQFKiqKnlsjM16aS+N7ndqNoMJdV7XwSq937zRORr/sYZi8hcxYzAI8g/JqFdGzV9yJsPgV6mcpRS36+AXp0sl1LO/YEt5eh3oVIeGhDKReNzybChVoozAY6rqn8a+W9oa/8muA/1WYOyCbnXHkiiTYUY1XR1b39B+DS1wQh5r+Bnk1TV2cf+s4H5OIR67Un7YOCgIuvYhkpv8fDpwCRDN2irRVX5E8W1WThGC90V7Tc7AbcyLuoaBoo3sZDgd+rc2VibgMASk//mDYTKMX1p7a2nU24iFO7L8IuNEwK7NNrvhxUWozxFA4woBkhZV1I5PbvoNB00jOAtBDm1uL1+ZC8wh2Brl hlUpXrE3 s7s3BbjL1BSDJVXBCcFhAIlwqDFTQX8en3ylaBA1VxB3Sq3YniXDEK746S2MuKqSL//YuK4nDrze/AX0Xgf2puIEz/Y1a3CJgOUxuI3SNTM4f/5GlcE78A0+4DimdFutviQQwsmYuwbrjEPqatBAvQz8V5IRH+u9P+FekTxjX0yPPccUZlz3Fw+idRheBP6BuwkgJD2i2HS3iDbe6cAN/NHo5HfsUM5IcNFMj4cuQB/ywsI8= 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 | 10 ++++++++++ mm/util.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/slab.h b/include/linux/slab.h index 45af703..740ddf7 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -226,6 +226,15 @@ struct kmem_cache *kmem_cache_create_usercopy(const char *name, */ size_t ksize(const void *objp); +/** + * ksize_full - Report full size of each accounted objp + * @objp: pointer to the object + * + * The difference between ksize() and ksize_full() is that ksize_full() + * includes the extra space which is used to store obj_cgroup membership. + */ +size_t ksize_full(const void *objp); + #ifdef CONFIG_PRINTK bool kmem_valid_obj(void *object); void kmem_dump_obj(void *object); @@ -762,6 +771,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(const 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..d6be4f94 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(const void *addr) +{ + if (is_vmalloc_addr(addr)) + return vsize(addr); + + return ksize_full(addr); +} + +/** * kvfree() - Free memory. * @addr: Pointer to allocated memory. *