From patchwork Tue Nov 27 16:20:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10700785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42955109C for ; Tue, 27 Nov 2018 16:20:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F9CF2C03C for ; Tue, 27 Nov 2018 16:20:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 233AA2C067; Tue, 27 Nov 2018 16:20:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 752322C03C for ; Tue, 27 Nov 2018 16:20:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3112E6B48EE; Tue, 27 Nov 2018 11:20:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2964B6B48F0; Tue, 27 Nov 2018 11:20:39 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09B596B48F2; Tue, 27 Nov 2018 11:20:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id B28746B48EE for ; Tue, 27 Nov 2018 11:20:38 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id 75so12143345pfq.8 for ; Tue, 27 Nov 2018 08:20:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=oiSRiDFO9E9QSI3x3EnPeiknaRm/sCPAKjOFlESNoe0=; b=iGq9OEQJjtDyNTMEsUQQFk8S7MtmbYOVPpB2JPnUDHh3UWNhiucI30Hbk3z/XA5zXt ffMvxBMp6rSmX1RtV5ghyvrKPBD+JS/iw5HGCAvYjIc7zyOt6Mhvufjv+1F+naHxSq/5 9658vUuwJ+3x/vZ2JqceXTHRWfKIwD4Q3djL2v1xFCjb44UxerZSuPciWRCGSXc/VvRu KWUQTf+jPo08wEFOlGN5jrILbbvIrPNsIP9pKtG996g/70fjRAzCdgMVvG+SGTs5Ngju 18krtQ0iUSg3HXYzUUr9JVJPhToaf8/kJSaeI0wxhz6HCYgcnlphk6cWmWOX8+UKaRf6 MfyA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AA+aEWYat3MRRhXWywTTKB0hLAk+DWlVhIn2+uVsQ6OEmjbub71sT5eu 8e7X79vKoZoXkprHNb9DMkjAFhwdSLJZ3AOuZmLVmAZS8ZBNvngbFHZWeyvrWm4a/hWS/odxFuA oEOahO92HDmB/MxqrH4TqIojC5/6lwiiAnZL6Gd1G1qN8CUhbmueUlA5pQ8iTD16dyw== X-Received: by 2002:a65:40c5:: with SMTP id u5mr28852664pgp.46.1543335637852; Tue, 27 Nov 2018 08:20:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/UZ4svdVppLcxC+ITtdpE7mpWtqdPcvrEjcmL55iU2wIyZ9bquLrFpGDbKzx0+BSTaZN9KH X-Received: by 2002:a65:40c5:: with SMTP id u5mr28852619pgp.46.1543335636824; Tue, 27 Nov 2018 08:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543335636; cv=none; d=google.com; s=arc-20160816; b=h41vD7w1Qn8d8hAJ/mjExzoxl4igr5ncqKlMUz2TbQU9JmfS+bmevOITfpfqer1Rr0 8YfIMqcrgjHWyi2/Cxtfu/wgcBvbxiMFMMqXdd+5a4pAu4xvWe8m566F/fU72wGcQvUg mJaqtPUIbsan6hsaEOC89SML5sdGcyeEWs5I8yIdTFqj0Ea5Y/FLS49+cOAxpIG5bZ7F gq0nWkU6oqNH53f7UugrfJDAWZ1Lb1bc1wzmcjVnIb+D+bLw8M1urjZvns37WWD3+TcH l4CUbWHfl/i0Rp0QImV64fj3AbZbBJaBsBWxdPJHJ52+1jnhaE+UT3r/ZNtERyauQPHA HBwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=oiSRiDFO9E9QSI3x3EnPeiknaRm/sCPAKjOFlESNoe0=; b=RTTDL51eEgAsBb/eIoG9JI8pSstS3fNsIkDQGjjq/7zQsU8+lTUZtUcBO5LgiNc94u YUgXu+avo4f2wr69Lrd9ll7zc0TvptSE793e886UW4g2w9WkAL5muKnANi+PATEBpiiv sLSXe2TF/7jyxypuhXG8KgJs1BRppRjM3KPxxQcdFo9O9Fw98c5q3+CmG22Jh7cVKCP9 1eE8tDoiEINB+TiwCuiQG+QvRsbcsfvjnYg4FYkp5Cx++9bJ9ZX/V5Moci24F3VEBdKq 644sQqEs56EzqM2LHVdpeBcA9FkaYn4dtjJChsCmZDj5+PvlZyYmENipPrgM0SWGT8Jo k9YA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id c15si3960584pgg.446.2018.11.27.08.20.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:20:36 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 27 Nov 2018 17:20:34 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 27 Nov 2018 16:20:13 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, pavel.tatashin@microsoft.com, jglisse@redhat.com, Jonathan.Cameron@huawei.com, rafael@kernel.org, david@redhat.com, linux-mm@kvack.org, Oscar Salvador , Oscar Salvador Subject: [PATCH v2 1/5] mm, memory_hotplug: Add nid parameter to arch_remove_memory Date: Tue, 27 Nov 2018 17:20:01 +0100 Message-Id: <20181127162005.15833-2-osalvador@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181127162005.15833-1-osalvador@suse.de> References: <20181127162005.15833-1-osalvador@suse.de> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Oscar Salvador This patch is only a preparation for the following-up patches. The idea of passing the nid is that it will allow us to get rid of the zone parameter afterwards. Signed-off-by: Oscar Salvador Reviewed-by: David Hildenbrand Reviewed-by: Pavel Tatashin --- arch/ia64/mm/init.c | 2 +- arch/powerpc/mm/mem.c | 3 ++- arch/s390/mm/init.c | 2 +- arch/sh/mm/init.c | 2 +- arch/x86/mm/init_32.c | 2 +- arch/x86/mm/init_64.c | 3 ++- include/linux/memory_hotplug.h | 4 ++-- kernel/memremap.c | 5 ++++- mm/memory_hotplug.c | 2 +- 9 files changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c index d5e12ff1d73c..904fe55e10fc 100644 --- a/arch/ia64/mm/init.c +++ b/arch/ia64/mm/init.c @@ -661,7 +661,7 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, } #ifdef CONFIG_MEMORY_HOTREMOVE -int arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) +int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 0a64fffabee1..40feb262080e 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -139,7 +139,8 @@ int __meminit arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap * } #ifdef CONFIG_MEMORY_HOTREMOVE -int __meminit arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) +int __meminit arch_remove_memory(int nid, u64 start, u64 size, + struct vmem_altmap *altmap) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 50388190b393..3e82f66d5c61 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -242,7 +242,7 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, } #ifdef CONFIG_MEMORY_HOTREMOVE -int arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) +int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { /* * There is no hardware or firmware interface which could trigger a diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c index c8c13c777162..a8e5c0e00fca 100644 --- a/arch/sh/mm/init.c +++ b/arch/sh/mm/init.c @@ -443,7 +443,7 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); #endif #ifdef CONFIG_MEMORY_HOTREMOVE -int arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) +int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { unsigned long start_pfn = PFN_DOWN(start); unsigned long nr_pages = size >> PAGE_SHIFT; diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c index 49ecf5ecf6d3..85c94f9a87f8 100644 --- a/arch/x86/mm/init_32.c +++ b/arch/x86/mm/init_32.c @@ -860,7 +860,7 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap, } #ifdef CONFIG_MEMORY_HOTREMOVE -int arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) +int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 5fab264948c2..449958da97a4 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1147,7 +1147,8 @@ kernel_physical_mapping_remove(unsigned long start, unsigned long end) remove_pagetable(start, end, true, NULL); } -int __ref arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) +int __ref arch_remove_memory(int nid, u64 start, u64 size, + struct vmem_altmap *altmap) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 84e9ae205930..3aedcd7929cd 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -107,8 +107,8 @@ static inline bool movable_node_is_enabled(void) } #ifdef CONFIG_MEMORY_HOTREMOVE -extern int arch_remove_memory(u64 start, u64 size, - struct vmem_altmap *altmap); +extern int arch_remove_memory(int nid, u64 start, u64 size, + struct vmem_altmap *altmap); extern int __remove_pages(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages, struct vmem_altmap *altmap); #endif /* CONFIG_MEMORY_HOTREMOVE */ diff --git a/kernel/memremap.c b/kernel/memremap.c index 3eef989ef035..0d5603d76c37 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -87,6 +87,7 @@ static void devm_memremap_pages_release(void *data) struct resource *res = &pgmap->res; resource_size_t align_start, align_size; unsigned long pfn; + int nid; pgmap->kill(pgmap->ref); for_each_device_pfn(pfn, pgmap) @@ -97,13 +98,15 @@ static void devm_memremap_pages_release(void *data) align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE) - align_start; + nid = page_to_nid(pfn_to_page(align_start >> PAGE_SHIFT)); + mem_hotplug_begin(); if (pgmap->type == MEMORY_DEVICE_PRIVATE) { pfn = align_start >> PAGE_SHIFT; __remove_pages(page_zone(pfn_to_page(pfn)), pfn, align_size >> PAGE_SHIFT, NULL); } else { - arch_remove_memory(align_start, align_size, + arch_remove_memory(nid, align_start, align_size, pgmap->altmap_valid ? &pgmap->altmap : NULL); kasan_remove_zero_shadow(__va(align_start), align_size); } diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7b4317ae8318..849bcc55c5f1 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1858,7 +1858,7 @@ void __ref __remove_memory(int nid, u64 start, u64 size) memblock_free(start, size); memblock_remove(start, size); - arch_remove_memory(start, size, NULL); + arch_remove_memory(nid, start, size, NULL); try_offline_node(nid); From patchwork Tue Nov 27 16:20:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10700787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CD4D109C for ; Tue, 27 Nov 2018 16:20:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C5102C0A7 for ; Tue, 27 Nov 2018 16:20:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 005FB2C068; Tue, 27 Nov 2018 16:20:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FCA22C067 for ; Tue, 27 Nov 2018 16:20:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C39AF6B48F0; Tue, 27 Nov 2018 11:20:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BC19E6B48F3; Tue, 27 Nov 2018 11:20:40 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EDEC6B48F4; Tue, 27 Nov 2018 11:20:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 526726B48F0 for ; Tue, 27 Nov 2018 11:20:40 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id 68so14408424pfr.6 for ; Tue, 27 Nov 2018 08:20:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=r9zH0dsu92dA/Tq/CzWHsmLnQoLC/zgThHTFaLEiF9U=; b=DlsrBvtLmocGC6o66IQ/uyDrBui42ESOZEIyO4NqgiJZYqTy6N7ltX8Ui8ji5yR+OG 2DDrNMSYvY4VtGcDh+bkU/R6QJkv5I6qSf5u+9J45OUfv58zbHBNLQ4Rqm6ml/ThcZBL IBXBCmz8RkcFtXadhDvSGLo292R2vNWgJsQ7egRn1dP3QL5LKuvkc9cy2eC3f4+WYRRp wskDrpATBbOUppay3uY9MFt2mw6qFEAok4zPynkAirb4XQpLb+Xf8KHfgYe1hL5W/iac j8aEhtRS6GMR5PGGzb/5pRFU0CyN2yzZmzC4S9NRG5VToEZenLqThoPke/eMUrUPv3Os MofQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AA+aEWYek6/rA2RAKQqxEuCWwZsjjyoRQylybFs7WppOlDDGkgSgNpPU yX0bXs32o36oR1UzgrYMo7WUK2uUowf9wCc47X4OluPrGMqiQkbru7T4Zx7T8tSJh9C6kCDvfrL xGbCtmIgOw+9x++uuewn+uLX4QrktYDdfwpPbwdQszGJUfx9A83Wlehg1imInKWQWkQ== X-Received: by 2002:a17:902:be0c:: with SMTP id r12mr19947745pls.299.1543335639927; Tue, 27 Nov 2018 08:20:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/VWstrTsCMcrrD7M5waYfHsT9/Sc31FlecJ83baS7dWfZuG3DayZe/qAJYc2F7wGokKF5IA X-Received: by 2002:a17:902:be0c:: with SMTP id r12mr19947681pls.299.1543335638760; Tue, 27 Nov 2018 08:20:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543335638; cv=none; d=google.com; s=arc-20160816; b=Rlwf8h0KkLo9QOIFKPzrticGmT2KuS7bZUQUW5t1HusiEUwFm2r5/+d+HomMhMlsjC aI0aQDGcrCJ6BFjxUEQEg0jZztXrGrwop3j07c7ihwgEKmlgP1B1Y4j80CYzagCwu9GQ nrs3+Gy9uaGzOZOxGIberASmtTt2JvUGK8qhXUJOvXXzZyuuMreSEIpnmJbKOxyp8R+8 PkcCVv6SLhykZnEzc28AHBg0OUmirjlU631fVfPc4sNJXp3ar0uU2VA+3k2drn30zGjD TF8MilNLrwKvX4zzeI6itKYYf+rAL+e1U+KtBcThZk03ILtfMZeyiDOnTDmaCMD4kATm 9VKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=r9zH0dsu92dA/Tq/CzWHsmLnQoLC/zgThHTFaLEiF9U=; b=zK7yE2J4vPudLRWw24/R0B87YDLh2uflQCcmfTV46SkmIj2axH/UPJD/wGCfIjvr2a DRmVmmLuWmJKcrcMcJw08TT8+G8V70jq1bsJYrE0JblieyPuYPgDrQ3oZLWNms1GDq/O azIu95hOW7aztYNaL+UxJ4jhikAISfikQOsU4eJ4lG4Gh/N4894SON6eXKLu7a/iDCGK OKAnyMduJRKFNWiITnfWQozdtbHbf0LniNODNXrJ84llPGPpPLtms5FRBs2QXjsOV9hs ehW9XBIDgQT+Yd24G+bHkB+IMLToFC2cgwXll8YRzg7/EDhaJDeupBE2tpAtmPV6gmZp MIMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id p26si5129609pli.225.2018.11.27.08.20.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:20:38 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 27 Nov 2018 17:20:36 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 27 Nov 2018 16:20:14 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, pavel.tatashin@microsoft.com, jglisse@redhat.com, Jonathan.Cameron@huawei.com, rafael@kernel.org, david@redhat.com, linux-mm@kvack.org, Oscar Salvador Subject: [PATCH v2 2/5] kernel, resource: Check for IORESOURCE_SYSRAM in release_mem_region_adjustable Date: Tue, 27 Nov 2018 17:20:02 +0100 Message-Id: <20181127162005.15833-3-osalvador@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181127162005.15833-1-osalvador@suse.de> References: <20181127162005.15833-1-osalvador@suse.de> 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: X-Virus-Scanned: ClamAV using ClamSMTP This is a preparation for the next patch. Currently, we only call release_mem_region_adjustable() in __remove_pages if the zone is not ZONE_DEVICE, because resources that belong to HMM/devm are being released by themselves with devm_release_mem_region. Since we do not want to touch any zone/page stuff during the removing of the memory (but during the offlining), we do not want to check for the zone here. So we need another way to tell release_mem_region_adjustable() to not realease the resource in case it belongs to HMM/devm. HMM/devm acquires/releases a resource through devm_request_mem_region/devm_release_mem_region. These resources have the flag IORESOURCE_MEM, while resources acquired by hot-add memory path (register_memory_resource()) contain IORESOURCE_SYSTEM_RAM. So, we can check for this flag in release_mem_region_adjustable, and if the resource does not contain such flag, we know that we are dealing with a HMM/devm resource, so we can back off. Signed-off-by: Oscar Salvador Reviewed-by: David Hildenbrand Reviewed-by: Pavel Tatashin --- kernel/resource.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/resource.c b/kernel/resource.c index 0aaa95005a2e..e20cea416f1f 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1266,6 +1266,21 @@ int release_mem_region_adjustable(struct resource *parent, continue; } + /* + * All memory regions added from memory-hotplug path have the + * flag IORESOURCE_SYSTEM_RAM. If the resource does not have + * this flag, we know that we are dealing with a resource coming + * from HMM/devm. HMM/devm use another mechanism to add/release + * a resource. This goes via devm_request_mem_region and + * devm_release_mem_region. + * HMM/devm take care to release their resources when they want, + * so if we are dealing with them, let us just back off here. + */ + if (!(res->flags & IORESOURCE_SYSRAM)) { + ret = 0; + break; + } + if (!(res->flags & IORESOURCE_MEM)) break; From patchwork Tue Nov 27 16:20:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10700789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C975109C for ; Tue, 27 Nov 2018 16:20:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 476972C078 for ; Tue, 27 Nov 2018 16:20:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BA672C08F; Tue, 27 Nov 2018 16:20:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0601B2C07A for ; Tue, 27 Nov 2018 16:20:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E30E6B48F3; Tue, 27 Nov 2018 11:20:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6171C6B48F5; Tue, 27 Nov 2018 11:20:42 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B9EE6B48F6; Tue, 27 Nov 2018 11:20:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id EA4F46B48F3 for ; Tue, 27 Nov 2018 11:20:41 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id l9so23427550plt.7 for ; Tue, 27 Nov 2018 08:20:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=Tj5Fh8thaRwCQFFe2e/MZPTIAPXOCwJSSlsFSWUr1hM=; b=OV7fJP1yqhhIijL+St5ql5JnwT7ZFrYepi6SLWuQVTUZAl9wxYfLnPFpO0Fs1UWikS OWMtowP/PLnmvlZiU5QErYjR1Wb03NWgpW35e21WnP0uUNiuR+Y1XwTHad0gbIgcc/kW qBLF5RggrwKf93n8H/EI8I3dF8IAehMmAtUAGzryh2JH1aOkJ5BHp6o2Rucooct50tZV OBS1j7t4LWZ+FdGmtD4UtASrAe69d2ba+P6rVJ4e2fZTwtoocJ2fOlTYBLeqFnCAZPLx egM8GlndmS8rX8J+yk3hXAgd7MU2boFSTiK7H1lfL3c8f6g7cR73wU2ar3bVEV/cMUz3 9ucw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AA+aEWaPm0QjE/krJt94LZHBNa+0GzJ2KK1u2/4H9HT/fg1RVuK6gvMV x50GrYs9KzGsOUSaj4yS31iVaxTF4xUbZSW0VL7twKfNnYndUhYvX6URqBWB0gb7cyTq4cUCrvp DmyHkqGuiUheGiob6hphMFIr/j5RO/s8Yh00bkVEhQ91yXsMeQqFwl6g3VYe6TYafOg== X-Received: by 2002:a17:902:6681:: with SMTP id e1-v6mr2865702plk.173.1543335641519; Tue, 27 Nov 2018 08:20:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/WPTtN3KcpyTd3eANa2W8cs4D0ZQtjILpT/dT/yfVXsIVwaA6UDa1q0nfooE29pQPht/Aq9 X-Received: by 2002:a17:902:6681:: with SMTP id e1-v6mr2865631plk.173.1543335640247; Tue, 27 Nov 2018 08:20:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543335640; cv=none; d=google.com; s=arc-20160816; b=dFEEMH6pW1cvd2oplpie5Fybha8blS6RVhjAL/ykiwuERPrlOhdJNdYUqqjyjblJu9 7iQ2gjBZhrVjfBksqf7190wg1JZx0jY+gdBvKCs1aWOhcm1tai61h7KevY+2wfLzg7Zy F+YHsqpO2zimvLpoVMD8B5B6spwq1UYtr2Zf80jWqmVqtuPFTb0C5l5e8wJzCXDprz4C xDyENSWY9ycwLdNuXK/Goy45XsDXlKnl/ScSkR9a/K610dOzzqd2GlSfwlB9Ya5tcP5l dda3SVecPJ9r8Z1TWRN0RvExno8mwKIHvw5rmFU0QGzcm0+clbXvFvli+oWsX6gZue8h 5jrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=Tj5Fh8thaRwCQFFe2e/MZPTIAPXOCwJSSlsFSWUr1hM=; b=eGA0fRqmNMAZ89J3pSFRLuqvXnSHgEZL1bPjvead+blqhcxjJQLPgWAYoVDITNMxk0 oUEgKPDkzWvjDCmbWsf+xiqGj917Vjtket74fCGGlW0QHfEzi5rsual6L9HqLQCBAs/C R/eIHxwqvKESi7xjV+VEHBUjoa+Mw4lGOEwLzcjLmQOqPztH/TooMUMmvxZFMCH7MpFS bMBnJ/ixK2AmJ3vyE0/mmqcRD+BDdk6xW1HXc6Spsrj7ms0KPQ0L9Geg0qhf6abEybIB cQJ9yby4EGGcDocJjOALiAc+GDmg0OEkEURNYiixA5tKxwDwVDl9A0giDyDAscZF+Rts WE+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id y10si3926463plt.406.2018.11.27.08.20.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:20:40 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 27 Nov 2018 17:20:37 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 27 Nov 2018 16:20:14 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, pavel.tatashin@microsoft.com, jglisse@redhat.com, Jonathan.Cameron@huawei.com, rafael@kernel.org, david@redhat.com, linux-mm@kvack.org, Oscar Salvador , Oscar Salvador Subject: [PATCH v2 3/5] mm, memory_hotplug: Move zone/pages handling to offline stage Date: Tue, 27 Nov 2018 17:20:03 +0100 Message-Id: <20181127162005.15833-4-osalvador@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181127162005.15833-1-osalvador@suse.de> References: <20181127162005.15833-1-osalvador@suse.de> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Oscar Salvador The current implementation accesses pages during hot-remove stage in order to get the zone linked to this memory-range. We use that zone for a) check if the zone is ZONE_DEVICE and b) to shrink the zone's spanned pages. Accessing pages during this stage is problematic, as we might be accessing pages that were not initialized if we did not get to online the memory before removing it. The only reason to check for ZONE_DEVICE in __remove_pages is to bypass the call to release_mem_region_adjustable(), since these regions are removed with devm_release_mem_region. With patch#2, this is no longer a problem so we can safely call release_mem_region_adjustable(). release_mem_region_adjustable() will spot that the region we are trying to remove was acquired by means of devm_request_mem_region, and will back off safely. This allows us to remove all zone-related operations from hot-remove stage. Because of this, zone's spanned pages are shrinked during the offlining stage in shrink_zone_pgdat(). It would have been great to decrease also the spanned page for the node there, but we need them in try_offline_node(). So we still decrease spanned pages for the node in the hot-remove stage. The only particularity is that now find_smallest_section_pfn/find_biggest_section_pfn, when called from shrink_zone_span, will now check for online sections and not valid sections instead. To make this work with devm/HMM code, we need to call offline_mem_sections and online_mem_sections in that code path when we are adding memory. Signed-off-by: Oscar Salvador --- arch/powerpc/mm/mem.c | 11 +---- arch/sh/mm/init.c | 4 +- arch/x86/mm/init_32.c | 3 +- arch/x86/mm/init_64.c | 8 +--- include/linux/memory_hotplug.h | 8 ++-- kernel/memremap.c | 14 +++++-- mm/memory_hotplug.c | 95 ++++++++++++++++++++++++------------------ mm/sparse.c | 4 +- 8 files changed, 76 insertions(+), 71 deletions(-) diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 40feb262080e..b3c9ee5c4f78 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -144,18 +144,9 @@ int __meminit arch_remove_memory(int nid, u64 start, u64 size, { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; - struct page *page; int ret; - /* - * If we have an altmap then we need to skip over any reserved PFNs - * when querying the zone. - */ - page = pfn_to_page(start_pfn); - if (altmap) - page += vmem_altmap_offset(altmap); - - ret = __remove_pages(page_zone(page), start_pfn, nr_pages, altmap); + ret = remove_sections(nid, start_pfn, nr_pages, altmap); if (ret) return ret; diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c index a8e5c0e00fca..1a483a008872 100644 --- a/arch/sh/mm/init.c +++ b/arch/sh/mm/init.c @@ -447,11 +447,9 @@ int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { unsigned long start_pfn = PFN_DOWN(start); unsigned long nr_pages = size >> PAGE_SHIFT; - struct zone *zone; int ret; - zone = page_zone(pfn_to_page(start_pfn)); - ret = __remove_pages(zone, start_pfn, nr_pages, altmap); + ret = remove_sections(nid, start_pfn, nr_pages, altmap); if (unlikely(ret)) pr_warn("%s: Failed, __remove_pages() == %d\n", __func__, ret); diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c index 85c94f9a87f8..0b8c7b0033d2 100644 --- a/arch/x86/mm/init_32.c +++ b/arch/x86/mm/init_32.c @@ -866,8 +866,7 @@ int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) unsigned long nr_pages = size >> PAGE_SHIFT; struct zone *zone; - zone = page_zone(pfn_to_page(start_pfn)); - return __remove_pages(zone, start_pfn, nr_pages, altmap); + return remove_sections(nid, start_pfn, nr_pages, altmap); } #endif #endif diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 449958da97a4..f80d98381a97 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1152,15 +1152,9 @@ int __ref arch_remove_memory(int nid, u64 start, u64 size, { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; - struct page *page = pfn_to_page(start_pfn); - struct zone *zone; int ret; - /* With altmap the first mapped page is offset from @start */ - if (altmap) - page += vmem_altmap_offset(altmap); - zone = page_zone(page); - ret = __remove_pages(zone, start_pfn, nr_pages, altmap); + ret = remove_sections(nid, start_pfn, nr_pages, altmap); WARN_ON_ONCE(ret); kernel_physical_mapping_remove(start, start + size); diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 3aedcd7929cd..0a882d8e32c6 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -109,8 +109,10 @@ static inline bool movable_node_is_enabled(void) #ifdef CONFIG_MEMORY_HOTREMOVE extern int arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap); -extern int __remove_pages(struct zone *zone, unsigned long start_pfn, - unsigned long nr_pages, struct vmem_altmap *altmap); +extern int remove_sections(int nid, unsigned long start_pfn, + unsigned long nr_pages, struct vmem_altmap *altmap); +extern void shrink_zone(struct zone *zone, unsigned long start_pfn, + unsigned long end_pfn, unsigned long offlined_pages); #endif /* CONFIG_MEMORY_HOTREMOVE */ /* reasonably generic interface to expand the physical pages */ @@ -335,7 +337,7 @@ extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); extern bool is_memblock_offlined(struct memory_block *mem); extern int sparse_add_one_section(struct pglist_data *pgdat, unsigned long start_pfn, struct vmem_altmap *altmap); -extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, +extern void sparse_remove_one_section(int nid, struct mem_section *ms, unsigned long map_offset, struct vmem_altmap *altmap); extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, unsigned long pnum); diff --git a/kernel/memremap.c b/kernel/memremap.c index 0d5603d76c37..66cbf334203b 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -87,6 +87,7 @@ static void devm_memremap_pages_release(void *data) struct resource *res = &pgmap->res; resource_size_t align_start, align_size; unsigned long pfn; + unsigned long nr_pages; int nid; pgmap->kill(pgmap->ref); @@ -101,10 +102,14 @@ static void devm_memremap_pages_release(void *data) nid = page_to_nid(pfn_to_page(align_start >> PAGE_SHIFT)); mem_hotplug_begin(); + + pfn = align_start >> PAGE_SHIFT; + nr_pages = align_size >> PAGE_SHIFT; + offline_mem_sections(pfn, pfn + nr_pages); + shrink_zone(page_zone(pfn_to_page(pfn)), pfn, pfn + nr_pages, nr_pages); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) { - pfn = align_start >> PAGE_SHIFT; - __remove_pages(page_zone(pfn_to_page(pfn)), pfn, - align_size >> PAGE_SHIFT, NULL); + remove_sections(nid, pfn, nr_pages, NULL); } else { arch_remove_memory(nid, align_start, align_size, pgmap->altmap_valid ? &pgmap->altmap : NULL); @@ -224,7 +229,10 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) if (!error) { struct zone *zone; + unsigned long pfn = align_start >> PAGE_SHIFT; + unsigned long nr_pages = align_size >> PAGE_SHIFT; + online_mem_sections(pfn, pfn + nr_pages); zone = &NODE_DATA(nid)->node_zones[ZONE_DEVICE]; move_pfn_range_to_zone(zone, align_start >> PAGE_SHIFT, align_size >> PAGE_SHIFT, altmap); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 849bcc55c5f1..4fe42ccb0be4 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -314,6 +314,17 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn, } #ifdef CONFIG_MEMORY_HOTREMOVE +static bool is_section_ok(struct mem_section *ms, bool zone) +{ + /* + * We cannot shrink pgdat's spanned because we use them + * in try_offline_node to check if all sections were removed. + */ + if (zone) + return online_section(ms); + else + return valid_section(ms); +} /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, unsigned long start_pfn, @@ -324,7 +335,7 @@ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) { ms = __pfn_to_section(start_pfn); - if (unlikely(!valid_section(ms))) + if (!is_section_ok(ms, !!zone)) continue; if (unlikely(pfn_to_nid(start_pfn) != nid)) @@ -352,7 +363,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone, for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) { ms = __pfn_to_section(pfn); - if (unlikely(!valid_section(ms))) + if (!is_section_ok(ms, !!zone)) continue; if (unlikely(pfn_to_nid(pfn) != nid)) @@ -414,7 +425,7 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) { ms = __pfn_to_section(pfn); - if (unlikely(!valid_section(ms))) + if (unlikely(!online_section(ms))) continue; if (page_zone(pfn_to_page(pfn)) != zone) @@ -501,23 +512,33 @@ static void shrink_pgdat_span(struct pglist_data *pgdat, pgdat->node_spanned_pages = 0; } -static void __remove_zone(struct zone *zone, unsigned long start_pfn) +void shrink_zone(struct zone *zone, unsigned long start_pfn, + unsigned long end_pfn, unsigned long offlined_pages) { - struct pglist_data *pgdat = zone->zone_pgdat; int nr_pages = PAGES_PER_SECTION; + unsigned long pfn; + + clear_zone_contiguous(zone); + for (pfn = start_pfn; pfn < end_pfn; pfn += nr_pages) + shrink_zone_span(zone, pfn, pfn + nr_pages); + set_zone_contiguous(zone); +} + +static void shrink_pgdat(int nid, unsigned long sect_nr) +{ + struct pglist_data *pgdat = NODE_DATA(nid); + int nr_pages = PAGES_PER_SECTION; + unsigned long pfn = section_nr_to_pfn((unsigned long)sect_nr); unsigned long flags; - pgdat_resize_lock(zone->zone_pgdat, &flags); - shrink_zone_span(zone, start_pfn, start_pfn + nr_pages); - shrink_pgdat_span(pgdat, start_pfn, start_pfn + nr_pages); - pgdat_resize_unlock(zone->zone_pgdat, &flags); + pgdat_resize_lock(pgdat, &flags); + shrink_pgdat_span(pgdat, pfn, pfn + nr_pages); + pgdat_resize_unlock(pgdat, &flags); } -static int __remove_section(struct zone *zone, struct mem_section *ms, +static int __remove_section(int nid, struct mem_section *ms, unsigned long map_offset, struct vmem_altmap *altmap) { - unsigned long start_pfn; - int scn_nr; int ret = -EINVAL; if (!valid_section(ms)) @@ -527,17 +548,15 @@ static int __remove_section(struct zone *zone, struct mem_section *ms, if (ret) return ret; - scn_nr = __section_nr(ms); - start_pfn = section_nr_to_pfn((unsigned long)scn_nr); - __remove_zone(zone, start_pfn); + shrink_pgdat(nid, __section_nr(ms)); - sparse_remove_one_section(zone, ms, map_offset, altmap); + sparse_remove_one_section(nid, ms, map_offset, altmap); return 0; } /** - * __remove_pages() - remove sections of pages from a zone - * @zone: zone from which pages need to be removed + * __remove_pages() - remove sections of pages from a nid + * @nid: nid from which pages belong to * @phys_start_pfn: starting pageframe (must be aligned to start of a section) * @nr_pages: number of pages to remove (must be multiple of section size) * @altmap: alternative device page map or %NULL if default memmap is used @@ -547,35 +566,28 @@ static int __remove_section(struct zone *zone, struct mem_section *ms, * sure that pages are marked reserved and zones are adjust properly by * calling offline_pages(). */ -int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, +int remove_sections(int nid, unsigned long phys_start_pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { unsigned long i; unsigned long map_offset = 0; int sections_to_remove, ret = 0; + resource_size_t start, size; - /* In the ZONE_DEVICE case device driver owns the memory region */ - if (is_dev_zone(zone)) { - if (altmap) - map_offset = vmem_altmap_offset(altmap); - } else { - resource_size_t start, size; - - start = phys_start_pfn << PAGE_SHIFT; - size = nr_pages * PAGE_SIZE; + start = phys_start_pfn << PAGE_SHIFT; + size = nr_pages * PAGE_SIZE; - ret = release_mem_region_adjustable(&iomem_resource, start, - size); - if (ret) { - resource_size_t endres = start + size - 1; + if (altmap) + map_offset = vmem_altmap_offset(altmap); - pr_warn("Unable to release resource <%pa-%pa> (%d)\n", - &start, &endres, ret); - } + ret = release_mem_region_adjustable(&iomem_resource, start, + size); + if (ret) { + resource_size_t endres = start + size - 1; + pr_warn("Unable to release resource <%pa-%pa> (%d)\n", + &start, &endres, ret); } - clear_zone_contiguous(zone); - /* * We can only remove entire sections */ @@ -587,15 +599,13 @@ int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; cond_resched(); - ret = __remove_section(zone, __pfn_to_section(pfn), map_offset, - altmap); + ret = __remove_section(nid, __pfn_to_section(pfn), map_offset, + altmap); map_offset = 0; if (ret) break; } - set_zone_contiguous(zone); - return ret; } #endif /* CONFIG_MEMORY_HOTREMOVE */ @@ -1652,11 +1662,14 @@ static int __ref __offline_pages(unsigned long start_pfn, /* reset pagetype flags and makes migrate type to be MOVABLE */ undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); /* removal success */ + + /* Shrink zone's managed,spanned and zone/pgdat's present pages */ adjust_managed_page_count(pfn_to_page(start_pfn), -offlined_pages); zone->present_pages -= offlined_pages; pgdat_resize_lock(zone->zone_pgdat, &flags); zone->zone_pgdat->node_present_pages -= offlined_pages; + shrink_zone(zone, valid_start, valid_end, offlined_pages); pgdat_resize_unlock(zone->zone_pgdat, &flags); init_per_zone_wmark_min(); diff --git a/mm/sparse.c b/mm/sparse.c index 691544a2814c..01aa42102f8b 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -790,12 +790,12 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap, free_map_bootmem(memmap); } -void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, +void sparse_remove_one_section(int nid, struct mem_section *ms, unsigned long map_offset, struct vmem_altmap *altmap) { struct page *memmap = NULL; unsigned long *usemap = NULL, flags; - struct pglist_data *pgdat = zone->zone_pgdat; + struct pglist_data *pgdat = NODE_DATA(nid); pgdat_resize_lock(pgdat, &flags); if (ms->section_mem_map) { From patchwork Tue Nov 27 16:25:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10700795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 417D113BB for ; Tue, 27 Nov 2018 16:26:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EE6B2C012 for ; Tue, 27 Nov 2018 16:26:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 224422C0C2; Tue, 27 Nov 2018 16:26:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SUBJ_OBFU_PUNCT_FEW,SUBJ_OBFU_PUNCT_MANY autolearn=no version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 094ED2C012 for ; Tue, 27 Nov 2018 16:26:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06F0C6B4900; Tue, 27 Nov 2018 11:26:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 01D4E6B4901; Tue, 27 Nov 2018 11:26:06 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E28296B4902; Tue, 27 Nov 2018 11:26:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 8C81A6B4900 for ; Tue, 27 Nov 2018 11:26:06 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id o21so7688213edq.4 for ; Tue, 27 Nov 2018 08:26:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=F1Nr2zVB8EvcG8qb92zXU5I/lOCOVfhjZfaoDqEe3q8=; b=h5wMmI8QgvmAT5fgVsWSaIWguJs4JRottjdEo+/88OVPDJXeBkSrM4xqANBvjV23gG jRqoZBZ+oFLjYzJErUjpsbKCHGjXTIHrjqKjs5pwk93IoXBnBGLI6vk1lsCNIULiD1g+ 4TPUVcu0YIkaTsYShSgJMUE7C1xepid31+hDewDGIJSA3lbzeM35wF3r2JmD4lysMNhb g6hhlSWjlp1ZXnUVSiMWYVddJeaBvlcHRVWC/5oX6lY9VA8AfMfHeFvTMLLvV9UzXx7n fNhcs77FFNeGOkZZxWkOyJmHhQo4A6KKN5Np/f3YXVOPRzslPK9j8xLbrwIVx5DEQkHq uHaA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AGRZ1gIPP0Z1UhEpCXsiNqPxAGlzc+jPkD8RhNL3HwEZkfcyZvh+Ghxa AT08PYfgcE4avmE9HAoYbQdEilQx4Ao2ODpIaXCH94xzpYGIk/Mso+CLQoxpP68wMWea56tfET8 XfOKyJzb02zI7sLNsSSLDRRz4jnBa11KKbMa7CZhpaNMRfBmb0MWV1Utq1CaOfuklyA== X-Received: by 2002:a17:906:6011:: with SMTP id o17-v6mr24235119ejj.237.1543335965959; Tue, 27 Nov 2018 08:26:05 -0800 (PST) X-Google-Smtp-Source: AJdET5egkTbZkoiWm976Lzh8hZ5ZGKQukFAoXqMCI02Rq0hl1ZFux70PdUBpvZiPkD+Iy2qQDUnC X-Received: by 2002:a17:906:6011:: with SMTP id o17-v6mr24235071ejj.237.1543335964707; Tue, 27 Nov 2018 08:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543335964; cv=none; d=google.com; s=arc-20160816; b=nxyYiLHlaxdYvNN/Pgk95mQ/uUSYkqeGf6DgDIKwwZONqUuA1zOOFmWxafoqMFYr83 2hInOpUF64BkQpbm6QjIkCZhLj+Cga6RlSPtAzuCY1sCSu/Rz+ivJJjRnhOWBWudOVhs oAtITPqUNTJbV7ouuaRUMO6YPwvAmDAVZQBIzECux7D90G6Kpoi8OqZFtm73yTIqxqLa AN6aNRKNWyPJ8sIixUlAJ1v0kcrhq1ct0VZotRPh3wac+h4nGA3ZkHEYxiUyeOrXMNc9 hQOyJHfCSQfL5gcXWFZm5ljtpy+juY6iWiUInSoeHd/hvRmDlWpSR421sjhIHC0fW46t MXuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=F1Nr2zVB8EvcG8qb92zXU5I/lOCOVfhjZfaoDqEe3q8=; b=pqCG+nqJMUZqHjSoPe7BU6n7IbNlCsNDcYH/qC1/STOflYGkPovQqecO3+JaJIJVLM quFzurHcPdo60mOK0xI7leH4rLCKUwryevL+KlQNrO3xiETN+1v2vTB/YgA/cmo6NMDX 6X0hnTvVSBgYFwV1OP1IwL5wNpk8FDZeHYuGyQE9SAWEvc664p+St5S2B7yc1vCaGYGV Ws+yCxdj+4+01HX4hDS43myi8X2bsD2y31fa/nKqknnkV6T/hsJlt7BUsHsnaztk1KeU MoUVv35RoGIlxeVJ5EpPvdk8r4gvLDZOhc5K2oj8X7VZXu1MRytI2Agk4asyH121HlMn xuZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id k3-v6si27618ejr.219.2018.11.27.08.26.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:26:04 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 27 Nov 2018 17:26:03 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 27 Nov 2018 16:25:42 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, pavel.tatashin@microsoft.com, jglisse@redhat.com, Jonathan.Cameron@huawei.com, rafael@kernel.org, david@redhat.com, linux-mm@kvack.org, Oscar Salvador , Oscar Salvador Subject: [PATCH v2 4/5] mm, memory-hotplug: Rework unregister_mem_sect_under_nodes Date: Tue, 27 Nov 2018 17:25:35 +0100 Message-Id: <20181127162535.15910-1-osalvador@suse.de> X-Mailer: git-send-email 2.13.6 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Oscar Salvador This tries to address another issue about accessing unitiliazed pages. Jonathan reported a problem [1] where we can access steal pages in case we hot-remove memory without onlining it first. This time is in unregister_mem_sect_under_nodes. This function tries to get the nid from the pfn and then tries to remove the symlink between mem_blk <-> nid and vice versa. Since we already know the nid in remove_memory(), we can pass it down the chain to unregister_mem_sect_under_nodes. There we can just remove the symlinks without the need to look into the pages. This also allows us to cleanup unregister_mem_sect_under_nodes. [1] https://www.spinics.net/lists/linux-mm/msg161316.html Signed-off-by: Oscar Salvador Tested-by: Jonathan Cameron --- drivers/base/memory.c | 9 ++++----- drivers/base/node.c | 39 ++++++--------------------------------- include/linux/memory.h | 2 +- include/linux/node.h | 9 ++++----- mm/memory_hotplug.c | 2 +- 5 files changed, 16 insertions(+), 45 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 0e5985682642..3d8c65d84bea 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -744,8 +744,7 @@ unregister_memory(struct memory_block *memory) device_unregister(&memory->dev); } -static int remove_memory_section(unsigned long node_id, - struct mem_section *section, int phys_device) +static int remove_memory_section(unsigned long nid, struct mem_section *section) { struct memory_block *mem; @@ -759,7 +758,7 @@ static int remove_memory_section(unsigned long node_id, if (!mem) goto out_unlock; - unregister_mem_sect_under_nodes(mem, __section_nr(section)); + unregister_mem_sect_under_nodes(nid, mem); mem->section_count--; if (mem->section_count == 0) @@ -772,12 +771,12 @@ static int remove_memory_section(unsigned long node_id, return 0; } -int unregister_memory_section(struct mem_section *section) +int unregister_memory_section(int nid, struct mem_section *section) { if (!present_section(section)) return -EINVAL; - return remove_memory_section(0, section, 0); + return remove_memory_section(nid, section); } #endif /* CONFIG_MEMORY_HOTREMOVE */ diff --git a/drivers/base/node.c b/drivers/base/node.c index 86d6cd92ce3d..0858f7f3c7cd 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -453,40 +453,13 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) return 0; } -/* unregister memory section under all nodes that it spans */ -int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index) +/* Remove symlink between node <-> mem_blk */ +void unregister_mem_sect_under_nodes(int nid, struct memory_block *mem_blk) { - NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); - unsigned long pfn, sect_start_pfn, sect_end_pfn; - - if (!mem_blk) { - NODEMASK_FREE(unlinked_nodes); - return -EFAULT; - } - if (!unlinked_nodes) - return -ENOMEM; - nodes_clear(*unlinked_nodes); - - sect_start_pfn = section_nr_to_pfn(phys_index); - sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; - for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { - int nid; - - nid = get_nid_for_pfn(pfn); - if (nid < 0) - continue; - if (!node_online(nid)) - continue; - if (node_test_and_set(nid, *unlinked_nodes)) - continue; - sysfs_remove_link(&node_devices[nid]->dev.kobj, - kobject_name(&mem_blk->dev.kobj)); - sysfs_remove_link(&mem_blk->dev.kobj, - kobject_name(&node_devices[nid]->dev.kobj)); - } - NODEMASK_FREE(unlinked_nodes); - return 0; + sysfs_remove_link(&node_devices[nid]->dev.kobj, + kobject_name(&mem_blk->dev.kobj)); + sysfs_remove_link(&mem_blk->dev.kobj, + kobject_name(&node_devices[nid]->dev.kobj)); } int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn) diff --git a/include/linux/memory.h b/include/linux/memory.h index a6ddefc60517..d75ec88ca09d 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -113,7 +113,7 @@ extern int register_memory_isolate_notifier(struct notifier_block *nb); extern void unregister_memory_isolate_notifier(struct notifier_block *nb); int hotplug_memory_register(int nid, struct mem_section *section); #ifdef CONFIG_MEMORY_HOTREMOVE -extern int unregister_memory_section(struct mem_section *); +extern int unregister_memory_section(int nid, struct mem_section *); #endif extern int memory_dev_init(void); extern int memory_notify(unsigned long val, void *v); diff --git a/include/linux/node.h b/include/linux/node.h index 257bb3d6d014..488c1333bb06 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -72,8 +72,8 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); extern int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg); -extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index); +extern void unregister_mem_sect_under_nodes(int nid, + struct memory_block *mem_blk); #ifdef CONFIG_HUGETLBFS extern void register_hugetlbfs_with_node(node_registration_func_t doregister, @@ -105,10 +105,9 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk, { return 0; } -static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index) +static inline void unregister_mem_sect_under_nodes(int nid, + struct memory_block *mem_blk) { - return 0; } static inline void register_hugetlbfs_with_node(node_registration_func_t reg, diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 4fe42ccb0be4..49b91907e19e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -544,7 +544,7 @@ static int __remove_section(int nid, struct mem_section *ms, if (!valid_section(ms)) return ret; - ret = unregister_memory_section(ms); + ret = unregister_memory_section(nid, ms); if (ret) return ret; From patchwork Tue Nov 27 16:20:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10700791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF04F15A7 for ; Tue, 27 Nov 2018 16:20:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBF3B2BFFF for ; Tue, 27 Nov 2018 16:20:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D01272C084; Tue, 27 Nov 2018 16:20:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D57A2BFFF for ; Tue, 27 Nov 2018 16:20:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF2566B48F5; Tue, 27 Nov 2018 11:20:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E7B1B6B48F7; Tue, 27 Nov 2018 11:20:43 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCDF66B48F8; Tue, 27 Nov 2018 11:20:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 8475F6B48F5 for ; Tue, 27 Nov 2018 11:20:43 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id 75so12143503pfq.8 for ; Tue, 27 Nov 2018 08:20:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=x/y2fSWSjzgnUrsW0zmFCZt5KOKR2Mvo+rugbSemlkM=; b=GwXXPODZ3n8HnLDlj27JKLssUbNhHr1HUC3qPsja2RsJ4bug1i642zFFDMgvsScnKU rGkXA8bcnrFaFjCi2BhHYdy41XlGKht0ALSMLTVJdl99rc8yW8gwPhSCdg6irPaBTzRb a0lN+zB2MYr6sMTn9BTrKTNebPLh1ljWLfEwjuOtslIGhx/0hX/2g9w0soc+OD8p3gsV 7T4PvTKjh4Skkl+YseNz7of9wdGqmbrt6HQ1kwo029BHlhKErWAdnSs54AB1+MSjUA5A o8h/sLGky4I+dHOMDK2qIugn3VG700Zvxq6x07BRu4c4bhFamXXyPYgseH88Z6g08LYz pMIQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AA+aEWbMjTz4lsqXMvOxCWTkGYYmw4uXOg9P1KxpWeWmpx48ZW+vy6bY heOCwN0JjAwcyRPFRzEtd1tA9jsrGDoNkLVgZIu1I8ZLjQs7ut9G5W9eVxUkQ2UOXOXJSp2xncc is+y19sPJxDtaHm1ETjrEgF1FQk1q92uRRXf1FtQUhn1I3sMTSfqKqAZZ3DVntn+OAw== X-Received: by 2002:a17:902:820d:: with SMTP id x13mr33734875pln.229.1543335643123; Tue, 27 Nov 2018 08:20:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/VoYMkL4jHe2RgU62V+DHgWvUWNd5YfvgYYSuOl2IvvKGEgqJz4qxFmghAmVhtZi+tNaHmd X-Received: by 2002:a17:902:820d:: with SMTP id x13mr33734784pln.229.1543335641734; Tue, 27 Nov 2018 08:20:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543335641; cv=none; d=google.com; s=arc-20160816; b=CktURyj53cihnVnDbUK3NIC5gPzxydKer9PxytVj32Er8rtQI8yP/Yam3KcMcXoI17 1vrJ4qRZZ+YCIM9DBxk+5ZDLyac/wXZOfId35P7FamtTXqWbpL+a25ZOMuC6eRiHHPkk OQisUdfr0Im69BqwEI4R3QrA1psNzAcdA+S7XmYMJSQmZ8+6dioStJcZRn73tqPhQaMM spvMqoKfxYP7yIbOf8vwcL5Trgjv9+q2DVd9NtDf9i2dCxMRPUidEf6F/SDptWh+e7Wk udaav4ZQakQ+MipBKPMkjL/WZGQG4onEP5zfBCQDn3YLFCaNZxvcO1f/EpUz0RSY0vZV RTRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=x/y2fSWSjzgnUrsW0zmFCZt5KOKR2Mvo+rugbSemlkM=; b=S77xGh6ybA5SFZ3TpgK/L4D7AWm4WXRWPM8jbIjWLO2uwlhhxyFi+i2YsVqq/eoynn vydFRn8lyz0dWoi7OhYh8WgbfZfBLvpdTzkM15/Ddwe6uh/h6WIVqPe4snWqvQhvunFs f48uMn2/VEOTpy8CnnJQ6949IcPHQV382TLGoHB+UFepngI0GfOUjX3XH+/joYC1ZUrC ye0Eezljgz+tww0UJobRFfjliMSeCvzaDDCT57OEDk9UakzqD/1hHrZQX8ob7DnXudRp UjfSLmvUsopT5ZHXEj82lcNPZwU8ds+BPZMM/O9dwR/IuW4yu9kQlhjP1GLuSBCFxRMw GnFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id h19si4399825plr.67.2018.11.27.08.20.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:20:41 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 27 Nov 2018 17:20:39 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 27 Nov 2018 16:20:15 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, pavel.tatashin@microsoft.com, jglisse@redhat.com, Jonathan.Cameron@huawei.com, rafael@kernel.org, david@redhat.com, linux-mm@kvack.org, Oscar Salvador , Oscar Salvador Subject: [PATCH v2 5/5] mm, memory_hotplug: Refactor shrink_zone/pgdat_span Date: Tue, 27 Nov 2018 17:20:05 +0100 Message-Id: <20181127162005.15833-6-osalvador@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181127162005.15833-1-osalvador@suse.de> References: <20181127162005.15833-1-osalvador@suse.de> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Oscar Salvador shrink_zone_span and shrink_pgdat_span look a bit weird. They both have a loop at the end to check if the zone or pgdat contains only holes in case the section to be removed was not either the first one or the last one. Both code loops look quite similar, so we can simplify it a bit. We do that by creating a function (has_only_holes), that basically calls find_smallest_section_pfn() with the full range. In case nothing has to be found, we do not have any more sections there. To be honest, I am not really sure we even need to go through this check in case we are removing a middle section, because from what I can see, we will always have a first/last section. Taking the chance, we could also simplify both find_smallest_section_pfn() and find_biggest_section_pfn() functions and move the common code to a helper. Signed-off-by: Oscar Salvador --- mm/memory_hotplug.c | 163 +++++++++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 99 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 49b91907e19e..0e3f89423153 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -325,28 +325,29 @@ static bool is_section_ok(struct mem_section *ms, bool zone) else return valid_section(ms); } + +static bool is_valid_section(struct zone *zone, int nid, unsigned long pfn) +{ + struct mem_section *ms = __pfn_to_section(pfn); + + if (unlikely(!is_section_ok(ms, !!zone))) + return false; + if (unlikely(pfn_to_nid(pfn) != nid)) + return false; + if (zone && zone != page_zone(pfn_to_page(pfn))) + return false; + + return true; +} + /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) { - struct mem_section *ms; - - for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) { - ms = __pfn_to_section(start_pfn); - - if (!is_section_ok(ms, !!zone)) - continue; - - if (unlikely(pfn_to_nid(start_pfn) != nid)) - continue; - - if (zone && zone != page_zone(pfn_to_page(start_pfn))) - continue; - - return start_pfn; - } - + for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) + if (is_valid_section(zone, nid, start_pfn)) + return start_pfn; return 0; } @@ -355,29 +356,26 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) { - struct mem_section *ms; unsigned long pfn; /* pfn is the end pfn of a memory section. */ pfn = end_pfn - 1; - for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) { - ms = __pfn_to_section(pfn); - - if (!is_section_ok(ms, !!zone)) - continue; - - if (unlikely(pfn_to_nid(pfn) != nid)) - continue; - - if (zone && zone != page_zone(pfn_to_page(pfn))) - continue; - - return pfn; - } - + for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) + if (is_valid_section(zone, nid, pfn)) + return pfn; return 0; } +static bool has_only_holes(int nid, struct zone *zone, + unsigned long start_pfn, + unsigned long end_pfn) +{ + /* + * Let us check if the range has only holes + */ + return !find_smallest_section_pfn(nid, zone, start_pfn, end_pfn); +} + static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) { @@ -385,7 +383,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */ unsigned long zone_end_pfn = z; unsigned long pfn; - struct mem_section *ms; int nid = zone_to_nid(zone); zone_span_writelock(zone); @@ -397,11 +394,12 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, * for shrinking zone. */ pfn = find_smallest_section_pfn(nid, zone, end_pfn, - zone_end_pfn); - if (pfn) { - zone->zone_start_pfn = pfn; - zone->spanned_pages = zone_end_pfn - pfn; - } + zone_end_pfn); + if (!pfn) + goto no_sections; + + zone->zone_start_pfn = pfn; + zone->spanned_pages = zone_end_pfn - pfn; } else if (zone_end_pfn == end_pfn) { /* * If the section is biggest section in the zone, it need @@ -410,39 +408,23 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, * shrinking zone. */ pfn = find_biggest_section_pfn(nid, zone, zone_start_pfn, - start_pfn); - if (pfn) - zone->spanned_pages = pfn - zone_start_pfn + 1; - } - - /* - * The section is not biggest or smallest mem_section in the zone, it - * only creates a hole in the zone. So in this case, we need not - * change the zone. But perhaps, the zone has only hole data. Thus - * it check the zone has only hole or not. - */ - pfn = zone_start_pfn; - for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) { - ms = __pfn_to_section(pfn); - - if (unlikely(!online_section(ms))) - continue; + start_pfn); + if (!pfn) + goto no_sections; - if (page_zone(pfn_to_page(pfn)) != zone) - continue; - - /* If the section is current section, it continues the loop */ - if (start_pfn == pfn) - continue; - - /* If we find valid section, we have nothing to do */ - zone_span_writeunlock(zone); - return; + zone->spanned_pages = pfn - zone_start_pfn + 1; + } else { + if (has_only_holes(nid, zone, zone_start_pfn, zone_end_pfn)) + goto no_sections; } + goto out; + +no_sections: /* The zone has no valid section */ zone->zone_start_pfn = 0; zone->spanned_pages = 0; +out: zone_span_writeunlock(zone); } @@ -453,7 +435,6 @@ static void shrink_pgdat_span(struct pglist_data *pgdat, unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */ unsigned long pgdat_end_pfn = p; unsigned long pfn; - struct mem_section *ms; int nid = pgdat->node_id; if (pgdat_start_pfn == start_pfn) { @@ -465,10 +446,11 @@ static void shrink_pgdat_span(struct pglist_data *pgdat, */ pfn = find_smallest_section_pfn(nid, NULL, end_pfn, pgdat_end_pfn); - if (pfn) { - pgdat->node_start_pfn = pfn; - pgdat->node_spanned_pages = pgdat_end_pfn - pfn; - } + if (!pfn) + goto no_sections; + + pgdat->node_start_pfn = pfn; + pgdat->node_spanned_pages = pgdat_end_pfn - pfn; } else if (pgdat_end_pfn == end_pfn) { /* * If the section is biggest section in the pgdat, it need @@ -478,35 +460,18 @@ static void shrink_pgdat_span(struct pglist_data *pgdat, */ pfn = find_biggest_section_pfn(nid, NULL, pgdat_start_pfn, start_pfn); - if (pfn) - pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1; - } - - /* - * If the section is not biggest or smallest mem_section in the pgdat, - * it only creates a hole in the pgdat. So in this case, we need not - * change the pgdat. - * But perhaps, the pgdat has only hole data. Thus it check the pgdat - * has only hole or not. - */ - pfn = pgdat_start_pfn; - for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SECTION) { - ms = __pfn_to_section(pfn); - - if (unlikely(!valid_section(ms))) - continue; - - if (pfn_to_nid(pfn) != nid) - continue; + if (!pfn) + goto no_sections; - /* If the section is current section, it continues the loop */ - if (start_pfn == pfn) - continue; - - /* If we find valid section, we have nothing to do */ - return; + pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1; + } else { + if (has_only_holes(nid, NULL, pgdat_start_pfn, pgdat_end_pfn)) + goto no_sections; } + return; + +no_sections: /* The pgdat has no valid section */ pgdat->node_start_pfn = 0; pgdat->node_spanned_pages = 0; @@ -540,6 +505,7 @@ static int __remove_section(int nid, struct mem_section *ms, unsigned long map_offset, struct vmem_altmap *altmap) { int ret = -EINVAL; + int sect_nr = __section_nr(ms); if (!valid_section(ms)) return ret; @@ -548,9 +514,8 @@ static int __remove_section(int nid, struct mem_section *ms, if (ret) return ret; - shrink_pgdat(nid, __section_nr(ms)); - sparse_remove_one_section(nid, ms, map_offset, altmap); + shrink_pgdat(nid, (unsigned long)sect_nr); return 0; }