Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2189895pxm; Fri, 4 Mar 2022 11:02:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4GVDVJmJvj+GZnvoMZWSr8nXgeiyZG3txzYUYLv2MHJ9R+cD03chyGrBPhuC3uFn6UhYB X-Received: by 2002:a63:6cca:0:b0:37c:7cd8:e53d with SMTP id h193-20020a636cca000000b0037c7cd8e53dmr5809666pgc.600.1646420547890; Fri, 04 Mar 2022 11:02:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646420547; cv=none; d=google.com; s=arc-20160816; b=wzSHv6kupssnygmeoZfzInbtRE/QFTsTMZlB1yRPoc5H0PhTlWJrv5nUmwJJP5wfIO SQ1YBQYp3+62sJYAHDjy7/uJaEhwQb/rMZiBRaWA4UWrSNa0UHxsJsvstz+D+ecMzKYq aXtdjdvkVc4CQGA0zewSgeztDtmvZ7pt/5HXlGJcyR8rw+VY7NJA7dqwQQa+T9KTRwq3 g5W9JWo4abbVqK+J3coXhd9LcIn9F+tmSMXg1UapXG3MTAjOLt5zjDGaAS/Id/1x+G58 nWkZnTP39pKgVsSUilHN777EwPCep4E92mJNxxsXMrCgnJJc2EzMVTvvmL+rU7aVHeKG 8vAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sl+tnBHk3Om3exFNoQL1k9gm+o8msiRC3imZlWXFCFQ=; b=A4ejd+7ISA0UdiPLKJG7sVzu22B5T9LeV2KMKYuoEReUMLcHXvSnk2Ad/kvbxzKRtC aDDXh6mDHJ4RwpuFIE1haXR3ESCUkAZ4TAIjOlU+SPqmddMXuo6XHKZDmaJI6oQa0aYZ UfXOBrxdarijKSoV+9me+vpkMrnrxmI190w7W9E6g9PzBPugIRbeKyFFqIxMS1I5Eyyw /VJl2EkQRRfH1/CLnlRmmcGsDgqra/zNcF2jAnVAMJ7VknoVTR5qF/HB16y4zaYCW1k5 5zgdjJkGBO39w/UDi29YnTz+n5AqB2QaAq9gcEWVBGw9EMg6VW09urQcJ/x3YkSHv4ao +CXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RqVWgGr9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h191-20020a6383c8000000b0037d92b9aa5dsi1716654pge.751.2022.03.04.11.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 11:02:27 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RqVWgGr9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 189201D97EE; Fri, 4 Mar 2022 11:01:11 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238513AbiCDGg2 (ORCPT + 99 others); Fri, 4 Mar 2022 01:36:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238497AbiCDGgP (ORCPT ); Fri, 4 Mar 2022 01:36:15 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE3F518DAAD for ; Thu, 3 Mar 2022 22:34:47 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id g1so6862322pfv.1 for ; Thu, 03 Mar 2022 22:34:47 -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=g9Pd08BtkrnkKkvselJ0RqlOR8gfLmktibbFUn8VOdoLgtZEQk4ySts6Gc0a+26akt 3OeVnda8yVni7SG6yNFSdb4ETS/y3zxjTHDNMOqxkg5Bra6y6uSUQlvV41zQGAzLpitW 4ZILNqMrtpfvgKPXbS8Ye9OROZe5ND3zdG3kg2LyPeyDZbTQ1BPLywJp6qfTd0lhc2F2 77P00LIlaYzTildqD6gtRsLuwkRYE/ICQAdi0uFv89Bn3lfgtemfqZ81GU5BxGbqN4aL qpToaxpGXWAV8rBu9Nu2BYgWuqFlPZA7XU7wpSgbrU2seMdPA7YOldl/sTgWGSbYV3k/ k0Rg== X-Gm-Message-State: AOAM533GzZSMiPqr4W55b2stKTDqewPmmqxYe31CCFo9YG8bJGiC5uR0 ElElTJl6iXsD4CT/uhlpSr61LAtbyeeGCw== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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> --- 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; -- 2.33.1