From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f51.google.com (mail-yx1-f51.google.com [74.125.224.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF5273B0ACC for ; Fri, 17 Jul 2026 23:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784330194; cv=none; b=Wg72yZvHO2MhNLcXFW3dA0Psa3ncFU2w9ZS9rDpXSTK6EoZ3vDxs5cKsB4mlQtEWv7PQEW5TWZyjxV8VMt2rzv+1Wfx/fTRYCJGHgFudZckv1RvAxLAHBlDdXbXk8CL6yUUT7G7vNi9Bx2/y0vaIO9Rni0C6ASpD6uG05h22GWY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784330194; c=relaxed/simple; bh=IBq+gshVVi9cK9TyEuOZANWZ9met9Ll7U3lLnIHgDOg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bjh5j5nW+AlbiaddS1tOQ2C3NJ8aGEByqssIwJjYNUUwuNo0k5PMb+ksw5tRv0K2dwIajOljYG14eFu2kDhkKwTXza+Dtg+e82lVgnkbMNIEc1bGayVZkY6UMztiE3ZRnXDxhQ/F1ZmGmLPRvJ+NgyjpsUfVOYF6ROEDB5W2vZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=n4KVXrjp; arc=none smtp.client-ip=74.125.224.51 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.b="n4KVXrjp" Received: by mail-yx1-f51.google.com with SMTP id 956f58d0204a3-6611669cd16so5073670d50.0 for ; Fri, 17 Jul 2026 16:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784330189; x=1784934989; 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=Whm4jZa43igZwN7cS/CfJYk9DtbneKig663jvNEluns=; b=n4KVXrjpenP3OSPlPm5OGSmRIgnQZO6LldHRXWieKdBKE8Vzpgibe2hVNGqADL3DZP gx4+dsu6SnCjCQDHrJLCYsZCqkQhfUkhV8JeslW/9ECuaWYIslJM1xFZBaQ+vYUK5ryU ec7gr63MudKzKOqYqmXmPuNBR2on8YZEBZUPQd+rUfTRXKF+90xtV8OuAMjXV1+5rd/y HvPH/VK8Obd4myqKYG1oMTdKs3qIZ6C59Ilh0m4nXq0Tu1hlabPphTPhd+W5MpFO3zJg wiuJ2rkmns/nrWXwIcD5BwUTF1Gh6wjQUhyYwItxh7elaQAKIVyavvSaeaQeMOUcggDw +zgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784330189; x=1784934989; 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=Whm4jZa43igZwN7cS/CfJYk9DtbneKig663jvNEluns=; b=PYXg/xSIsR3PRYIRDqdmMXAQRdcdXpifAEzc5PAKxA4nRDIwaac9Snl8sYE77o9fHE fLXqYhsxTiTGAL/MolXLswXRaB8PMldHfynaAheY+wjFRJA3C7XegnsrYxHOk20ijdoT Ac6RExHf37SHaRXrSuJsda4+fOhqFpAPffCTElBhjbPBQGFEqrQS754tqb4Ge33BIXjs EUvdvNE/VsnwT0grgTrJ6uKL1TaLoX3r4jtq32ZaeJoftvWbTm0Uz1lGOIFPnlEsVrRe bQadFF1Lb+TKEuAbE/WDDCxChCO8iL8Fbv01Rh5HXn5ynCmSgfPHTWjLhGad4ZENMElJ LjeQ== X-Forwarded-Encrypted: i=1; AHgh+RrZx9iooeZDXx0vD8YlGC4gUvrLsINbcTPjOLo46o0qKOB3vyv6n47nf27yz1w2nqwTqgJSBBdY0Cvzm/g=@vger.kernel.org X-Gm-Message-State: AOJu0YyZv+ndzMqlzUszOdMygTTaH7skLmfSRCLZFAJKJRvKcuzwoQmA m2qUysbAR9GEeYzDEb6uwbiKscFFMU5Ucoi6UGkMr0VuZkkqMkcS2MWD X-Gm-Gg: AfdE7cn/7cR8JpUKkkkOGKBP8fda31Z+E5bEutC7KuEDdj4Hfcpu4EHli6mMIGnE4da I0oVZDCha0o71VYNPd/GZSVuOShHKdkglrliqiX/8lSWCVLRF2zLCL/ACc8aQxZ5ap0FstC3HG8 MwModOqGnFFW5WUpIii9j25Jtmj7wq+8e9vv6SXcArSqRYTyFgX6soKUQHQvZI5uJY7QjvzE+Cc KRpHduD3yzHns95/Rnh8LnF6vnO7CqkcINV2mk2iWCxKz/ypW0e15AEazGbNIifW7BilRwf7oVJ WZ0u71U7DfuvIFXS7uOubZT2tSUPMJj0KOtF/ioUKeQCDMpmUlEvDiUhiN6aUKqEsLfof94EuWF P5liQCzvfoWv/msWXzJyPAHitYop6lSvJX4getjpE0qGSANnXLjpLHQEBIa0II81m3/0OerhPD8 piJxgIY6fIRyRj46xx90CUlnArfL7KGQSh21t10tVjxaKVF8ewR63JcI0= X-Received: by 2002:a05:690e:154b:20b0:667:b57b:8697 with SMTP id 956f58d0204a3-6683bd2fa43mr1100245d50.61.1784330189257; Fri, 17 Jul 2026 16:16:29 -0700 (PDT) Received: from localhost.localdomain ([107.198.84.185]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6683b5645a3sm2597231d50.6.2026.07.17.16.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 16:16:28 -0700 (PDT) From: Paul Sherman To: linux-mm@kvack.org Cc: tj@kernel.org, vbabka@suse.cz, dennis@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Paul Sherman Subject: [PATCH] mm/percpu: allow embed allocator when total size fits in vmalloc Date: Fri, 17 Jul 2026 16:16:16 -0700 Message-ID: <20260717231616.9126-1-shermanpauldylan@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On large NUMA systems (e.g. 4-node 128GB), the physical span between NUMA nodes may exceed 75% of vmalloc space even though the total percpu allocation is tiny (e.g. ~6MB for 64 CPUs). The 75% check was designed for pcpu_get_vm_areas() used by dynamic percpu chunks, where vmalloc congruency is required. The embed allocator uses the linear map directly for the first chunk -- physical addresses are accessible as virtual addresses without vmalloc mapping. The relevant constraint is total percpu size, not physical span. Replace the unconditional fallback with a total-size check: if the aggregate percpu allocation fits within 75% of vmalloc space, proceed with embed regardless of physical NUMA span. Systems where total percpu size genuinely exceeds the vmalloc bound retain the page allocator fallback. Tested on Sophgo SG2042 (64-hart, 4-NUMA, 128GB DDR4, RISC-V Sv39): percpu: embed: span 0x17def7a000 > vmalloc 75% but total 0x5c0000 fits -- linear map used percpu: Embedded 23 pages/cpu s54168 r8192 d31848 u94208 Link: https://lkml.iu.edu/hypermail/linux/kernel/1707.3/00337.html Cc: Tejun Heo Cc: Vlastimil Babka Cc: Dennis Zhou Signed-off-by: Paul Sherman --- This fix is inert on systems where the original check never fired; it only activates when physical span exceeds 75% of vmalloc but total percpu size does not. Architecture analysis: Architecture | vmalloc | phys span | total percpu | result ---------------|--------------|--------------|--------------|-------- RISC-V Sv39 | ~88 GB | ~102 GB | ~6 MB | fixed RISC-V Sv48 | ~88 TB | ~102 GB | ~6 MB | unaffected RISC-V Sv57 | ~44 PB | ~102 GB | ~6 MB | unaffected ARM64 large | ~248 TB | varies | tiny | unaffected 32-bit NUMA | ~128 MB | varies | may exceed | correct fallback Tejun Heo noted in 2017 [Link] that the only constraint is vmalloc size relative to NUMA node distances, and that making vmalloc bigger would be the best fix. On RISC-V Sv39 with 88GB vmalloc and 102GB physical NUMA span that is not an option -- but the embed allocator does not need congruent vmalloc mapping for the first chunk anyway. mm/percpu.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index b0676b8054ed..72695778872c 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -3069,13 +3069,32 @@ int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size, /* warn if maximum distance is further than 75% of vmalloc space */ if (max_distance > VMALLOC_TOTAL * 3 / 4) { - pr_warn("max_distance=0x%lx too large for vmalloc space 0x%lx\n", + pr_warn("percpu: embed: max_distance=0x%lx too large for vmalloc space 0x%lx\n", max_distance, VMALLOC_TOTAL); #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK - /* and fail if we have fallback */ - rc = -EINVAL; - goto out_free_areas; -#endif + /* + * The embed allocator uses the linear map directly for the + * first chunk -- physical addresses are accessible as virtual + * addresses without vmalloc mapping. The 75% check was designed + * for pcpu_get_vm_areas() (dynamic chunks) where vmalloc + * congruency is required. On large NUMA systems, physical span + * between nodes may exceed vmalloc bounds even though total + * percpu size is tiny. Check total size, not physical span. + */ + { + unsigned long total_size = 0; + for (group = 0; group < ai->nr_groups; group++) + total_size += (unsigned long)ai->unit_size * + ai->groups[group].nr_units; + if (total_size > VMALLOC_TOTAL * 3 / 4) { + rc = -EINVAL; + goto out_free_areas; + } + pr_info("percpu: embed: span 0x%lx > vmalloc 75%%" + " but total 0x%lx fits -- linear map used\n", + max_distance, total_size); + } +#endif /* CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK */ } /* -- 2.53.0