From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2679AC352A3 for ; Tue, 11 Feb 2020 12:47:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C041520637 for ; Tue, 11 Feb 2020 12:47:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iWkhgOz7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C041520637 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 15D596B02C8; Tue, 11 Feb 2020 07:47:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10DF36B02C9; Tue, 11 Feb 2020 07:47:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F18516B02CA; Tue, 11 Feb 2020 07:46:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id D57876B02C8 for ; Tue, 11 Feb 2020 07:46:59 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 76BCC181AC553 for ; Tue, 11 Feb 2020 12:46:59 +0000 (UTC) X-FDA: 76477820958.17.home95_1fd50c4fe5063 X-HE-Tag: home95_1fd50c4fe5063 X-Filterd-Recvd-Size: 5860 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Tue, 11 Feb 2020 12:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581425218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/aoK1QXCzMorlswoGVCOoMeDkLwKz3AeoTqS+YSOfSw=; b=iWkhgOz7+jXcll//QRcXsDBNM1rxqnZ1Hl8CShw/4C9ARzUaY9C4dpqN3DjtMxVN8jTBpb yloZ7kyCnVUlluAMtGDQtDEVnaKOFr9FhgXNo3HgslrvCJ/H18AnCRCnh70E21/ZWwlIz9 m+0k/aN9GjU/C1x5YCR1T+drjy/DaXU= 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-214-SXnDScXhMiOTsLtNUoNaXQ-1; Tue, 11 Feb 2020 07:46:56 -0500 X-MC-Unique: SXnDScXhMiOTsLtNUoNaXQ-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 D097C477; Tue, 11 Feb 2020 12:46:54 +0000 (UTC) Received: from localhost (ovpn-12-50.pek2.redhat.com [10.72.12.50]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2754B5D9E2; Tue, 11 Feb 2020 12:46:51 +0000 (UTC) Date: Tue, 11 Feb 2020 20:46:48 +0800 From: Baoquan He To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, dan.j.williams@intel.com, richardw.yang@linux.intel.com Subject: Re: [PATCH 1/7] mm/sparse.c: Introduce new function fill_subsection_map() Message-ID: <20200211124648.GF8965@MiWiFi-R3L-srv> References: <20200209104826.3385-1-bhe@redhat.com> <20200209104826.3385-2-bhe@redhat.com> <0463a54b-12cb-667e-7c86-66cd707cec84@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0463a54b-12cb-667e-7c86-66cd707cec84@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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: On 02/10/20 at 10:49am, David Hildenbrand wrote: > On 09.02.20 11:48, Baoquan He wrote: > > 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; > > > > What about having two variants of > section_activate()/section_deactivate() instead? Then we don't have any > subsection related stuff in !subsection code. Thanks for looking into this, David. Having two variants of section_activate()/section_deactivate() is also good. Just not like memmap handling which is very different between classic sparse and vmemmap, makes having two variants very attractive, the code and logic in section_activate()/section_deactivate() is not too much, and both of them basically can share the most of code, these make the variants way not so necessary. I personally prefer the current way, what do you think? Thanks Baoquan