From patchwork Fri Mar 4 06:34:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12768531 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 BF3F8C433EF for ; Fri, 4 Mar 2022 06:34:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B6118D0005; Fri, 4 Mar 2022 01:34:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 43F218D0001; Fri, 4 Mar 2022 01:34:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DF608D0005; Fri, 4 Mar 2022 01:34:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 1FE688D0001 for ; Fri, 4 Mar 2022 01:34:49 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CEBDE9B7 for ; Fri, 4 Mar 2022 06:34:48 +0000 (UTC) X-FDA: 79205740656.03.B4E36DD Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf18.hostedemail.com (Postfix) with ESMTP id 4AE021C0015 for ; Fri, 4 Mar 2022 06:34:48 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id s8so2760643pfk.12 for ; Thu, 03 Mar 2022 22:34:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sl+tnBHk3Om3exFNoQL1k9gm+o8msiRC3imZlWXFCFQ=; b=RqVWgGr9J9yOyOmhf/M7Rf5rVoQmBacywljxXUt7owe+MoiBcPp5It1tMurj0PjnXd Ouqe/V6NBZrcvo6w7ZMuEdxfbsjAkSoFES01WeJvCt6D3HdrZvRJXFnMbIvexDn/FyhD iBQzMeqSvC0nBRzJ88nbEK9TTmcnpWFpAxvynTA7kLxRKnDcYMzhsuN3zD9VWmGIrmOM vhEzX4e6v7tTBdZfWd55w0xwJa+3Yup/4gmOEjWsj/dO0PJNxiG4madqTytAua4HdpvS 04mkkhHJhosVGbv66Ql6zJ2KJ/C0GcJtbwewtqAQtFtaP+l7OfjN6qUJehTr+x3SRHe9 UhgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sl+tnBHk3Om3exFNoQL1k9gm+o8msiRC3imZlWXFCFQ=; b=sWWWJrIty+bEoL2PDD52m0uuMLa+R4Dm6sudhamQvoM7Q8YaExUmsFs2lDeb3IOP2j yXPiDZ4aWnc7A6sBSWk7KrmgfgvJTGypfbGLCzteLlj3u5ioscLqzt4TX6C1XVAXo/zd TU2AikOYjC7R8+64cNXQmtDviFBnVsp6ofo9gK+oDvaYKQGWAI+K5RfgEiHenaX4v0Fr M4GfPtInPOSFgQpmEDAfhlJAlyqNdFiOpPZ2HHrQ3NqHkX327om10/iPGjRRHj+mpfyG wWUsW+2ae72TIAsFUZ3YkTxArdNVAvQSsFKrRXPMYkZeuYwlXunZ6rK5YE3/P6JsWXpg XIrA== X-Gm-Message-State: AOAM533x/eVSMsSAw8ObBr0L1rqHHwJeZhcWkPGzG2FPKfl8E45+ul2a M9OdJ5S7ryXBgO/O/wpxRMzwePyR+Yqp2g== X-Google-Smtp-Source: ABdhPJxAx/kaLkY9NudzLA8xsz3v1HTz5vDFFp5IWgY5okd3A/kN+0kX2WWhmiiBZ7RvUzsi5ADCrg== X-Received: by 2002:a63:cd02:0:b0:378:9b24:4a9 with SMTP id i2-20020a63cd02000000b003789b2404a9mr20323397pgg.327.1646375687212; Thu, 03 Mar 2022 22:34:47 -0800 (PST) Received: from ip-172-31-19-208.ap-northeast-1.compute.internal (ec2-18-181-137-102.ap-northeast-1.compute.amazonaws.com. [18.181.137.102]) by smtp.gmail.com with ESMTPSA id v10-20020a056a00148a00b004e0f420dd90sm4900007pfu.40.2022.03.03.22.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 22:34:47 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: linux-mm@kvack.org Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Marco Elver , Matthew WilCox , Roman Gushchin , linux-kernel@vger.kernel.org, 42.hyeyoo@gmail.com Subject: [PATCH v2 2/5] mm/sl[au]b: unify __ksize() Date: Fri, 4 Mar 2022 06:34:24 +0000 Message-Id: <20220304063427.372145-3-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220304063427.372145-1-42.hyeyoo@gmail.com> References: <20220304063427.372145-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4AE021C0015 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RqVWgGr9; spf=pass (imf18.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 33t3hzcyo47miyapim7jp5zp5hpjpzph X-HE-Tag: 1646375688-3059 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: Now that SLAB passes large requests to page allocator like SLUB, Unify __ksize(). Only SLOB need to implement own version of __ksize() because it stores size in object header for kmalloc objects. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Vlastimil Babka --- mm/slab.c | 30 ------------------------------ mm/slab_common.c | 27 +++++++++++++++++++++++++++ mm/slub.c | 16 ---------------- 3 files changed, 27 insertions(+), 46 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 570af6dc3478..3ddf2181d8e4 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -4216,33 +4216,3 @@ void __check_heap_object(const void *ptr, unsigned long n, usercopy_abort("SLAB object", cachep->name, to_user, offset, n); } #endif /* CONFIG_HARDENED_USERCOPY */ - -/** - * __ksize -- Uninstrumented ksize. - * @objp: pointer to the object - * - * Unlike ksize(), __ksize() is uninstrumented, and does not provide the same - * safety checks as ksize() with KASAN instrumentation enabled. - * - * Return: size of the actual memory used by @objp in bytes - */ -size_t __ksize(const void *objp) -{ - struct kmem_cache *c; - struct folio *folio; - size_t size; - - BUG_ON(!objp); - if (unlikely(objp == ZERO_SIZE_PTR)) - return 0; - - folio = virt_to_folio(objp); - if (!folio_test_slab(folio)) - return folio_size(folio); - - c = virt_to_cache(objp); - size = c ? c->object_size : 0; - - return size; -} -EXPORT_SYMBOL(__ksize); diff --git a/mm/slab_common.c b/mm/slab_common.c index 23f2ab0713b7..1d2f92e871d2 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1245,6 +1245,33 @@ void kfree_sensitive(const void *p) } EXPORT_SYMBOL(kfree_sensitive); +#ifndef CONFIG_SLOB +/** + * __ksize -- Uninstrumented ksize. + * @objp: pointer to the object + * + * Unlike ksize(), __ksize() is uninstrumented, and does not provide the same + * safety checks as ksize() with KASAN instrumentation enabled. + * + * Return: size of the actual memory used by @objp in bytes + */ +size_t __ksize(const void *object) +{ + struct folio *folio; + + if (unlikely(object == ZERO_SIZE_PTR)) + return 0; + + folio = virt_to_folio(object); + + if (unlikely(!folio_test_slab(folio))) + return folio_size(folio); + + return slab_ksize(folio_slab(folio)->slab_cache); +} +EXPORT_SYMBOL(__ksize); +#endif + /** * ksize - get the actual amount of memory allocated for a given object * @objp: Pointer to the object diff --git a/mm/slub.c b/mm/slub.c index 04fd084f4709..6f0ebadd8f30 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4507,22 +4507,6 @@ void __check_heap_object(const void *ptr, unsigned long n, } #endif /* CONFIG_HARDENED_USERCOPY */ -size_t __ksize(const void *object) -{ - struct folio *folio; - - if (unlikely(object == ZERO_SIZE_PTR)) - return 0; - - folio = virt_to_folio(object); - - if (unlikely(!folio_test_slab(folio))) - return folio_size(folio); - - return slab_ksize(folio_slab(folio)->slab_cache); -} -EXPORT_SYMBOL(__ksize); - void kfree(const void *x) { struct folio *folio;