From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00D1C606A688 for ; Wed, 2 Dec 2026 12:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=rnvK5YlD Received: by kanga.kvack.org (Postfix) id 28B4F6B05B7; Wed, 2 Dec 2026 07:10:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 263346B05EB; Wed, 2 Dec 2026 07:10:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 179B46B0644; Wed, 2 Dec 2026 07:10:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EF5206B05B7 for ; Wed, 2 Dec 2026 07:10:13 -0500 (EST) Received: from smtpin29.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8E93A1402D4 for ; Wed, 2 Dec 2026 12:10:13 +0000 (UTC) X-FDA: 85498925106.29.4A82187 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 67FCF180006 for ; Wed, 2 Dec 2026 12:10:11 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=arm.com header.s=foss header.b=rnvK5YlD; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf06.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796213411; b=8inbiTLl8b83HrEKLsiNpwlEKjUrBzoGy2XbJIlUzZmA17JS8xBhSCEiHY55T/j1N5/Wy8 jHWP5sc16AIj3dBKZpvxK1nC2NFGCyOnDz8kb4A/aLUliRb9PT1LzuwZK32/IPMXiER50D kXLTNVTL55dHuRIPaAEejQICDyuuSzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796213411; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+Z1a4uIXRplNLyL0VNXn6vBan1zhAYE4Crmb5H12vmU=; b=QHHKMeq4lkejNwCLcfIOZyvN3H4bGetnXY+HR5gCtLebzy0uRu57F5OkVblWIcNN7EbGdb W3a/1Y9ElepZsadlJ5+DJJeJalFpwJXZNE9LDMVlg9ooazn6noswq4CbI/TWUVo+icphZH VdwAH4ei19XjHul7uGmMK+vuXXlKTg4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=arm.com header.s=foss header.b=rnvK5YlD; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf06.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7B4721570; Wed, 2 Dec 2026 04:10:07 -0800 (PST) Received: from [10.164.148.53] (MacBook-Pro-3.blr.arm.com [10.164.148.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E4C483F86F; Wed, 2 Dec 2026 04:10:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796213410; bh=k1zYprFhbp6DIleOhJuNxIi6aaeTIV1qZQG4i3qZeo8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=rnvK5YlDvGhonR8V5AqSRWu3rl+zYkQoOSfKwdHd1khGv39w2vxq8CyoQmrHv1Y91 xp6md2yrMmBIBscWcpAbjFKlu0bMkKln7E80oauz1e00ZsmCPWb5FZvM/rd21bcmn7 ZsZTlRU1S+LGwMSGdjQqalsE0B9AStRc/8gfmD6s= Message-ID: <634c3d35-857c-455a-b0aa-3bc14239dff2@arm.com> Date: Wed, 2 Dec 2026 17:39:58 +0530 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 0/4] mm/vmalloc: Reduce memory usage and speed up huge vmalloc To: Wen Jiang , Andrew Morton , Uladzislau Rezki , linux-mm@kvack.org Cc: Barry Song , Ryan Roberts , Anshuman Khandual , David Hildenbrand , Catalin Marinas , Will Deacon , Leo Yan , Xueyuan Chen , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Wen Jiang References: <20261202091212.363755-1-jiangwenxiaomi@gmail.com> Content-Language: en-US From: Dev Jain In-Reply-To: <20261202091212.363755-1-jiangwenxiaomi@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 67FCF180006 X-Stat-Signature: icx91austtusxzfamzbm4tekqfxbjpyo X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1796213411-856307 X-HE-Meta: U2FsdGVkX1+k/JmetRJerwyZ8Ag9ubgpCnSMSDJVOJtk/9Akb2OyMg7fqIFPGtGwZIVCheK3D0MpFrMhS19/MFlLuCZQi9CLY8xg684C/3MJTndVdw+RAjNFLFHOeUn2jhfG69m41c1aUcS2XlrTobTkLoZhkgLfTV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9CplOvEcp4HNoUCUj+5x9UEvb4MHLxVOns8oPVB/0PX2ERH/n9cSoLLiv3kXNrS8c4NQqaUlRKgnyCikBVs8g0b4sGMX0Npr2diDVogUyEWUciho3pcWil/JJb9Cm/1E1dB1L36gcngy7ewlvJLEULdrSzDEdrOibSDyAoeDxtNE5hma5eZiskr70OpSAgRKx7S5IwfL8IqhAGSqiYWk3h9gFChxSo9e9kTHNmVUil5BNvG3a1OVDnuGf8okRfcqv22abdHUqmTUHg3KAXO1tr4O4vzsjSr0bkaPVWmlgCOKVpNVKeGyZNqascl67RMAV1AsvRYOalhd6XMnZhms6vzV6Nc8vG1EwOlSBY8gYhv+z9XIID26h7m67Kgnkmu1kX7iZvAHsRKjoyi5ctOSK4H5qY8XNFftpV Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 02/12/26 2:42 pm, Wen Jiang wrote: > From: Wen Jiang > > Huge vmalloc (VM_ALLOW_HUGE_VMAP, used by kvmalloc() and vmalloc_huge()) > has two problems: > > 1. The size is rounded up to the mapping size. On arm64 a 2.1MB > kvmalloc() backs 4MB, and an 8.1MB one backs 10MB. Besides the wasted > memory, every extra page has to be zeroed on allocation (with > init_on_alloc or __GFP_ZERO) and freed again by vfree(), so > allocation and vfree() are also slower. > > 2. If a huge page allocation fails halfway, e.g. the first 2MB block > succeeds but the second does not, everything obtained so far is > freed and the whole area is allocated again with base pages. The > time spent on the first block is wasted, and smaller block sizes > such as arm64 CONT_PTE are never tried. > > This series allocates and maps an area level by level, e.g. > PMD -> CONT_PTE -> PAGE on arm64, keeping what was already obtained, > and stops rounding the size up, so an area can mix block sizes: > > 2.1MB area on arm64 (not to scale): > > baseline, 2MB blocks available: 4MB used, 2 TLB entries > +--------------------------+--------------------------+ > | 2MB PMD | 2MB PMD, 1.9MB unused | > +--------------------------+--------------------------+ > > baseline, 2MB blocks not available: 537 TLB entries > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | | | | | | | | | | | | | | | | | | | | | | | | | | | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > 537 x 4KB PTE > > this series: 2.1MB used, 11 TLB entries > +--------------------------+------+-+-+-+-+-+-+-+-+-+ > | 2MB PMD | 64KB | | | | | | | | | | > +--------------------------+------+-+-+-+-+-+-+-+-+-+ > CONT_PTE 9 x 4KB PTE > > Patch 1 extracts the mapping into vmalloc_area_map_range(), so that > an area can be mapped in several runs. > > Patch 2 adds an internal VM_HAS_HUGE_VMAP flag. A mixed area has a > page_order of 0, so vrealloc() and is_vm_area_hugepages() use the flag > to tell whether the area has any block mappings. > > Patch 3 falls back level by level. Each level takes as many whole > blocks as fit the remainder, and since the level only goes down, every > run stays aligned for its shift. It builds on the vmalloc batched > mapping series [1]. > > Patch 4 stops rounding the size up, except for VM_REQUIRE_HUGE_VMAP. Just for your note, I had tried this, but with a different motivation: https://lore.kernel.org/all/20251112110807.69958-2-dev.jain@arm.com/ Now that you are doing this, and with some vmalloc-vfree optimizations done in the past months, we may actually revisit "vmalloc-huge by default". > > Results > ======= > > On RK3588 (Cortex-A76), pinned to one core with the performance > governor. vmalloc_huge() and vfree() are timed separately; each number > is the median of 2000 calls. > > * Memory: a 2.1MB area uses 2.1MB instead of 4MB. > * vmalloc_huge() + vfree() is up to 1.9x faster, in proportion to the > pages no longer allocated. > * With simulated fragmentation, where the second 2MB block cannot be > obtained, vmalloc_huge() + vfree() is 1.4x-1.7x faster and the area > keeps its PMD and CONT_PTE mappings. > > 1. Rounding up the size > > Memory backing the area, with the mapping in 4K pages: > > size baseline this series > 2.1MB 4MB (PMD 1024) 2.1MB (PMD 512 + CONT 16 + PTE 9) > 3MB 4MB (PMD 1024) 3MB (PMD 512 + CONT 256) > 8.1MB 10MB (PMD 2560) 8.1MB (PMD 2048 + CONT 16 + PTE 9) > > Time per call in us with init_on_alloc=1, lower is better. total is > vmalloc_huge() plus vfree(), from the same run: > > baseline this series > size alloc vfree total alloc vfree total speedup > 2.1MB 143 43 186 76 23 99 1.88x > 3MB 145 43 188 110 34 144 1.31x > 8.1MB 376 107 483 304 88 392 1.23x > 4MB 146 43 189 146 43 189 1.00x > 8MB 295 86 381 297 86 383 0.99x > > 4MB and 8MB are mapped the same way on both kernels and take the same > time, so splitting an area into several runs adds no measurable cost. > > Time of vmalloc_huge() alone in us. zeroing is init_on_alloc=1 minus > init_on_alloc=0: > > init_on_alloc=1 init_on_alloc=0 zeroing > size baseline series baseline series baseline series > 2.1MB 143 76 3.8 3.2 139 73 > 3MB 145 110 3.8 3.8 141 106 > 8.1MB 376 304 9.0 8.2 367 296 > 4MB 146 146 3.8 3.8 142 142 > 8MB 295 297 7.3 7.3 288 290 > > Without zeroing, vmalloc_huge() takes 3-9us on both kernels. Zeroing > costs about 0.14us per 4K page on both, so the alloc gain comes from > zeroing fewer pages. vfree() does not zero; it costs about 0.042us per > 4K page on both kernels, so its gain also comes from freeing fewer > pages. > > 2. Only the first 2MB block succeeds > > A test hook lets each vmalloc_huge() call get only one 2MB block: the > first order-9 allocation succeeds, and every later order-9 or larger > allocation fails without calling the page allocator. The baseline > gets the first 2MB block, frees it and allocates the whole area again > with base pages. This series keeps the block and continues with > CONT_PTE. > > Mapping of the area, in 4K pages: > > size baseline this series > 4MB PTE 1024 PMD 512 + CONT 512 > 8MB PTE 2048 PMD 512 + CONT 1536 > > Time per call in us with init_on_alloc=1, lower is better: > > baseline this series > size alloc vfree total alloc vfree total speedup > 4MB 279 52 331 150 48 198 1.67x > 8MB 468 102 570 309 97 406 1.40x > > Without the hook, the same sizes take 189us and 381us in total (table > above). The baseline fallback costs another 142us and 189us: the first > block is allocated, zeroed and thrown away, and the whole area is > allocated again from base pages. This series stays close to the > no-failure time. > > Testing on other machines and with real workloads would be very > welcome. > > lib/test_vmalloc.ko passes, and a vrealloc() shrink test shows that > only areas without block mappings free their tail pages. > > This series is based on mm-new. > > [1] https://lore.kernel.org/all/20261107134953.748622-1-jiangwenxiaomi@gmail.com/ > > Wen Jiang (4): > mm/vmalloc: extract vmalloc_area_map_range() > mm/vmalloc: add VM_HAS_HUGE_VMAP > mm/vmalloc: try smaller block sizes before base pages > mm/vmalloc: page align huge vmalloc sizes > > include/linux/vmalloc.h | 7 +- > kernel/liveupdate/kexec_handover.c | 3 +- > mm/vmalloc.c | 124 ++++++++++++++++++----------- > 3 files changed, 85 insertions(+), 49 deletions(-) >