From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796202776; b=1+8ye/5NuTf776SmAZnmtdU3UO4Tpa1IBBIO0nse8thE6vdVEYMFNoU/Nud0yYv+KRi6 SsSUGWmL+nU/mkS9LHReXw4DDtkxCtTTRhps96MLRxBv1TA3jHBA132ZhI73GUI0EjVb2 4LCYa4/cTdqb9bgwgzsF4WF7XwXh48PGl4r5TABlax6DIjxTinWrRK0Kl3WoPrdvEnm1Q 3ujjj5h9hcaADk4ltQQV6buLzFxzaWorwMmpyVZsBceZcx0O0ndO3yhG9Jt/i00srZBmK zBMavuh3zAFDjoc/Oyc/HB9XCiWF/zxEfVwavj3CECxvI40xCUwudqm727F3GmV+x0A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202776; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=Sv/1u0rLXnuGCp/mNtZ9uCXcYa3xj6fYgaFI1LF9jlY=; b=Vkg7++oLkP/uFHUUiN+qb7avjR1FDpgVW9wPFRKcAmIs8ZX+wdz3mSD49f6awiY51dmj 4QBsLMYZreAwZXvu1oGbXJWFYxaFu4fRNEfQ0ZnuIRUX50GPEUhLgby2HKGQf7kOBBwlW UpHPzJjI6nw/zHjDCVKhB8pTULWXvTO4VSUduCgJPxNRP/FdHxAG2nx/pU+AmDheyh5db CUHmk20wU7hnR9xlXrFNtVBZeiW7YtJ9ZAtIxhjW77z59OIcNicJZS+5Y+8irrsxCoBO7 UPcLhvt0dK+V+tDsO4s7RCeO3jYMc44apMiSjowiJKkyUviMK/igwNZ/Ec+fir84ylg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PpL3Gss3; arc=none smtp.remote-ip=209.85.215.174 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C59B606A31A for ; Wed, 2 Dec 2026 09:12:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8C59B606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PpL3Gss3 Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-cde7e8abf9cso5182126a12.0 for ; Wed, 02 Dec 2026 01:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796202775; x=1796807575; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Sv/1u0rLXnuGCp/mNtZ9uCXcYa3xj6fYgaFI1LF9jlY=; b=PpL3Gss3AL0nPuSSYLPJ3qbvyuQpe0tCQoT9IebniOrPmUKUnlSGVGOLtnITNrDyiA wp/UVZRktpiU0QdeKPwkhvjcJ5La8ya5LypFUnhD2MV5BNhsHfIGxxIPmuD+ERfJjC/C yJ3bKrvZBD1WcqFui4EGSYvo/RZC00qAKTIyXXnYkV4YNGfJVkzE4K+cSsSL7DMAEDau UBDZfDdWFnssEOCGrBycB+T8IhYI8dd/r6M2onrJKm9RQLFQ9MydTxC10Oh4tF3ZyDIO F/Io7jx5ZTgYUVBeI0i1xYfolHXh2TZ6yB1C4CWrIrvU6iO+ViWBrY+KCoiatTgUrXOI WqpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796202775; x=1796807575; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Sv/1u0rLXnuGCp/mNtZ9uCXcYa3xj6fYgaFI1LF9jlY=; b=npVypGg6LZ25qk+o/+N8km39wgZSJPA80BdHkAvapeokI1Q2QYWE7ODPtvTPB8+/lR eEN50OI+5rRlGzT35dA6WKKpvQZL1Br2iUJ6eBvT8X790hjb1VNP1h3wqcFIVuNOJSuv qLeH/z/6g7C/wpourhhdWbi5WK3hm2ivFyc+37mBZz8Ky+RJqaO6ik0HemWoxFRH6xeP y9nIz55yXBF6ZyasyjjalJQfRHCKk6y8tbiMyARzCMXl9r1uIaRBg5CtKjYVI+aktq9+ FwpQ1YI2qfoD4lcc5KrfLYSivINeGHtKeznIo4gXMivTSh1giLsXUTPrh9gGOiATvtSZ taXg== X-Forwarded-Encrypted: i=1; AL+hErEnzpQ1FBh3iwhfr/GQb+LEOZHlforvtpoOeHXNNz6BKgf+KwhXFwDkWJtZwU/AofeWU6PE+M9iV6IGXEo=@vger.kernel.org X-Gm-Message-State: APuU4Z96ATwSrRr6X8IR3LOnCkFEHEt9GODsNzOeAO6RgTgYcbgWCZlx ZtGOWOZBwiL6lWcrsvJ/woFENR2igNqhHpIzIMGakhLdmsu7AimdHV6Q X-Gm-Gg: AZFdTZfAjD98bRAsKZnpe3KIRayDFmT/2//lW6xVe+u84P3MJvNEBB9lodvMijpVexg 92D5XSS/V8lJUHs9A3Ly5334Tl4AqFs8GRNRqAigpY5AxLWk8y1HW+xqPRqZ2tnQNuEhBsR16gL FINvq/+RNW1OUxEygaPzvsywrjOMqIJ0oanM4tl+Xls/atXgFJlE/Iy3syi1JLwXQiVpq8knw5r C/VNziW3I+9YPY3ECjBqKWFjcev+PpfwtZRHfgoWutkz5AUPEl0OrAy8gYtXu4YWvA8d4UDvtoL fF6+j+0gj6G4grwuVpCfrO2i0On9ly8zkwoumDgWHTYES9LUKI6dZib8TdBkmz1FfT8rl7oOM4J q2vH88jHictoWLimgypct4Em7xqXD49SwTT6/bDadBxoN/IkztmqG1B/ECyrezHEvcqvMtwa1G2 wFV7S3an/OQ30E3HI30ORSPrmrXNGx3/StnTE7gOpdHFu0KlopjMn1X7lUfgQGCkprNqtBmaw+Z ZjagRjOEmisobzIivHcUr3IDZ9rCR+/2i2WE3ii/JYZU4ebKLh1ov5akQIISupNxa6gaKMKnG2G 5//fSgBua/vLi0mGhtCG0oOedWuj834D/I9iwAQoZRh2ulpFnfQAQKSMB5JXHsLbIljwjYs2//9 RPje6 X-Received: by 2002:a17:90b:1641:b0:3b4:fcba:8c57 with SMTP id 98e67ed59e1d1-3b4fcba964fmr23185935a91.20.1796202774703; Wed, 02 Dec 2026 01:12:54 -0800 (PST) Received: from mi-OptiPlex-7060.mioffice.cn ([43.224.245.234]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41adcafe0sm65347467a91.16.2026.12.02.01.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 01:12:54 -0800 (PST) From: Wen Jiang To: Andrew Morton , Uladzislau Rezki , linux-mm@kvack.org Cc: Barry Song , Ryan Roberts , Dev Jain , 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 Subject: [RFC PATCH 0/4] mm/vmalloc: Reduce memory usage and speed up huge vmalloc Date: Wed, 2 Dec 2026 17:12:08 +0800 Message-Id: <20261202091212.363755-1-jiangwenxiaomi@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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(-) -- 2.34.1