From patchwork Thu Feb 20 04:33:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11393283 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B6D214BC for ; Thu, 20 Feb 2020 04:33:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 283EC20801 for ; Thu, 20 Feb 2020 04:33:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QOQzU3zo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 283EC20801 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 546326B0006; Wed, 19 Feb 2020 23:33:41 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F72E6B0007; Wed, 19 Feb 2020 23:33:41 -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 40DCB6B0008; Wed, 19 Feb 2020 23:33:41 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0172.hostedemail.com [216.40.44.172]) by kanga.kvack.org (Postfix) with ESMTP id 2E7D26B0006 for ; Wed, 19 Feb 2020 23:33:41 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E63B41260 for ; Thu, 20 Feb 2020 04:33:40 +0000 (UTC) X-FDA: 76509237000.07.clock78_2017321af2a48 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:richardw.yang@linux.intel.com:david@redhat.com:osalvador@suse.de:dan.j.williams@intel.com:mhocko@suse.com:bhe@redhat.com:rppt@linux.ibm.com:robin.murphy@arm.com,RULES_HIT:30029:30054:30056,0,RBL:205.139.110.61:@redhat.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: clock78_2017321af2a48 X-Filterd-Recvd-Size: 3929 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 04:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=OypSrNlVU+Ioj3sY2Bn1pRl83867r8kivUZcDObKvMU=; b=QOQzU3zoGv4xv4jPiD7DQi8pw5NDSXmBim/n/tp5NOP/9Vnzo8LUhswcs2Pz4OheiXhFkX jzEj7K6qbI1B8t2lbb+dlDcwUnigo4ldEsIV66cXcs0osfX6pDX/z+LJTYZOUkWW4D7X4R U/D4aA/kDKANam4see5NqHVI/vSXy1Q= 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-268-P5cc6_KBPaSE5q765trgJg-1; Wed, 19 Feb 2020 23:33:35 -0500 X-MC-Unique: P5cc6_KBPaSE5q765trgJg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E663107ACC4; Thu, 20 Feb 2020 04:33:33 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 995CA5DA60; Thu, 20 Feb 2020 04:33:26 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, richardw.yang@linux.intel.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, mhocko@suse.com, bhe@redhat.com, rppt@linux.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 1/7] mm/hotplug: fix hot remove failure in SPARSEMEM|!VMEMMAP case Date: Thu, 20 Feb 2020 12:33:10 +0800 Message-Id: <20200220043316.19668-2-bhe@redhat.com> In-Reply-To: <20200220043316.19668-1-bhe@redhat.com> References: <20200220043316.19668-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: In section_deactivate(), pfn_to_page() doesn't work any more after ms->section_mem_map is resetting to NULL in SPARSEMEM|!VMEMMAP case. It caused hot remove failure: kernel BUG at mm/page_alloc.c:4806! invalid opcode: 0000 [#1] SMP PTI CPU: 3 PID: 8 Comm: kworker/u16:0 Tainted: G W 5.5.0-next-20200205+ #340 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 Workqueue: kacpi_hotplug acpi_hotplug_work_fn RIP: 0010:free_pages+0x85/0xa0 Call Trace: __remove_pages+0x99/0xc0 arch_remove_memory+0x23/0x4d try_remove_memory+0xc8/0x130 ? walk_memory_blocks+0x72/0xa0 __remove_memory+0xa/0x11 acpi_memory_device_remove+0x72/0x100 acpi_bus_trim+0x55/0x90 acpi_device_hotplug+0x2eb/0x3d0 acpi_hotplug_work_fn+0x1a/0x30 process_one_work+0x1a7/0x370 worker_thread+0x30/0x380 ? flush_rcu_work+0x30/0x30 kthread+0x112/0x130 ? kthread_create_on_node+0x60/0x60 ret_from_fork+0x35/0x40 Let's move the ->section_mem_map resetting after depopulate_section_memmap() to fix it. Signed-off-by: Baoquan He Reviewed-by: Wei Yang Reviewed-by: David Hildenbrand Reviewed-by: David Hildenbrand Reviewed-by: Dan Williams --- mm/sparse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/sparse.c b/mm/sparse.c index 596b2a45b100..b8e52c8fed7f 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -779,13 +779,15 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, ms->usage = NULL; } memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); - ms->section_mem_map = (unsigned long)NULL; } if (section_is_early && memmap) free_map_bootmem(memmap); else depopulate_section_memmap(pfn, nr_pages, altmap); + + if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) + ms->section_mem_map = (unsigned long)NULL; } static struct page * __meminit section_activate(int nid, unsigned long pfn, From patchwork Thu Feb 20 04:33:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11393285 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96E3914BC for ; Thu, 20 Feb 2020 04:33:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5300024673 for ; Thu, 20 Feb 2020 04:33:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZRKLAn8A" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5300024673 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 8A3106B0007; Wed, 19 Feb 2020 23:33:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8522C6B0008; Wed, 19 Feb 2020 23:33:45 -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 7686B6B000A; Wed, 19 Feb 2020 23:33:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 63A286B0007 for ; Wed, 19 Feb 2020 23:33:45 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2F9DE181AEF10 for ; Thu, 20 Feb 2020 04:33:45 +0000 (UTC) X-FDA: 76509237210.26.limit57_20b8d9ad1ee5a X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:richardw.yang@linux.intel.com:david@redhat.com:osalvador@suse.de:dan.j.williams@intel.com:mhocko@suse.com:bhe@redhat.com:rppt@linux.ibm.com:robin.murphy@arm.com,RULES_HIT:30012:30034:30054,0,RBL:207.211.31.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: limit57_20b8d9ad1ee5a X-Filterd-Recvd-Size: 4592 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 04:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=ekBaR/Uum+S2ojPBcrtCzTRvb9rStp58NNQZFSgK8iY=; b=ZRKLAn8A64D22NtFDQrKQ30zPUUYaxVF2+RoXlpjQA+YbCGln9V752BynTkg+y533NwDqc ZOU9JXQuFRry8qbLG7n7LgKfuHoK6UrB+wQpGp0nM7NVzVgfQwWT428SKFh5Y90U3GzOmZ FavU0KDrfJlGRkOBQAoFxufBYaGI++w= 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-175-4m-qdQPuNUSpTIHSi1mBIQ-1; Wed, 19 Feb 2020 23:33:40 -0500 X-MC-Unique: 4m-qdQPuNUSpTIHSi1mBIQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 365D08017DF; Thu, 20 Feb 2020 04:33:38 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E4865DA60; Thu, 20 Feb 2020 04:33:33 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, richardw.yang@linux.intel.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, mhocko@suse.com, bhe@redhat.com, rppt@linux.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 2/7] mm/sparse.c: introduce new function fill_subsection_map() Date: Thu, 20 Feb 2020 12:33:11 +0800 Message-Id: <20200220043316.19668-3-bhe@redhat.com> In-Reply-To: <20200220043316.19668-1-bhe@redhat.com> References: <20200220043316.19668-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: Wrap the codes filling subsection map from section_activate() into fill_subsection_map(), this makes section_activate() cleaner and easier to follow. Signed-off-by: Baoquan He Reviewed-by: Wei Yang Reviewed-by: David Hildenbrand --- mm/sparse.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index b8e52c8fed7f..977b47acd38d 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -790,24 +790,28 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, ms->section_mem_map = (unsigned long)NULL; } -static struct page * __meminit section_activate(int nid, unsigned long pfn, - unsigned long nr_pages, struct vmem_altmap *altmap) +/** + * fill_subsection_map - fill subsection map of a memory region + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This fills the related subsection map inside one section, and only + * intended for hotplug. + * + * Return: + * * 0 - On success. + * * -EINVAL - Invalid memory region. + * * -EEXIST - Subsection map has been set. + */ +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) { - DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; struct mem_section *ms = __pfn_to_section(pfn); - struct mem_section_usage *usage = NULL; + DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; unsigned long *subsection_map; - struct page *memmap; int rc = 0; subsection_mask_set(map, pfn, nr_pages); - if (!ms->usage) { - usage = kzalloc(mem_section_usage_size(), GFP_KERNEL); - if (!usage) - return ERR_PTR(-ENOMEM); - ms->usage = usage; - } subsection_map = &ms->usage->subsection_map[0]; if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) @@ -818,6 +822,25 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, bitmap_or(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); + return rc; +} + +static struct page * __meminit section_activate(int nid, unsigned long pfn, + unsigned long nr_pages, struct vmem_altmap *altmap) +{ + struct mem_section *ms = __pfn_to_section(pfn); + struct mem_section_usage *usage = NULL; + struct page *memmap; + int rc = 0; + + if (!ms->usage) { + usage = kzalloc(mem_section_usage_size(), GFP_KERNEL); + if (!usage) + return ERR_PTR(-ENOMEM); + ms->usage = usage; + } + + rc = fill_subsection_map(pfn, nr_pages); if (rc) { if (usage) ms->usage = NULL; From patchwork Thu Feb 20 04:33:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11393287 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B181B13A4 for ; Thu, 20 Feb 2020 04:33:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7E99624673 for ; Thu, 20 Feb 2020 04:33:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TZUU2Dt1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E99624673 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 B883C6B0008; Wed, 19 Feb 2020 23:33:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B38BF6B000A; Wed, 19 Feb 2020 23:33:52 -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 9D9866B000C; Wed, 19 Feb 2020 23:33:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 8521D6B0008 for ; Wed, 19 Feb 2020 23:33:52 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4B4DB824805A for ; Thu, 20 Feb 2020 04:33:52 +0000 (UTC) X-FDA: 76509237504.28.act76_21c8adbf21248 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:richardw.yang@linux.intel.com:david@redhat.com:osalvador@suse.de:dan.j.williams@intel.com:mhocko@suse.com:bhe@redhat.com:rppt@linux.ibm.com:robin.murphy@arm.com,RULES_HIT:30012:30034:30054,0,RBL:205.139.110.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: act76_21c8adbf21248 X-Filterd-Recvd-Size: 5145 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 04:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=qCQa83ebMhYRS+/RYU756BhqBknrzlZVZWgnaECEj/U=; b=TZUU2Dt1BZmzZs1nL9DuPjH5C9UdecsEHV7Rjx2E/v/+CkyULUYDXbwtuM9SvshD4S9FAM u9eE/1kXnKzhNy75Bh1nMpmbXV0mzvFblqwc4QyCmeXnFlHWDjasXq5gyAwFJTSlwTW79R dOgJmq3u1xczvFLDSHSCwSoNynQIlQk= 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-84-nQQ10umtMxqn1IHit_NLdA-1; Wed, 19 Feb 2020 23:33:47 -0500 X-MC-Unique: nQQ10umtMxqn1IHit_NLdA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 879F5801E6C; Thu, 20 Feb 2020 04:33:45 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id B84AE5DA60; Thu, 20 Feb 2020 04:33:38 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, richardw.yang@linux.intel.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, mhocko@suse.com, bhe@redhat.com, rppt@linux.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 3/7] mm/sparse.c: introduce a new function clear_subsection_map() Date: Thu, 20 Feb 2020 12:33:12 +0800 Message-Id: <20200220043316.19668-4-bhe@redhat.com> In-Reply-To: <20200220043316.19668-1-bhe@redhat.com> References: <20200220043316.19668-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: Wrap the codes which clear subsection map of one memory region from section_deactivate() into clear_subsection_map(). Signed-off-by: Baoquan He Reviewed-by: Wei Yang --- mm/sparse.c | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 977b47acd38d..df857ee9330c 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -726,14 +726,25 @@ static void free_map_bootmem(struct page *memmap) } #endif /* CONFIG_SPARSEMEM_VMEMMAP */ -static void section_deactivate(unsigned long pfn, unsigned long nr_pages, - struct vmem_altmap *altmap) +/** + * clear_subsection_map - Clear subsection map of one memory region + * + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This is only intended for hotplug, and clear the related subsection + * map inside one section. + * + * Return: + * * -EINVAL - Section already deactived. + * * 0 - Subsection map is emptied. + * * 1 - Subsection map is not empty. + */ +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) { DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 }; struct mem_section *ms = __pfn_to_section(pfn); - bool section_is_early = early_section(ms); - struct page *memmap = NULL; unsigned long *subsection_map = ms->usage ? &ms->usage->subsection_map[0] : NULL; @@ -744,8 +755,28 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, if (WARN(!subsection_map || !bitmap_equal(tmp, map, SUBSECTIONS_PER_SECTION), "section already deactivated (%#lx + %ld)\n", pfn, nr_pages)) - return; + return -EINVAL; + + bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); + if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) + return 0; + + return 1; +} + +static void section_deactivate(unsigned long pfn, unsigned long nr_pages, + struct vmem_altmap *altmap) +{ + struct mem_section *ms = __pfn_to_section(pfn); + bool section_is_early = early_section(ms); + struct page *memmap = NULL; + int rc; + + + rc = clear_subsection_map(pfn, nr_pages); + if (IS_ERR_VALUE((unsigned long)rc)) + return; /* * There are 3 cases to handle across two configurations * (SPARSEMEM_VMEMMAP={y,n}): @@ -763,8 +794,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, * * For 2/ and 3/ the SPARSEMEM_VMEMMAP={y,n} cases are unified */ - bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); - if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) { + if (!rc) { unsigned long section_nr = pfn_to_section_nr(pfn); /* @@ -786,7 +816,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, else depopulate_section_memmap(pfn, nr_pages, altmap); - if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) + if (!rc) ms->section_mem_map = (unsigned long)NULL; } From patchwork Thu Feb 20 04:33:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11393289 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D11013A4 for ; Thu, 20 Feb 2020 04:33:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F0C724670 for ; Thu, 20 Feb 2020 04:33:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HWjvIEQg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F0C724670 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 594826B000A; Wed, 19 Feb 2020 23:33:58 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 51DC06B000C; Wed, 19 Feb 2020 23:33:58 -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 40DF16B000D; Wed, 19 Feb 2020 23:33:58 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 293776B000A for ; Wed, 19 Feb 2020 23:33:58 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E993840E1 for ; Thu, 20 Feb 2020 04:33:57 +0000 (UTC) X-FDA: 76509237714.24.fowl09_2291a1157874d X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:richardw.yang@linux.intel.com:david@redhat.com:osalvador@suse.de:dan.j.williams@intel.com:mhocko@suse.com:bhe@redhat.com:rppt@linux.ibm.com:robin.murphy@arm.com,RULES_HIT:30012:30054,0,RBL:205.139.110.61:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: fowl09_2291a1157874d X-Filterd-Recvd-Size: 5070 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 04:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=oCBv2HOJLKiIgRMHMc/3eKQp7QmzN8xhrTm/x4TQ1YA=; b=HWjvIEQgMjCpMfpFK8o3//maEC5efxRmKLO9VAbriN8Kw/mB/BBbLPTfNzUVy6/qmtb4bh PrGTucH+1wH1gBPWF5ps/bxRRyueVxZ1ulPHtT/L9td4BKui4Wd4f9D8s5W/hbvcfiTxU9 QxH6d6vtCsOvpquALDI4h2OmIkbL3U8= 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-228-jGP_ygKmNh2_31R1tSC_YA-1; Wed, 19 Feb 2020 23:33:53 -0500 X-MC-Unique: jGP_ygKmNh2_31R1tSC_YA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B7A8800D53; Thu, 20 Feb 2020 04:33:51 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D86F5DA60; Thu, 20 Feb 2020 04:33:45 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, richardw.yang@linux.intel.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, mhocko@suse.com, bhe@redhat.com, rppt@linux.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 4/7] mm/sparse.c: only use subsection map in VMEMMAP case Date: Thu, 20 Feb 2020 12:33:13 +0800 Message-Id: <20200220043316.19668-5-bhe@redhat.com> In-Reply-To: <20200220043316.19668-1-bhe@redhat.com> References: <20200220043316.19668-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: Currently, subsection map is used when SPARSEMEM is enabled, including VMEMMAP case and !VMEMMAP case. However, subsection hotplug is not supported at all in SPARSEMEM|!VMEMMAP case, subsection map is unnecessary and misleading. Let's adjust code to only allow subsection map being used in VMEMMAP case. Signed-off-by: Baoquan He Reviewed-by: Wei Yang --- include/linux/mmzone.h | 2 ++ mm/sparse.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 462f6873905a..fc0de3a9a51e 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1185,7 +1185,9 @@ static inline unsigned long section_nr_to_pfn(unsigned long sec) #define SUBSECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SUBSECTION_MASK) struct mem_section_usage { +#ifdef CONFIG_SPARSEMEM_VMEMMAP DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION); +#endif /* See declaration of similar field in struct zone */ unsigned long pageblock_flags[0]; }; diff --git a/mm/sparse.c b/mm/sparse.c index df857ee9330c..66c497d6a229 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -209,6 +209,7 @@ static inline unsigned long first_present_section_nr(void) return next_present_section_nr(-1); } +#ifdef CONFIG_SPARSEMEM_VMEMMAP static void subsection_mask_set(unsigned long *map, unsigned long pfn, unsigned long nr_pages) { @@ -243,6 +244,11 @@ void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages) nr_pages -= pfns; } } +#else +void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages) +{ +} +#endif /* Record a memory area against a node. */ void __init memory_present(int nid, unsigned long start, unsigned long end) @@ -726,6 +732,7 @@ static void free_map_bootmem(struct page *memmap) } #endif /* CONFIG_SPARSEMEM_VMEMMAP */ +#ifdef CONFIG_SPARSEMEM_VMEMMAP /** * clear_subsection_map - Clear subsection map of one memory region * @@ -764,6 +771,12 @@ static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) return 1; } +#else +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + return 0; +} +#endif static void section_deactivate(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) @@ -820,6 +833,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, ms->section_mem_map = (unsigned long)NULL; } +#ifdef CONFIG_SPARSEMEM_VMEMMAP /** * fill_subsection_map - fill subsection map of a memory region * @pfn - start pfn of the memory range @@ -854,6 +868,12 @@ static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) return rc; } +#else +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + return 0; +} +#endif static struct page * __meminit section_activate(int nid, unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) From patchwork Thu Feb 20 04:33:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11393291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1009D13A4 for ; Thu, 20 Feb 2020 04:34:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D0C4C2467A for ; Thu, 20 Feb 2020 04:34:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Z4mSVyN8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0C4C2467A 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 E95F56B000C; Wed, 19 Feb 2020 23:34:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E22A66B000D; Wed, 19 Feb 2020 23:34:00 -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 C723B6B000E; Wed, 19 Feb 2020 23:34:00 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id ADCF86B000C for ; Wed, 19 Feb 2020 23:34:00 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6AA37824805A for ; Thu, 20 Feb 2020 04:34:00 +0000 (UTC) X-FDA: 76509237840.25.fear96_22f5e6d4a1713 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:richardw.yang@linux.intel.com:david@redhat.com:osalvador@suse.de:dan.j.williams@intel.com:mhocko@suse.com:bhe@redhat.com:rppt@linux.ibm.com:robin.murphy@arm.com,RULES_HIT:30012:30054:30074,0,RBL:205.139.110.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: fear96_22f5e6d4a1713 X-Filterd-Recvd-Size: 4992 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 04:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173239; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=9GUV7ZJmC2qQXzHNAmZVY0tFi2CtcIn1WjDc/UVGLOM=; b=Z4mSVyN8FZwomC0LHBRs9c2yHXR8tzwHW8qFcPUHJ64BjhZEcXTS120ZjeqF7wT80WN9zy VD63hL2l6M317k9AKu9R2gB6e/T6OmdrGmJJRxfntUDen/5MANJbE6kttvtW4WzAUe5kSu /HoT6V1oaKUNCM3tiyMGaQpAvgqFfXo= 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-118-spB0LoAhN9eMFmFDFL6hzA-1; Wed, 19 Feb 2020 23:33:57 -0500 X-MC-Unique: spB0LoAhN9eMFmFDFL6hzA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8CFBF801E5C; Thu, 20 Feb 2020 04:33:55 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 234A95DA60; Thu, 20 Feb 2020 04:33:51 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, richardw.yang@linux.intel.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, mhocko@suse.com, bhe@redhat.com, rppt@linux.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 5/7] mm/sparse.c: add code comment about sub-section hotplug Date: Thu, 20 Feb 2020 12:33:14 +0800 Message-Id: <20200220043316.19668-6-bhe@redhat.com> In-Reply-To: <20200220043316.19668-1-bhe@redhat.com> References: <20200220043316.19668-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: It's helpful to note that sub-section is only supported in SPARSEMEM_VMEMMAP case, but not in SPARSEMEM|!VMEMMAP case. Add sentences into the code comment above sparse_add_section. And also move the code comments from inside section_deactivate() to be above it. The code comments are reasonable to the whole function, and the moving makes code cleaner. Signed-off-by: Baoquan He --- mm/sparse.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 66c497d6a229..14bff0b44e7c 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -778,6 +778,22 @@ static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) } #endif +/* + * To deactivate a memory region, there are 3 cases to handle across + * two configurations (SPARSEMEM_VMEMMAP={y,n}): + * + * 1. deactivation of a partial hot-added section (only possible in + * the SPARSEMEM_VMEMMAP=y case). + * a) section was present at memory init + * b) section was hot-added post memory init + * 2. deactivation of a complete hot-added section. + * 3. deactivation of a complete section from memory init. + * + * For case 1, when subsection_map does not empty we will not be freeing + * the usage map, but still need to free the vmemmap range. + * + * For case 2 and 3, the SPARSEMEM_VMEMMAP={y,n} cases are unified. + */ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { @@ -790,23 +806,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, rc = clear_subsection_map(pfn, nr_pages); if(IS_ERR_VALUE((unsigned long)rc)) return; - /* - * There are 3 cases to handle across two configurations - * (SPARSEMEM_VMEMMAP={y,n}): - * - * 1/ deactivation of a partial hot-added section (only possible - * in the SPARSEMEM_VMEMMAP=y case). - * a/ section was present at memory init - * b/ section was hot-added post memory init - * 2/ deactivation of a complete hot-added section - * 3/ deactivation of a complete section from memory init - * - * For 1/, when subsection_map does not empty we will not be - * freeing the usage map, but still need to free the vmemmap - * range. - * - * For 2/ and 3/ the SPARSEMEM_VMEMMAP={y,n} cases are unified - */ + if (!rc) { unsigned long section_nr = pfn_to_section_nr(pfn); @@ -926,6 +926,11 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, * * This is only intended for hotplug. * + * Note that the added memory region is either section aligned, or + * sub-section aligned. The subsection hotplug is only supported in + * VMEMMAP case, please refer to ZONE_DEVICE part of memory-model.rst + * for more details. + * * Return: * * 0 - On success. * * -EEXIST - Section has been present. From patchwork Thu Feb 20 04:33:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11393293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11E6D14BC for ; Thu, 20 Feb 2020 04:34:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C474D2467B for ; Thu, 20 Feb 2020 04:34:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FANxa/uZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C474D2467B 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 E6E546B000D; Wed, 19 Feb 2020 23:34:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DF7C76B000E; Wed, 19 Feb 2020 23:34: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 CBF5D6B0010; Wed, 19 Feb 2020 23:34:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id B10A96B000D for ; Wed, 19 Feb 2020 23:34:06 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 90CE940D6 for ; Thu, 20 Feb 2020 04:34:06 +0000 (UTC) X-FDA: 76509238092.27.grape89_23d8b531f7007 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:richardw.yang@linux.intel.com:david@redhat.com:osalvador@suse.de:dan.j.williams@intel.com:mhocko@suse.com:bhe@redhat.com:rppt@linux.ibm.com:robin.murphy@arm.com,RULES_HIT:30012:30034:30054:30070,0,RBL:207.211.31.81:@redhat.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: grape89_23d8b531f7007 X-Filterd-Recvd-Size: 8264 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 04:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=ZsnXHCcrWo+gPrG0fF1fKC61Jtysuvlmbj43W1C5IdY=; b=FANxa/uZ+/FqO1Tq8nOqSz5Kk8UCYiKgEYrxPKf4lM0bW5uTYXu5nhbas0LLYz57oGqXFt w+Y7Klix5lIs+ay+ldsONU3xuDvBv852UV85tbazbOCOxhvvU9WZSQz3JY0MfoM+VgFSsl Vkd8wKiElgexvWVWnVmWSafOSUp+M2Q= 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-267-x6yvPR75PKGESqoFvpMkEA-1; Wed, 19 Feb 2020 23:34:02 -0500 X-MC-Unique: x6yvPR75PKGESqoFvpMkEA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C7F3107ACC4; Thu, 20 Feb 2020 04:33:59 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1241B5DA60; Thu, 20 Feb 2020 04:33:55 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, richardw.yang@linux.intel.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, mhocko@suse.com, bhe@redhat.com, rppt@linux.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 6/7] mm/sparse.c: move subsection_map related codes together Date: Thu, 20 Feb 2020 12:33:15 +0800 Message-Id: <20200220043316.19668-7-bhe@redhat.com> In-Reply-To: <20200220043316.19668-1-bhe@redhat.com> References: <20200220043316.19668-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: No functional change. Signed-off-by: Baoquan He --- mm/sparse.c | 172 +++++++++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 88 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 14bff0b44e7c..053d6c2e5c1f 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -244,10 +244,94 @@ void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages) nr_pages -= pfns; } } + +/** + * clear_subsection_map - Clear subsection map of one memory region + * + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This is only intended for hotplug, and clear the related subsection + * map inside one section. + * + * Return: + * * -EINVAL - Section already deactived. + * * 0 - Subsection map is emptied. + * * 1 - Subsection map is not empty. + */ +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; + DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 }; + struct mem_section *ms = __pfn_to_section(pfn); + unsigned long *subsection_map = ms->usage + ? &ms->usage->subsection_map[0] : NULL; + + subsection_mask_set(map, pfn, nr_pages); + if (subsection_map) + bitmap_and(tmp, map, subsection_map, SUBSECTIONS_PER_SECTION); + + if (WARN(!subsection_map || !bitmap_equal(tmp, map, SUBSECTIONS_PER_SECTION), + "section already deactivated (%#lx + %ld)\n", + pfn, nr_pages)) + return -EINVAL; + + bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); + + if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) + return 0; + + return 1; +} + +/** + * fill_subsection_map - fill subsection map of a memory region + * @pfn - start pfn of the memory range + * @nr_pages - number of pfns to add in the region + * + * This fills the related subsection map inside one section, and only + * intended for hotplug. + * + * Return: + * * 0 - On success. + * * -EINVAL - Invalid memory region. + * * -EEXIST - Subsection map has been set. + */ +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + struct mem_section *ms = __pfn_to_section(pfn); + DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; + unsigned long *subsection_map; + int rc = 0; + + subsection_mask_set(map, pfn, nr_pages); + + subsection_map = &ms->usage->subsection_map[0]; + + if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) + rc = -EINVAL; + else if (bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION)) + rc = -EEXIST; + else + bitmap_or(subsection_map, map, subsection_map, + SUBSECTIONS_PER_SECTION); + + return rc; +} #else void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages) { } + +static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + return 0; +} + +static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) +{ + return 0; +} #endif /* Record a memory area against a node. */ @@ -732,52 +816,6 @@ static void free_map_bootmem(struct page *memmap) } #endif /* CONFIG_SPARSEMEM_VMEMMAP */ -#ifdef CONFIG_SPARSEMEM_VMEMMAP -/** - * clear_subsection_map - Clear subsection map of one memory region - * - * @pfn - start pfn of the memory range - * @nr_pages - number of pfns to add in the region - * - * This is only intended for hotplug, and clear the related subsection - * map inside one section. - * - * Return: - * * -EINVAL - Section already deactived. - * * 0 - Subsection map is emptied. - * * 1 - Subsection map is not empty. - */ -static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) -{ - DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; - DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 }; - struct mem_section *ms = __pfn_to_section(pfn); - unsigned long *subsection_map = ms->usage - ? &ms->usage->subsection_map[0] : NULL; - - subsection_mask_set(map, pfn, nr_pages); - if (subsection_map) - bitmap_and(tmp, map, subsection_map, SUBSECTIONS_PER_SECTION); - - if (WARN(!subsection_map || !bitmap_equal(tmp, map, SUBSECTIONS_PER_SECTION), - "section already deactivated (%#lx + %ld)\n", - pfn, nr_pages)) - return -EINVAL; - - bitmap_xor(subsection_map, map, subsection_map, SUBSECTIONS_PER_SECTION); - - if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) - return 0; - - return 1; -} -#else -static int clear_subsection_map(unsigned long pfn, unsigned long nr_pages) -{ - return 0; -} -#endif - /* * To deactivate a memory region, there are 3 cases to handle across * two configurations (SPARSEMEM_VMEMMAP={y,n}): @@ -833,48 +871,6 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, ms->section_mem_map = (unsigned long)NULL; } -#ifdef CONFIG_SPARSEMEM_VMEMMAP -/** - * fill_subsection_map - fill subsection map of a memory region - * @pfn - start pfn of the memory range - * @nr_pages - number of pfns to add in the region - * - * This fills the related subsection map inside one section, and only - * intended for hotplug. - * - * Return: - * * 0 - On success. - * * -EINVAL - Invalid memory region. - * * -EEXIST - Subsection map has been set. - */ -static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) -{ - struct mem_section *ms = __pfn_to_section(pfn); - DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 }; - unsigned long *subsection_map; - int rc = 0; - - subsection_mask_set(map, pfn, nr_pages); - - subsection_map = &ms->usage->subsection_map[0]; - - if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) - rc = -EINVAL; - else if (bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION)) - rc = -EEXIST; - else - bitmap_or(subsection_map, map, subsection_map, - SUBSECTIONS_PER_SECTION); - - return rc; -} -#else -static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) -{ - return 0; -} -#endif - static struct page * __meminit section_activate(int nid, unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { From patchwork Thu Feb 20 04:33:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11393295 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B08DC13A4 for ; Thu, 20 Feb 2020 04:34:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 73E4724676 for ; Thu, 20 Feb 2020 04:34:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U+JjR+SR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73E4724676 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 AEB6C6B000E; Wed, 19 Feb 2020 23:34:17 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A75BE6B0010; Wed, 19 Feb 2020 23:34:17 -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 964376B0032; Wed, 19 Feb 2020 23:34:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 7FB466B000E for ; Wed, 19 Feb 2020 23:34:17 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 544E240D6 for ; Thu, 20 Feb 2020 04:34:17 +0000 (UTC) X-FDA: 76509238554.28.stick78_25662b78d522f X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:richardw.yang@linux.intel.com:david@redhat.com:osalvador@suse.de:dan.j.williams@intel.com:mhocko@suse.com:bhe@redhat.com:rppt@linux.ibm.com:robin.murphy@arm.com,RULES_HIT:30012:30054,0,RBL:207.211.31.81:@redhat.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: stick78_25662b78d522f X-Filterd-Recvd-Size: 3303 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 04:34:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=WBTkH8NFztz9hV99W9A9KyCR3kKGKSPFetvSYFlBOK4=; b=U+JjR+SRWurzsjjw2UUiGgelx1EiiI8apnj5j3hSlID18RJbNaCNBuH3XmLq1poDHT7X3I Kg+nuX0cN4ClAVbXCa69gSX/AGam7D6xUPPsIizDWIbYl/r0XKtMAoai4d1kIXFxv3eewx JiDOIDsa09FWyL1OZDiU/7nsi72gZEU= 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-251-9XzCVf-KMBCXGMKnWeEqWA-1; Wed, 19 Feb 2020 23:34:10 -0500 X-MC-Unique: 9XzCVf-KMBCXGMKnWeEqWA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C866800D53; Thu, 20 Feb 2020 04:34:08 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2356C5DA60; Thu, 20 Feb 2020 04:33:59 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, richardw.yang@linux.intel.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, mhocko@suse.com, bhe@redhat.com, rppt@linux.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 7/7] mm/sparse.c: Use __get_free_pages() instead in populate_section_memmap() Date: Thu, 20 Feb 2020 12:33:16 +0800 Message-Id: <20200220043316.19668-8-bhe@redhat.com> In-Reply-To: <20200220043316.19668-1-bhe@redhat.com> References: <20200220043316.19668-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: This removes the unnecessary goto, and simplify codes. Signed-off-by: Baoquan He Reviewed-by: Wei Yang --- mm/sparse.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 053d6c2e5c1f..572b71bd15aa 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -754,23 +754,19 @@ static void free_map_bootmem(struct page *memmap) struct page * __meminit populate_section_memmap(unsigned long pfn, unsigned long nr_pages, int nid, struct vmem_altmap *altmap) { - struct page *page, *ret; + struct page *ret; unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION; - page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size)); - if (page) - goto got_map_page; + ret = (void *)__get_free_pages(GFP_KERNEL|__GFP_NOWARN, + get_order(memmap_size)); + if (ret) + return ret; ret = vmalloc(memmap_size); if (ret) - goto got_map_ptr; + return ret; return NULL; -got_map_page: - ret = (struct page *)pfn_to_kaddr(page_to_pfn(page)); -got_map_ptr: - - return ret; } static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,