From patchwork Wed Jul 17 22:24:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13735866 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 EF341C3DA60 for ; Wed, 17 Jul 2024 22:25:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80F026B0083; Wed, 17 Jul 2024 18:25:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BE646B00B3; Wed, 17 Jul 2024 18:25:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 686726B00B5; Wed, 17 Jul 2024 18:25:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4997D6B0083 for ; Wed, 17 Jul 2024 18:25:22 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E66B11A0D2E for ; Wed, 17 Jul 2024 22:25:21 +0000 (UTC) X-FDA: 82350676842.29.9B4B1F8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 52FA41C001F for ; Wed, 17 Jul 2024 22:25:19 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sVb1qGaN; spf=pass (imf18.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721255088; 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:references:dkim-signature; bh=MABp/Y/czZfRvLEYFMleg1MlNZ5vIS3VTbfPHv6mg7U=; b=wZ70TND72qKW9UY4IQwOiP6xVrEN4TsdgcH1ksJMHHa23WUWrMdcwBGDleN79s25K1vgPQ ZC2OqfUK8m1PpKsdhn4g2Aa0iyomtaS4AXBnaBBHEYd5HLmpv9f7ZcoPedgqw1mku2hbME Z7b5w5j88vRLGUDlzW4rUwnBYYUQM+E= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sVb1qGaN; spf=pass (imf18.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721255088; a=rsa-sha256; cv=none; b=gVP1JNNMvkKbUoqEg76qnaLxWcnMAQW9LTQ5bMCeVRmOOdQP1X/h7tfFFxtJKTT7CQ4S7Y HQpkIGHx2TcqGyFmDwDmOogzHk2EwXcvOPH84uukRwbp6+oD7I4Xw9XNqIwJGzYUB838LI d5klE3SRajKtKg3Ru65T28Nan1dr5gk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3200461973; Wed, 17 Jul 2024 22:25:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB6C3C2BD10; Wed, 17 Jul 2024 22:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721255117; bh=OH7w4hEU9ChwjQWvmRyr95FS1DYgivolB3TlsPr5q2g=; h=From:To:Cc:Subject:Date:From; b=sVb1qGaNdjANFyXnfEpOeB+aGu0hyTo1BiSu7LkDmNq0K+fNX97TjKF13kvYElFVP IZcWC1NnBW50uLWI1Ge5ViB1d/nU3IINis5Pz3gqbzJdZtayMsMz/lHywchCfbCx0N IfX8LpbJZQNLGoz/XXxeRuYWMgcKWri/tfq7OnfpL6tg+k57GtI4JK/UCSV3wjOtzd 3cx4IiHjdcQ3B3he81CVrZOTBvYMEDU375wxcyZsEpYWj49wSPLaRovN9NwWj1MCfr tixPHXgf58WKAXnSfxdDk68DJ1UMiorFjLo1R2J30zKe8KhATBzHlxbrIr6RjYhhZc ossw8PjcbNA+A== From: Danilo Krummrich To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, urezki@gmail.com, hch@infradead.org, kees@kernel.org, ojeda@kernel.org, wedsonaf@gmail.com, mhocko@kernel.org, mpe@ellerman.id.au, chandan.babu@oracle.com, christian.koenig@amd.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org, Danilo Krummrich Subject: [PATCH 0/2] Align kvrealloc() with krealloc() Date: Thu, 18 Jul 2024 00:24:00 +0200 Message-ID: <20240717222427.2211-1-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Stat-Signature: cboqd83k7ae6mq6arbrwehrbpg9794oq X-Rspam-User: X-Rspamd-Queue-Id: 52FA41C001F X-Rspamd-Server: rspam02 X-HE-Tag: 1721255119-72786 X-HE-Meta: U2FsdGVkX18QYifgz2bmz5EXCKiN6XOQXCmlcShrSlL+iiZoaAsr28RFKcqN3iGjTX+YB4zaB4J3QvSVQhDyf62K3tM6MSsj+AkSUmV4iqtWySzj3D50a8MPjUK4fFCZSL+aAkOUMU+oWUzlWs3gR2LdelX1Yp67rBqqHR8nEq67CQ/yfEDqc1qozgX1bLqQ1tAuJZerGjsjRkg87KMt9Xo6Nl1/Swsx8FpBrehmNNDHRMvNO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NLS6khOJ4jbAJI= 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: List-Subscribe: List-Unsubscribe: Hi, Besides the obvious (and desired) difference between krealloc() and kvrealloc(), there is some inconsistency in their function signatures and behavior: - krealloc() frees the memory when the requested size is zero, whereas kvrealloc() simply returns a pointer to the existing allocation. - krealloc() behaves like kmalloc() if a NULL pointer is passed, whereas kvrealloc() does not accept a NULL pointer at all and, if passed, would fault instead. - krealloc() is self-contained, whereas kvrealloc() relies on the caller to provide the size of the previous allocation. Inconsistent behavior throughout allocation APIs is error prone, hence make kvrealloc() behave like krealloc(), which seems superior in all mentioned aspects. In order to be able to get rid of kvrealloc()'s oldsize parameter, introduce vrealloc() and make use of it in kvrealloc(). Making use of vrealloc() in kvrealloc() also provides oppertunities to grow (and shrink) allocations more efficiently. For instance, vrealloc() could be optimized to extend the existing allocation if there is enough contiguous space left in the virtual address space at the end of the existing allocation. Besides the above, those functions are required by Rust's allocator abstractons [1] (rework based on this series in [2]). With `Vec` or `KVec` respectively, potentially growing (and shrinking) data structures are rather common. The patches of this series can also be found in [3]. [1] https://lore.kernel.org/lkml/20240704170738.3621-1-dakr@redhat.com/ [2] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/mm [3] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=mm/krealloc Danilo Krummrich (2): mm: vmalloc: implement vrealloc() mm: kvmalloc: align kvrealloc() with krealloc() arch/powerpc/platforms/pseries/papr-vpd.c | 5 +- drivers/gpu/drm/drm_exec.c | 3 +- fs/xfs/xfs_log_recover.c | 2 +- include/linux/slab.h | 3 +- include/linux/vmalloc.h | 4 ++ kernel/resource.c | 3 +- lib/fortify_kunit.c | 3 +- mm/util.c | 72 ++++++++++++++++------- mm/vmalloc.c | 58 ++++++++++++++++++ 9 files changed, 118 insertions(+), 35 deletions(-) base-commit: 51835949dda3783d4639cfa74ce13a3c9829de00