From patchwork Tue Jul 11 04:48:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 13308125 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 3A66CEB64DD for ; Tue, 11 Jul 2023 04:49:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2ECD8E0002; Tue, 11 Jul 2023 00:49:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CDF678E0001; Tue, 11 Jul 2023 00:49:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B802B8E0002; Tue, 11 Jul 2023 00:49:42 -0400 (EDT) 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 A61A58E0001 for ; Tue, 11 Jul 2023 00:49:42 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 77A53C01D6 for ; Tue, 11 Jul 2023 04:49:42 +0000 (UTC) X-FDA: 80998103004.27.12285F2 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf30.hostedemail.com (Postfix) with ESMTP id 399268000C for ; Tue, 11 Jul 2023 04:49:40 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=KJ7+NaAp; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf30.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689050980; 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:in-reply-to:references:references:dkim-signature; bh=eacDrbdl29DxFhYva5Qa/VnwoE6kPv96SsaOfM9iVK8=; b=CFUNGR8ol9sloWR018k7leMkHzYmvlfhMO8di2khteOq4MkenkGoLuk2sAArbuD2q0UFIh 5wK85XahD5EGrxgZTMsUjFx0kGqnAbCZ2i4XH1Nmcruf6Gd46FAiZV7tNJo9ZcZJf3L15h lJYY4KpG8c2rtiLBOJLYFhhavR/9pHA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=KJ7+NaAp; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf30.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689050980; a=rsa-sha256; cv=none; b=Og8EzKrp0Vug/uskzjTvbvviBO3i2QhuO4Y/OL3DeF4KaY9AfT1XmAj5KsQCMvbCnKQYPb 2F2kgOhpomKF96YUr70H5W0AmexU4c3Oe/hmHWpsGcFlLN//Oog9c76q2kYKX3odEhi+9O 3M7/Yi/J6ex+dVjc4GyWMvCXyL8PeUk= Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36B4dAhl028675; Tue, 11 Jul 2023 04:49:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=eacDrbdl29DxFhYva5Qa/VnwoE6kPv96SsaOfM9iVK8=; b=KJ7+NaApI9zWgMOH8hpNhh6W+YbFGRBfkcSk5FZycQg8/kKSScp8geXmdRubJi5yDEAd IQyXFJseWPpQTIqe+ovzu7qCL9jvwZTHNaHXUSlaQGyShaIu+gZ/j4W0O0814raSRU8z ek7Fdcn5E53MMTQ0JA4WPyjrc0nBogWxgMxJeMqaxNmda6e80eybJbai3rtA7BuAQhyq 0MOUQmRXFBvxtzakxAY+l5ti8CoZJdJIhIA0d7JPVC2ASCTLCRDfGAb6WfdGVMgI+EMX DHGiYgJl5a+uDnmuAxxgl8/5vYbba2bfl4wbDeBso/LU/do4iALPtJIB70FLl4Y1tFOF IA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rs085gdqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 04:49:33 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 36B4k2SE022906; Tue, 11 Jul 2023 04:49:32 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rs085gdq1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 04:49:32 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 36B4isnb027325; Tue, 11 Jul 2023 04:49:31 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([9.208.129.114]) by ppma02wdc.us.ibm.com (PPS) with ESMTPS id 3rpye654vb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 04:49:31 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36B4nUaN32178704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Jul 2023 04:49:30 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 537405804B; Tue, 11 Jul 2023 04:49:30 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 66FD15805B; Tue, 11 Jul 2023 04:49:25 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.86.43]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 11 Jul 2023 04:49:24 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: Oscar Salvador , David Hildenbrand , Michal Hocko , Vishal Verma , "Aneesh Kumar K.V" Subject: [PATCH v3 7/7] mm/hotplug: Embed vmem_altmap details in memory block Date: Tue, 11 Jul 2023 10:18:33 +0530 Message-ID: <20230711044834.72809-8-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230711044834.72809-1-aneesh.kumar@linux.ibm.com> References: <20230711044834.72809-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: t2kWuIOWjE3PtaxHweABZiJ1AaXIKpAx X-Proofpoint-GUID: alyn84FG50u2HhQsCbuZAtw8sCs7Emcm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-11_02,2023-07-06_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=694 mlxscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 lowpriorityscore=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307110040 X-Rspamd-Queue-Id: 399268000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: n4w3mcrtahs63pmo4njerwewd7o18st4 X-HE-Tag: 1689050980-893005 X-HE-Meta: U2FsdGVkX18QP+ZfQ7if/lkuRP1sZMJbvgU4q12jm5icl6RXXjDFvPBPLBzfPQfCcJtgGOIFviNxvz3mC9QwO/dmYPUltzWwZJuEyNZoHrpHU2WrQJidBfpOn/X7RqtKvg4++pMU6DkUX+2+QoNwJ3VBRAPEWF17OnJ5w2A4UtZwnj8hFCqMAefrHKF8n06RroNyttRbzhGNCzs4LDFLCEmzSSlz7mXE7i9AlQJzKTjv4wX7ye4rbmLlcxFhbAVSwbYO4Vopp1Q6pWFPCyaoJiCajk7lYIYAi13fG+4OWjHZnx4NCCRabrT1mrMI+/+kYb/HpeT53MZD56g4tvRVwkAmYuixYn8PZpuvwdrS+Vl/VSWQ+J8PVgfN4ySTOrmaHOxPnY8hh+M6ifmfwZ5j510sS/BIk3VSAJ2wlq3+BPcYfrgjFT+uo5ZYaoHohArsuXcnt0pA2a/o5V5Qt3KqqgiANwcLG1none9rTfucbjAqwCy2ViGl0GyxrutfeR40mC7zse1+My41qlvHONpXMcPuzO0L1UBfMmUUniaAenxM1104ISnM8YrAm6UDE0QlOborbk6f+WA8K9jCB5tYCOY7vB2Nl9Z6l0s2UFyN1HbSS3xxudQUZlR8mVCVikoIN8xBFD7GSrRxVc9DSRSYnHlLGfcpABZEUVaPJQHO6J8XwGtF3wjbbc/qrAZtdNaz90btKqiPptXfAK14oUjKVdtGam/62ganVWSrrwRGiVwjoTRq2VpiAK74Ctw//1eC8F/ci2/+yPLw9kD6LTNHt3NMibRDh0wmZHLR8bkNYWk2RQLofJd0ndeAPkMNrI4oXOHhXQ9nC/XcSfweaF9Y99T2Y+vuuykAtuIiVcHOusYYdW9JMZ6vFns4jinYDj27/NJpvnalsLpIcwNlY2fchmSiqCzDO27F87o186KIuC7r5ilkuw5aCS2l3gpjkS05Vm/iBuYJ1Ew8028rFul Pga+RWuR vp1xGjWpSC6jN/UWzpjT1PTFN4U7HQzWjNQ1qR4hP2r8xRLKGNtxelcHBQyZF0vDMajaYNbB+2cE4UeC4K5CoEYKBTZYBtaTrYlynn2MuSYNJ3rQRPXrM7aFFel55wW7dQ2xwe0KsfnGaqKJfvzJpDkxTsy2OwUUkspnOUXG5GT03G3O4z1nlX0YmTv00spHNYFY1 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: With memmap on memory, some architecture needs more details w.r.t altmap such as base_pfn, end_pfn, etc to unmap vmemmap memory. Instead of computing them again when we remove a memory block embed vmem_altmap details in struct memory_block if we are using memmap on memory block feature. No functional change in this patch Signed-off-by: Aneesh Kumar K.V --- drivers/base/memory.c | 35 ++++++++++++++++++++++++++--------- include/linux/memory.h | 8 ++------ mm/memory_hotplug.c | 34 ++++++++++++++-------------------- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b456ac213610..10aacaecf8de 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -106,6 +106,10 @@ static void memory_block_release(struct device *dev) { struct memory_block *mem = to_memory_block(dev); + if (mem->altmap) { + WARN(mem->altmap->alloc, "Altmap not fully unmapped"); + kfree(mem->altmap); + } kfree(mem); } @@ -183,7 +187,7 @@ static int memory_block_online(struct memory_block *mem) { unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; - unsigned long nr_vmemmap_pages = mem->nr_vmemmap_pages; + unsigned long nr_vmemmap_pages = 0; struct zone *zone; int ret; @@ -200,6 +204,9 @@ static int memory_block_online(struct memory_block *mem) * stage helps to keep accounting easier to follow - e.g vmemmaps * belong to the same zone as the memory they backed. */ + if (mem->altmap) + nr_vmemmap_pages = mem->altmap->alloc + mem->altmap->reserve; + if (nr_vmemmap_pages) { ret = mhp_init_memmap_on_memory(start_pfn, nr_vmemmap_pages, zone); if (ret) @@ -230,7 +237,7 @@ static int memory_block_offline(struct memory_block *mem) { unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; - unsigned long nr_vmemmap_pages = mem->nr_vmemmap_pages; + unsigned long nr_vmemmap_pages = 0; int ret; if (!mem->zone) @@ -240,6 +247,9 @@ static int memory_block_offline(struct memory_block *mem) * Unaccount before offlining, such that unpopulated zone and kthreads * can properly be torn down in offline_pages(). */ + if (mem->altmap) + nr_vmemmap_pages = mem->altmap->alloc + mem->altmap->reserve; + if (nr_vmemmap_pages) adjust_present_page_count(pfn_to_page(start_pfn), mem->group, -nr_vmemmap_pages); @@ -726,7 +736,7 @@ void memory_block_add_nid(struct memory_block *mem, int nid, #endif static int add_memory_block(unsigned long block_id, unsigned long state, - unsigned long nr_vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group) { struct memory_block *mem; @@ -744,7 +754,14 @@ static int add_memory_block(unsigned long block_id, unsigned long state, mem->start_section_nr = block_id * sections_per_block; mem->state = state; mem->nid = NUMA_NO_NODE; - mem->nr_vmemmap_pages = nr_vmemmap_pages; + if (altmap) { + mem->altmap = kmalloc(sizeof(struct vmem_altmap), GFP_KERNEL); + if (!mem->altmap) { + kfree(mem); + return -ENOMEM; + } + memcpy(mem->altmap, altmap, sizeof(*altmap)); + } INIT_LIST_HEAD(&mem->group_next); #ifndef CONFIG_NUMA @@ -783,14 +800,14 @@ static int __init add_boot_memory_block(unsigned long base_section_nr) if (section_count == 0) return 0; return add_memory_block(memory_block_id(base_section_nr), - MEM_ONLINE, 0, NULL); + MEM_ONLINE, NULL, NULL); } static int add_hotplug_memory_block(unsigned long block_id, - unsigned long nr_vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group) { - return add_memory_block(block_id, MEM_OFFLINE, nr_vmemmap_pages, group); + return add_memory_block(block_id, MEM_OFFLINE, altmap, group); } static void remove_memory_block(struct memory_block *memory) @@ -818,7 +835,7 @@ static void remove_memory_block(struct memory_block *memory) * Called under device_hotplug_lock. */ int create_memory_block_devices(unsigned long start, unsigned long size, - unsigned long vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group) { const unsigned long start_block_id = pfn_to_block_id(PFN_DOWN(start)); @@ -832,7 +849,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size, return -EINVAL; for (block_id = start_block_id; block_id != end_block_id; block_id++) { - ret = add_hotplug_memory_block(block_id, vmemmap_pages, group); + ret = add_hotplug_memory_block(block_id, altmap, group); if (ret) break; } diff --git a/include/linux/memory.h b/include/linux/memory.h index 31343566c221..f53cfdaaaa41 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -77,11 +77,7 @@ struct memory_block { */ struct zone *zone; struct device dev; - /* - * Number of vmemmap pages. These pages - * lay at the beginning of the memory block. - */ - unsigned long nr_vmemmap_pages; + struct vmem_altmap *altmap; struct memory_group *group; /* group (if any) for this block */ struct list_head group_next; /* next block inside memory group */ #if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_MEMORY_HOTPLUG) @@ -147,7 +143,7 @@ static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri) extern int register_memory_notifier(struct notifier_block *nb); extern void unregister_memory_notifier(struct notifier_block *nb); int create_memory_block_devices(unsigned long start, unsigned long size, - unsigned long vmemmap_pages, + struct vmem_altmap *altmap, struct memory_group *group); void remove_memory_block_devices(unsigned long start, unsigned long size); extern void memory_dev_init(void); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 0c4d3fdd31a2..f22831eaa93f 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1386,8 +1386,7 @@ int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) goto error; /* create memory block devices after memory was added */ - ret = create_memory_block_devices(start, size, mhp_altmap.alloc + mhp_altmap.reserve, - group); + ret = create_memory_block_devices(start, size, params.altmap, group); if (ret) { arch_remove_memory(start, size, NULL); goto error; @@ -1988,12 +1987,18 @@ static int check_memblock_offlined_cb(struct memory_block *mem, void *arg) return 0; } -static int get_nr_vmemmap_pages_cb(struct memory_block *mem, void *arg) +static int get_vmemmap_altmap_cb(struct memory_block *mem, void *arg) { + struct vmem_altmap **altmap = (struct vmem_altmap **)arg; /* - * If not set, continue with the next block. + * If we have any pages allocated from altmap + * return the altmap details and break callback. */ - return mem->nr_vmemmap_pages; + if (mem->altmap) { + *altmap = mem->altmap; + return 1; + } + return 0; } static int check_cpu_on_node(int nid) @@ -2068,9 +2073,8 @@ EXPORT_SYMBOL(try_offline_node); static int __ref try_remove_memory(u64 start, u64 size) { - struct vmem_altmap mhp_altmap = {}; + int ret; struct vmem_altmap *altmap = NULL; - unsigned long nr_vmemmap_pages; int rc = 0, nid = NUMA_NO_NODE; BUG_ON(check_hotplug_memory_range(start, size)); @@ -2093,25 +2097,15 @@ static int __ref try_remove_memory(u64 start, u64 size) * the same granularity it was added - a single memory block. */ if (mhp_memmap_on_memory()) { - nr_vmemmap_pages = walk_memory_blocks(start, size, NULL, - get_nr_vmemmap_pages_cb); - if (nr_vmemmap_pages) { + ret = walk_memory_blocks(start, size, &altmap, + get_vmemmap_altmap_cb); + if (ret) { if (size != memory_block_size_bytes()) { pr_warn("Refuse to remove %#llx - %#llx," "wrong granularity\n", start, start + size); return -EINVAL; } - - /* - * Let remove_pmd_table->free_hugepage_table do the - * right thing if we used vmem_altmap when hot-adding - * the range. - */ - mhp_altmap.base_pfn = PHYS_PFN(start); - mhp_altmap.free = PHYS_PFN(size) - nr_vmemmap_pages; - mhp_altmap.alloc = nr_vmemmap_pages; - altmap = &mhp_altmap; } }