From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 38584C44501 for ; Wed, 15 Jul 2026 18:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NSx8H0FV10BFt7xj9//KnorYKlq18iN0Y6e4bLh9hRI=; b=Z1kAkDgxsWw/SFYHsgZbxWB2dc R4fbMVqH8RURqwtEH3iyyjgEi1YMnXK1QOEyEodgoOGNEuAQT7UlHaAUoudPUCSwLETP7hKWowmiL nrozGkrFHteBucqRjPncGK9wWTyefbObnwshzIFcWWWsil3bqMl6OXIubK2vKxEMS0gLeoVFbEFlS 6cX3WAXycSELIqM8BnrV/tjk2mwEtgk/k88awv1vfZYOeMlut4tQaxi2G1evEPVD2CbP3dUFUTpJo CaNxSh3GtCMJf/SO0VDIWkAw1LzcTzC+8qxY3cv/QKt58qHlz+txhy2yutDH8GRp4XrkoJAbg+WXr d/oBCJLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wk3zr-0000000Fci1-0XJm; Wed, 15 Jul 2026 18:06:15 +0000 Received: from mail-westus2azlp170100005.outbound.protection.outlook.com ([2a01:111:f403:c005::5] helo=CO1PR03CU002.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wk3zc-0000000FcJK-421G for linux-arm-kernel@lists.infradead.org; Wed, 15 Jul 2026 18:06:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=imqjSA2O/7J8zCHW9HlNEKE1iKO56hq4DKZsJLJFHfeWtbI0tkz2kWhxQ6p6qce4ws5RKINVsqomPypT+GGrD5JDcBLGhppHuUxlLxVEb+5bixLQK35NN4gfMluPtRujg1xp4iEy631bUamGJzyQFosqAso4u+JmVXajXbpjtrgPnEtZD/pO5g749oWDQWEMQZEBYqPRT2YZCQxocbWBMq519I1G+qxd4uFz695k5+ylmg1bUKOrBNvmIJYQkd5tRk4RNVh0+ESynnfj4i4LD13QFgINi4A42W10wW4Mx/G6pkEVG0DbR97ka110N+QCgDdY80vThGVGJI00JOiZyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NSx8H0FV10BFt7xj9//KnorYKlq18iN0Y6e4bLh9hRI=; b=iIZpMNw/urwrvqF54LKqAjtEPmT38aOZF5zW4+cyftn1HdGgyQK7qh6bNP1SeCluYBl/p/hTHJ5mB9UPtcVAayU4FH5n084NhxIDO6bSig4V4zd/uaxS2wWcHXn7kgW6OFnERXlcHZYuGaNaty+iiPRGYvDskWWi8045iZNctfMH9Vr6Vy6mFmAiqnp1qwyn0Pm2+WSoRhVnQBLeGYa7NpHGqLHIGF7+LpCcOyv7H35n9htPI9a+1noXYQlc+qyjqadom86gaUH9mDSkVJ5TJD9JE0wOpIpLGGvYcanaRktM4NFOXarAmpQnZcMIE30d/LUH7NA8jRBpChR8ylzyEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NSx8H0FV10BFt7xj9//KnorYKlq18iN0Y6e4bLh9hRI=; b=YSKkkzSf3hVvz/kZlV7mDj83y6TX00EIzAQwTncxH6XIPMTCs/w3AZiMbvhLVCiexOrIhqB0A+gFJxlqUyyr1wnls4Zpb+bjzoKL7pForu98ApJ5+WyJUvP30E/Hp3ZiW1kn2wRlRZfdNkeMJbD2YS921GRpirG8UiJr9vVO/KI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from CH0PR01MB6873.prod.exchangelabs.com (2603:10b6:610:112::22) by LV2PR01MB7767.prod.exchangelabs.com (2603:10b6:408:170::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.223.10; Wed, 15 Jul 2026 18:05:47 +0000 Received: from CH0PR01MB6873.prod.exchangelabs.com ([fe80::46eb:64a3:667c:c1a0]) by CH0PR01MB6873.prod.exchangelabs.com ([fe80::46eb:64a3:667c:c1a0%3]) with mapi id 15.21.0223.008; Wed, 15 Jul 2026 18:05:47 +0000 From: Yang Shi To: cl@gentwo.org, dennis@kernel.org, tj@kernel.org, urezki@gmail.com, catalin.marinas@arm.com, will@kernel.org, ryan.roberts@arm.com, david@kernel.org, akpm@linux-foundation.org, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com Cc: yang@os.amperecomputing.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/16] mm: percpu: set up first chunk and reserve chunk Date: Wed, 15 Jul 2026 11:04:14 -0700 Message-ID: <20260715180455.515692-13-yang@os.amperecomputing.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260715180455.515692-1-yang@os.amperecomputing.com> References: <20260715180455.515692-1-yang@os.amperecomputing.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: CYZPR05CA0010.namprd05.prod.outlook.com (2603:10b6:930:89::18) To CH0PR01MB6873.prod.exchangelabs.com (2603:10b6:610:112::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR01MB6873:EE_|LV2PR01MB7767:EE_ X-MS-Office365-Filtering-Correlation-Id: 73c4d2b4-ed2b-4738-7700-08dee29bb270 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|7416014|11063799006|56012099006|10067099003|22082099003|55112099003|18002099003|6133799003|921020; X-Microsoft-Antispam-Message-Info: k2soA6jyWHcdkU4PAHPi1NePaYptG0SfUM3+iOUeRQxTukQo5I3FlrYr27o2pJfChwid8fHkcpek4VTjZDvMkdYRG9mLFeFQugDOYwGGaE4WX54TneXdvACCUx4IBfQhjxhJYynuPUabsQ/uwQg47TevjuGKNcT0TXxtl6tv4qXJxXKSE8bEEq3lRzQiKWRAQcX6m3aKVNwODKk2KUg+I1TeexvmWh//Gr1jLy9z753SHkoWYtxwXJ3bcrWYdo60VLAg2c4jkVIsmGnC1GwcOeTAS9IMUbOw2bSbRQWOIUQIMHSuZccUyjFn9Q2qeE5IEl9RFdlA/LFqkRQrxNdCnZuyHK2Pq7ddUoas7dw+PHIfcL5x4/V9Ppqm8AepPCJQq1S/lfMqBTNDRWhcT/ZzxU94gQnnwkd+TyrxS1NM4pq7/P0P1hzHJkz1izR0PTiKuFnCWDe6Uqa72NMd50vbbu97Wr+bunaJtrqLeoy8mTV1IAeq9eR/lQuUESrDtQhcqpIUucGe/xuPrTeklbOTpII1s/qn/VYTHBymHzZWi4l2KKvWfgRoIl98GxgMuYojeVL6zk2C3z9cASzELNCd7tvAe0xtUP2RqjQb+FgwOFd0tOwiifXM8Pwk/ZBLSg84yGtXTAqS8QIBScKUWUQ0O7WfWKdadVwXA+99PF6ZeP1ORlu295WZjCX1BheM4wUgHHTyR4tTNkdcruQsnIpoCg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH0PR01MB6873.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(7416014)(11063799006)(56012099006)(10067099003)(22082099003)(55112099003)(18002099003)(6133799003)(921020);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kSARMe0KKhBVY++DJJOaSzBXkIL0NRshRLRVSVLKuYlTX7qoV1Lm7FuIjErn?= =?us-ascii?Q?i/8PUM664yZ6+rBOhIHW/mi3hTT3j6P99eExZTJiRsU7+C4BPmRJOfqYrgH1?= =?us-ascii?Q?MAW2QSqqn9dIgT3QrViH0vzMphdjmMr/fNXRgBLCagwvPvHYTDhtThzORwKs?= =?us-ascii?Q?Dikh39TY0MAwZFWV4bRawWGgZ90tle4hXD/nwRe4RGkEffTf3plzFi5l0Upe?= =?us-ascii?Q?A0u0I6KqywwCI5z2be3aJh5LTW4uIrscjvu7MqYU9qppfg9fxTgjPWXYgb6U?= =?us-ascii?Q?ryjS4PIykdXIM2+T+HSIoFP/uzYUgBqFWj6M05oVgK4pGRoiC2NpcjZN2+IR?= =?us-ascii?Q?GMC23DIPzMCuRDVNmONsQvlJ/Rce6MYz7M/FdOAomIagcAOa8nzw41GouaQ6?= =?us-ascii?Q?R95zVbsJ/M3GGCd5953qZvO24PsC6Y3hNDx4zReMW6fqJigHyKumApKj9UhA?= =?us-ascii?Q?VRaonC1hs01WwMk9J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= =?us-ascii?Q?UNXvMEmpWf7n45+qC+y28v6ZZ2ReWdqfzOs8iVJQURPWjr0fiux0dEMbiJxI?= =?us-ascii?Q?lTE0BmD43iwnvQ89tglrQaQjv4KdYAqUXGcVYWrLFjQtgVfuINvC6jO4bdpF?= =?us-ascii?Q?G2eNYOeANmsgN4sLJdQseJ83Dxx/rpBuK6htksPqbgKBvASuhLProyWkvOtf?= =?us-ascii?Q?atxIuZLogIFmJWIvrOEK85T7zpIs930PFEfWXeK9Y8fx5XFnau4dD7nYLiwD?= =?us-ascii?Q?y1MUFCErha2mpl+bv1O50NbYn7Rv1fwuCjqhpVnHY5nfE/yNV7KTM6YdtT42?= =?us-ascii?Q?Ni3GOsxq6YmHXZN+N888w03J1JEH8WvN43ONR4YsfgGGS2vCEWxB0Hhbq+8R?= =?us-ascii?Q?YVbuz/XasdFEX1rbvRdCaLOpYRi1OIY=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73c4d2b4-ed2b-4738-7700-08dee29bb270 X-MS-Exchange-CrossTenant-AuthSource: CH0PR01MB6873.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2026 18:05:47.5930 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: J4utBpbZ1+OW5y3XxjqCoQL1NTX7pSYRn7jbSxiNy7UpROBMhFH4yaeOvFWue2JvisjzgbMNdi57qg56vupwd7dtlvf7FjXBqA1c5QNFG0o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR01MB7767 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260715_110601_021782_4C6A04D6 X-CRM114-Status: GOOD ( 16.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Set up the first chunk and reserve chunk with local percpu map. Signed-off-by: Yang Shi --- include/linux/percpu.h | 2 +- mm/percpu-internal.h | 2 ++ mm/percpu.c | 27 ++++++++++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/linux/percpu.h b/include/linux/percpu.h index 4f36b8585995..2f0e190aca29 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -114,7 +114,7 @@ extern struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups, extern void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai); extern void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, - void *base_addr); + void *base_addr, void *local_base); extern int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size, size_t atom_size, diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h index 6d0542fb9e49..ec2e55a2f836 100644 --- a/mm/percpu-internal.h +++ b/mm/percpu-internal.h @@ -63,6 +63,8 @@ struct pcpu_chunk { * chunk_md. */ void *base_addr ____cacheline_aligned_in_smp; + /* percpu local base address of the chunk */ + void *local_base; unsigned long *alloc_map; /* allocation map */ struct pcpu_block_md *md_blocks; /* metadata blocks */ diff --git a/mm/percpu.c b/mm/percpu.c index df2daa57309b..15303611ecaf 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1338,6 +1338,7 @@ static void pcpu_init_md_blocks(struct pcpu_chunk *chunk) /** * pcpu_alloc_first_chunk - creates chunks that serve the first chunk * @tmp_addr: the start of the region served + * @local_tmp: the start of the local percpu region served * @map_size: size of the region served * * This is responsible for creating the chunks that serve the first chunk. The @@ -1349,15 +1350,16 @@ static void pcpu_init_md_blocks(struct pcpu_chunk *chunk) * Chunk serving the region at @tmp_addr of @map_size. */ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr, - int map_size) + unsigned long local_tmp, int map_size) { struct pcpu_chunk *chunk; - unsigned long aligned_addr; + unsigned long aligned_addr, aligned_local; int start_offset, offset_bits, region_size, region_bits; size_t alloc_size; /* region calculations */ aligned_addr = tmp_addr & PAGE_MASK; + aligned_local = local_tmp & PAGE_MASK; start_offset = tmp_addr - aligned_addr; region_size = ALIGN(start_offset + map_size, PAGE_SIZE); @@ -1370,6 +1372,7 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr, INIT_LIST_HEAD(&chunk->list); chunk->base_addr = (void *)aligned_addr; + chunk->local_base = (void *)aligned_local; chunk->start_offset = start_offset; chunk->end_offset = region_size - chunk->start_offset - map_size; @@ -2562,7 +2565,7 @@ static void pcpu_dump_alloc_info(const char *lvl, * and available for dynamic allocation like any other chunk. */ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, - void *base_addr) + void *base_addr, void *local_base) { size_t size_sum = ai->static_size + ai->reserved_size + ai->dyn_size; size_t static_size, dyn_size; @@ -2572,7 +2575,7 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, unsigned int cpu; int *unit_map; int group, unit, i; - unsigned long tmp_addr; + unsigned long tmp_addr, local_tmp = 0; size_t alloc_size; #define PCPU_SETUP_BUG_ON(cond) do { \ @@ -2713,11 +2716,15 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, * chunk. */ tmp_addr = (unsigned long)base_addr + static_size; + if (local_base) + local_tmp = (unsigned long)local_base + static_size; if (ai->reserved_size) - pcpu_reserved_chunk = pcpu_alloc_first_chunk(tmp_addr, + pcpu_reserved_chunk = pcpu_alloc_first_chunk(tmp_addr, local_tmp, ai->reserved_size); tmp_addr = (unsigned long)base_addr + static_size + ai->reserved_size; - pcpu_first_chunk = pcpu_alloc_first_chunk(tmp_addr, dyn_size); + if (local_base) + local_tmp = (unsigned long)local_base + static_size + ai->reserved_size; + pcpu_first_chunk = pcpu_alloc_first_chunk(tmp_addr, local_tmp, dyn_size); pcpu_nr_empty_pop_pages = pcpu_first_chunk->nr_empty_pop_pages; pcpu_chunk_relocate(pcpu_first_chunk, -1); @@ -3108,7 +3115,7 @@ int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size, PFN_DOWN(size_sum), ai->static_size, ai->reserved_size, ai->dyn_size, ai->unit_size); - pcpu_setup_first_chunk(ai, base); + pcpu_setup_first_chunk(ai, base, NULL); goto out_free; out_free_areas: @@ -3260,6 +3267,8 @@ int __init pcpu_page_first_chunk(size_t reserved_size, pcpu_fc_cpu_to_node_fn_t vm.flags = VM_ALLOC; vm.size = num_possible_cpus() * ai->unit_size; vm_area_register_early(&vm, PAGE_SIZE); + + pcpu_vm.addr = NULL; #endif for (unit = 0; unit < num_possible_cpus(); unit++) { @@ -3295,7 +3304,7 @@ int __init pcpu_page_first_chunk(size_t reserved_size, pcpu_fc_cpu_to_node_fn_t unit_pages, psize_str, ai->static_size, ai->reserved_size, ai->dyn_size); - pcpu_setup_first_chunk(ai, vm.addr); + pcpu_setup_first_chunk(ai, vm.addr, pcpu_vm.addr); goto out_free_ar; enomem: @@ -3377,7 +3386,7 @@ void __init setup_per_cpu_areas(void) ai->groups[0].nr_units = 1; ai->groups[0].cpu_map[0] = 0; - pcpu_setup_first_chunk(ai, fc); + pcpu_setup_first_chunk(ai, fc, NULL); pcpu_free_alloc_info(ai); } -- 2.47.0