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 X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D212C47094 for ; Mon, 7 Jun 2021 19:57:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B6A160FF4 for ; Mon, 7 Jun 2021 19:57:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B6A160FF4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D30FF6B0072; Mon, 7 Jun 2021 15:57:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D07B76B0073; Mon, 7 Jun 2021 15:57:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B811C6B0075; Mon, 7 Jun 2021 15:57:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id 8230C6B0072 for ; Mon, 7 Jun 2021 15:57:19 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 11E35822A9B9 for ; Mon, 7 Jun 2021 19:57:19 +0000 (UTC) X-FDA: 78227986998.29.B3BA966 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id E6408C0A46A4 for ; Mon, 7 Jun 2021 19:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623095812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fc+iKS9+ANFB6y1dZFMDW1G21rBUMRkywsva5h/mmrk=; b=ctdKxI6i47E4V4tMXF4ZlHkDvoNpWsB+R+OIHRNaOzNk8RvD4+mSc/N8g67HFnXhjxS5qE 4m8973Xk6F/5hj2FxuE0U6lrsGK9WxbV8BnjpioKxRYPVHPWuAIfsehTRz8IQ9A5Z3kx4a kw47QYl9RdADV9AHvFnvfbIsxX92YBk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-lI1-N8yyPdK7mZjPkzUA4A-1; Mon, 07 Jun 2021 15:55:30 -0400 X-MC-Unique: lI1-N8yyPdK7mZjPkzUA4A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B4B8810074A6; Mon, 7 Jun 2021 19:55:26 +0000 (UTC) Received: from t480s.redhat.com (ovpn-112-9.ams2.redhat.com [10.36.112.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C7381002D71; Mon, 7 Jun 2021 19:55:14 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Vitaly Kuznetsov , "Michael S. Tsirkin" , Jason Wang , Marek Kedzierski , Hui Zhu , Pankaj Gupta , Wei Yang , Oscar Salvador , Michal Hocko , Dan Williams , Anshuman Khandual , Dave Hansen , Vlastimil Babka , Mike Rapoport , "Rafael J. Wysocki" , Len Brown , Pavel Tatashin , virtualization@lists.linux-foundation.org, linux-mm@kvack.org, linux-acpi@vger.kernel.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Vishal Verma , Dave Jiang , Nathan Lynch , Laurent Dufour , "Aneesh Kumar K.V" , Scott Cheloha , Anton Blanchard , linuxppc-dev@lists.ozlabs.org, nvdimm@lists.linux.dev Subject: [PATCH v1 05/12] mm/memory_hotplug: remove nid parameter from remove_memory() and friends Date: Mon, 7 Jun 2021 21:54:23 +0200 Message-Id: <20210607195430.48228-6-david@redhat.com> In-Reply-To: <20210607195430.48228-1-david@redhat.com> References: <20210607195430.48228-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E6408C0A46A4 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ctdKxI6i; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Stat-Signature: cgy6uhzbbcfy9k383jsgma5tntei7czr X-HE-Tag: 1623095819-99873 Content-Transfer-Encoding: quoted-printable 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: There is only a single user remaining. We can simply try to offline all online nodes - which is fast, because we usually span pages and can skip such nodes right away. Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: "Rafael J. Wysocki" Cc: Len Brown Cc: Dan Williams Cc: Vishal Verma Cc: Dave Jiang Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Andrew Morton Cc: Nathan Lynch Cc: Laurent Dufour Cc: "Aneesh Kumar K.V" Cc: Scott Cheloha Cc: Anton Blanchard Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-acpi@vger.kernel.org Cc: nvdimm@lists.linux.dev Signed-off-by: David Hildenbrand --- .../platforms/pseries/hotplug-memory.c | 9 ++++----- drivers/acpi/acpi_memhotplug.c | 7 +------ drivers/dax/kmem.c | 3 +-- drivers/virtio/virtio_mem.c | 4 ++-- include/linux/memory_hotplug.h | 10 +++++----- mm/memory_hotplug.c | 20 +++++++++---------- 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/power= pc/platforms/pseries/hotplug-memory.c index 8377f1f7c78e..4a9232ddbefe 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -286,7 +286,7 @@ static int pseries_remove_memblock(unsigned long base= , unsigned long memblock_si { unsigned long block_sz, start_pfn; int sections_per_block; - int i, nid; + int i; =20 start_pfn =3D base >> PAGE_SHIFT; =20 @@ -297,10 +297,9 @@ static int pseries_remove_memblock(unsigned long bas= e, unsigned long memblock_si =20 block_sz =3D pseries_memory_block_size(); sections_per_block =3D block_sz / MIN_MEMORY_BLOCK_SIZE; - nid =3D memory_add_physaddr_to_nid(base); =20 for (i =3D 0; i < sections_per_block; i++) { - __remove_memory(nid, base, MIN_MEMORY_BLOCK_SIZE); + __remove_memory(base, MIN_MEMORY_BLOCK_SIZE); base +=3D MIN_MEMORY_BLOCK_SIZE; } =20 @@ -386,7 +385,7 @@ static int dlpar_remove_lmb(struct drmem_lmb *lmb) =20 block_sz =3D pseries_memory_block_size(); =20 - __remove_memory(mem_block->nid, lmb->base_addr, block_sz); + __remove_memory(lmb->base_addr, block_sz); put_device(&mem_block->dev); =20 /* Update memory regions for memory remove */ @@ -638,7 +637,7 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb) =20 rc =3D dlpar_online_lmb(lmb); if (rc) { - __remove_memory(nid, lmb->base_addr, block_sz); + __remove_memory(lmb->base_addr, block_sz); invalidate_lmb_associativity_index(lmb); } else { lmb->flags |=3D DRCONF_MEM_ASSIGNED; diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplu= g.c index 8cc195c4c861..1d01d9414c40 100644 --- a/drivers/acpi/acpi_memhotplug.c +++ b/drivers/acpi/acpi_memhotplug.c @@ -239,19 +239,14 @@ static int acpi_memory_enable_device(struct acpi_me= mory_device *mem_device) =20 static void acpi_memory_remove_memory(struct acpi_memory_device *mem_dev= ice) { - acpi_handle handle =3D mem_device->device->handle; struct acpi_memory_info *info, *n; - int nid =3D acpi_get_node(handle); =20 list_for_each_entry_safe(info, n, &mem_device->res_list, list) { if (!info->enabled) continue; =20 - if (nid =3D=3D NUMA_NO_NODE) - nid =3D memory_add_physaddr_to_nid(info->start_addr); - acpi_unbind_memory_blocks(info); - __remove_memory(nid, info->start_addr, info->length); + __remove_memory(info->start_addr, info->length); list_del(&info->list); kfree(info); } diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index ac231cc36359..99e0f60c4c26 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -156,8 +156,7 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_d= ax) if (rc) continue; =20 - rc =3D remove_memory(dev_dax->target_node, range.start, - range_len(&range)); + rc =3D remove_memory(range.start, range_len(&range)); if (rc =3D=3D 0) { release_resource(data->res[i]); kfree(data->res[i]); diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 10ec60d81e84..e327fb878143 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -673,7 +673,7 @@ static int virtio_mem_remove_memory(struct virtio_mem= *vm, uint64_t addr, =20 dev_dbg(&vm->vdev->dev, "removing memory: 0x%llx - 0x%llx\n", addr, addr + size - 1); - rc =3D remove_memory(vm->nid, addr, size); + rc =3D remove_memory(addr, size); if (!rc) { atomic64_sub(size, &vm->offline_size); /* @@ -728,7 +728,7 @@ static int virtio_mem_offline_and_remove_memory(struc= t virtio_mem *vm, "offlining and removing memory: 0x%llx - 0x%llx\n", addr, addr + size - 1); =20 - rc =3D offline_and_remove_memory(vm->nid, addr, size); + rc =3D offline_and_remove_memory(addr, size); if (!rc) { atomic64_sub(size, &vm->offline_size); /* diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplu= g.h index 1d8d09c029c9..84f05435e2ae 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -319,9 +319,9 @@ static inline void pgdat_resize_init(struct pglist_da= ta *pgdat) {} =20 extern void try_offline_node(int nid); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages= ); -extern int remove_memory(int nid, u64 start, u64 size); -extern void __remove_memory(int nid, u64 start, u64 size); -extern int offline_and_remove_memory(int nid, u64 start, u64 size); +extern int remove_memory(u64 start, u64 size); +extern void __remove_memory(u64 start, u64 size); +extern int offline_and_remove_memory(u64 start, u64 size); =20 #else static inline void try_offline_node(int nid) {} @@ -331,12 +331,12 @@ static inline int offline_pages(unsigned long start= _pfn, unsigned long nr_pages) return -EINVAL; } =20 -static inline int remove_memory(int nid, u64 start, u64 size) +static inline int remove_memory(u64 start, u64 size) { return -EBUSY; } =20 -static inline void __remove_memory(int nid, u64 start, u64 size) {} +static inline void __remove_memory(u64 start, u64 size) {} #endif /* CONFIG_MEMORY_HOTREMOVE */ =20 extern void set_zone_contiguous(struct zone *zone); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index f9be66bbd847..9cae42636f3e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -2157,9 +2157,9 @@ void try_offline_node(int nid) } EXPORT_SYMBOL(try_offline_node); =20 -static int __ref try_remove_memory(int nid, u64 start, u64 size) +static int __ref try_remove_memory(u64 start, u64 size) { - int rc =3D 0; + int rc =3D 0, nid; struct vmem_altmap mhp_altmap =3D {}; struct vmem_altmap *altmap =3D NULL; unsigned long nr_vmemmap_pages; @@ -2220,7 +2220,8 @@ static int __ref try_remove_memory(int nid, u64 sta= rt, u64 size) =20 release_mem_region_adjustable(start, size); =20 - try_offline_node(nid); + for_each_online_node(nid) + try_offline_node(nid); =20 mem_hotplug_done(); return 0; @@ -2228,7 +2229,6 @@ static int __ref try_remove_memory(int nid, u64 sta= rt, u64 size) =20 /** * remove_memory - * @nid: the node ID * @start: physical address of the region to remove * @size: size of the region to remove * @@ -2236,14 +2236,14 @@ static int __ref try_remove_memory(int nid, u64 s= tart, u64 size) * and online/offline operations before this call, as required by * try_offline_node(). */ -void __remove_memory(int nid, u64 start, u64 size) +void __remove_memory(u64 start, u64 size) { =20 /* * trigger BUG() if some memory is not offlined prior to calling this * function */ - if (try_remove_memory(nid, start, size)) + if (try_remove_memory(start, size)) BUG(); } =20 @@ -2251,12 +2251,12 @@ void __remove_memory(int nid, u64 start, u64 size= ) * Remove memory if every memory block is offline, otherwise return -EBU= SY is * some memory is not offline */ -int remove_memory(int nid, u64 start, u64 size) +int remove_memory(u64 start, u64 size) { int rc; =20 lock_device_hotplug(); - rc =3D try_remove_memory(nid, start, size); + rc =3D try_remove_memory(start, size); unlock_device_hotplug(); =20 return rc; @@ -2316,7 +2316,7 @@ static int try_reonline_memory_block(struct memory_= block *mem, void *arg) * unplugged all memory (so it's no longer in use) and want to offline += remove * that memory. */ -int offline_and_remove_memory(int nid, u64 start, u64 size) +int offline_and_remove_memory(u64 start, u64 size) { const unsigned long mb_count =3D size / memory_block_size_bytes(); uint8_t *online_types, *tmp; @@ -2352,7 +2352,7 @@ int offline_and_remove_memory(int nid, u64 start, u= 64 size) * This cannot fail as it cannot get onlined in the meantime. */ if (!rc) { - rc =3D try_remove_memory(nid, start, size); + rc =3D try_remove_memory(start, size); if (rc) pr_err("%s: Failed to remove memory: %d", __func__, rc); } --=20 2.31.1