From patchwork Sun Feb 9 10:48:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11372051 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 3809513A4 for ; Sun, 9 Feb 2020 10:48:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF9122080C for ; Sun, 9 Feb 2020 10:48:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jCTwpBB0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF9122080C 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 DF8006B000A; Sun, 9 Feb 2020 05:48:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D81426B000C; Sun, 9 Feb 2020 05:48:44 -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 BAB5C6B000D; Sun, 9 Feb 2020 05:48:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 9EA856B000A for ; Sun, 9 Feb 2020 05:48:44 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4919121EA for ; Sun, 9 Feb 2020 10:48:44 +0000 (UTC) X-FDA: 76470265368.05.fire48_2f0eb4899762e X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:dan.j.williams@intel.com:richardw.yang@linux.intel.com:david@redhat.com:bhe@redhat.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:24,LUA_SUMMARY:none X-HE-Tag: fire48_2f0eb4899762e X-Filterd-Recvd-Size: 4506 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Sun, 9 Feb 2020 10:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581245322; 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=jCTwpBB0lbPQpo0LwiLLrGnwcwej4hVApfF+fCULWnTQFTaqm8K2TKW+EUie5bJy3ZexfP 8W5VXmOQQH7Q1iS8Di2iU4QpjcrQSfnq2BXHlR6u+7vHraZK2puq4AO+vG627P/CKd5o51 nxLdNIcfCBHdh0kNCxmUOdANraLeA+o= 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 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 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;