Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp243782ybv; Wed, 19 Feb 2020 20:34:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxvaYOzvQXF88ArfiChwYE8j7f1tvqLF2ezWhja4bk7abkLQ5J5L6jTq4vEI+P4WW2p5Glu X-Received: by 2002:aca:2114:: with SMTP id 20mr786269oiz.9.1582173257116; Wed, 19 Feb 2020 20:34:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582173257; cv=none; d=google.com; s=arc-20160816; b=bTtzuS5K1kNtmvGOIuYo0MyWWhtoDpjZx5dsQaAp+lqMSHi+p8hnP8ODbH9C/wkRnX rbp+YPSGMqQ4x3rFNDVyZ22BEw3hNu/wDRMZIKtBvUvA2iPmasbskIGpdtS+h/xAbQe/ JfbIllM2ZM4XteCGddxK2s6BFDbmlpwdg11Qn4FT+bM47ZsjEjXrY/w9J0SS/WJxZK5N iItNuQ9bKMGOLqjICD8j6yyOdGVq69u7ja7tvsL3Iq4tpRnmyfHd5K1eXYW8zS2YBw1H sTGlIzt5+KEMBf3541S/hhF5kgSw5a/eSOGMGTAzkzFy8aI4E8IPJBjHFNOwdK/r+Ey7 uRRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=ekBaR/Uum+S2ojPBcrtCzTRvb9rStp58NNQZFSgK8iY=; b=GXvr+hfiiQ2gOj0AmXWyQwpObcZkdkF5oMtVeAPx/dvuwfEWzEgTUE0WlaVkiWe/xl sZlF/d005+ZBwe0LAniDQowzcmXm5dmVNd8S7NXRxZMqyMOqGngTWECvymPyJMJUndGb dJFAxCH9pRQwI4MItbVWR/B5oQA69HK8p7KsGoRV8QfM56Yeto0qRww+owsR2bgNYYQG LZjUOcWFi9RCyAiN90KJRi8KyaaLZlyUYQ30YCEdYL+0A35lvzyJCba6zkVZyW8C4IH8 826Dnx4DejpODVoPO8DxuccTPoOn52zGrdwy7o7kZ6lBity3kngmrz1WKeDpUvS0p6NM qniQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DXyBiygz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si1048076otl.82.2020.02.19.20.34.04; Wed, 19 Feb 2020 20:34:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DXyBiygz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728021AbgBTEdp (ORCPT + 99 others); Wed, 19 Feb 2020 23:33:45 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:53951 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727476AbgBTEdo (ORCPT ); Wed, 19 Feb 2020 23:33:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582173223; 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=DXyBiygzU8aX59iNwYRKxaEFpQtDhjWRv4u149SwYZXYmByJd4sw12No/+Y/HLbKxhZJHD hDGX8PbsyUelMV9SPAHC1zjGGRRUMpD44NE2NnfvaD8lZn1HVm5Ksj/VYIqSdpKx9741od gvRrtEsET1IJvdYerse+CeyQADY+aTs= 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.17.2