Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2589157ybv; Sun, 9 Feb 2020 02:49:12 -0800 (PST) X-Google-Smtp-Source: APXvYqxxK4nGuIX+w67ZTxPnj2bdV39Xmy5BJpuscTM7kCsfVVdWjSkJC3u16SaXAhBmpN8PFyG5 X-Received: by 2002:aca:1a05:: with SMTP id a5mr7686769oia.97.1581245352055; Sun, 09 Feb 2020 02:49:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581245352; cv=none; d=google.com; s=arc-20160816; b=W0T5zOiP/8E0isCdi8iTiObiUcfXGaIMagxHO4VKX+O3WYKd9apSfA3vT/wWCG8ydS vwpnQ5J+ZQreWXbOPUGeWj5hshrdF/qM8qjm8Ag+bfT0BPRFBVZ9e6BRqVzZxyH216eI pYhseynj5ohP8bkyDbseVpVFRmnNjta4JHr1ncSLOt9/PgfVUlwaTAfRPyKzxYm6QC8W ck1nMxdw5sdoQS5B1TklpsV7yEpxToFaiumQfuDBrdtBbrSeqU41nQiqaMFG2bXt/YBL Ff9qS34LolPZxeEw1yIPr8kdGMCS5evtNrZfRKZjjBqqTLi0OKfFAza8GZLnwsBDCL9U ARtw== 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=mdBVxRpLdO0s6+uT+hO6BEgqaFn2MQXMmuMNW77AADU=; b=L2IPbVA+PN7LK6MJ3OnnE6vHV4PCKCHnYESYJ1JJ9fXJYtBrDP6lp0CR46JbWEnC2B r7+PYOYOYrMIW44QSm1P4Eh5ZqdqpGgLCCChEPpJO/ACpZBf6qcPkbu8yZPWtGPEA+G9 crUc9JnuWDLFQjaiy6EvFzOPuEZozfNSV3jIrUTprHvdAek+82IfW9opqizPFx6opBeU n/5twuUxqMcyfTR64lpvC2FnFo1SBXtq2bMaoXLXc9LIF5+Cu2HeRw/cl2DON15Gc5uW uN+d8oPVrS8ZLzBEelvfmnG8OnrdjRFLRHKEPKKsbum5RFMxea4iX8S8PVFWYd7lvlcp wVVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WtdM5CaA; 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 n2si2870190otq.315.2020.02.09.02.48.55; Sun, 09 Feb 2020 02:49:12 -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=WtdM5CaA; 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 S1727678AbgBIKsm (ORCPT + 99 others); Sun, 9 Feb 2020 05:48:42 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37104 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726081AbgBIKsm (ORCPT ); Sun, 9 Feb 2020 05:48:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245320; 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=mdBVxRpLdO0s6+uT+hO6BEgqaFn2MQXMmuMNW77AADU=; b=WtdM5CaAdlF0PtGuHbuIb3PWcSIuiHRBMRrmVHx6GUHorKB4WqwDT6opV4Dxd8qDDbysJb oAp9aLAz9U3BUnCQ+247i5y8oQb7gjwLfMUL4ehzjHtz8SNuTdaCGCP8cFNQu5EEg5rgzg I7mPhgIh3p+aQKNFm8y1Jc+7yCZ+OnY= 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-369-QKsqChD3ODO-MNUh75hE4A-1; Sun, 09 Feb 2020 05:48:37 -0500 X-MC-Unique: QKsqChD3ODO-MNUh75hE4A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D09613E5; Sun, 9 Feb 2020 10:48:36 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id A40B610013A7; Sun, 9 Feb 2020 10:48:33 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com, david@redhat.com, bhe@redhat.com Subject: [PATCH 1/7] mm/sparse.c: Introduce new function fill_subsection_map() Date: Sun, 9 Feb 2020 18:48:20 +0800 Message-Id: <20200209104826.3385-2-bhe@redhat.com> In-Reply-To: <20200209104826.3385-1-bhe@redhat.com> References: <20200209104826.3385-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 in 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 c184b69460b7..9ad741ccbeb6 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -788,24 +788,28 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, depopulate_section_memmap(pfn, nr_pages, altmap); } -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 clears 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)) @@ -816,6 +820,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