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.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 0350FFA372A for ; Wed, 16 Oct 2019 11:20:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB2D62067B for ; Wed, 16 Oct 2019 11:20:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB2D62067B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 558B98E0019; Wed, 16 Oct 2019 07:20:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 508D88E0001; Wed, 16 Oct 2019 07:20:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 448868E0019; Wed, 16 Oct 2019 07:20:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0100.hostedemail.com [216.40.44.100]) by kanga.kvack.org (Postfix) with ESMTP id 24A458E0001 for ; Wed, 16 Oct 2019 07:20:55 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 82554F96 for ; Wed, 16 Oct 2019 11:20:54 +0000 (UTC) X-FDA: 76049405628.04.farm47_7c474c039fd07 X-HE-Tag: farm47_7c474c039fd07 X-Filterd-Recvd-Size: 4832 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Oct 2019 11:20:53 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BF6F0B304; Wed, 16 Oct 2019 11:20:52 +0000 (UTC) Date: Wed, 16 Oct 2019 13:20:51 +0200 From: Michal Hocko To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Andrea Arcangeli , Andrew Morton , Vlastimil Babka , Oscar Salvador , Mel Gorman , Mike Rapoport , Dan Williams , Alexander Duyck , Pavel Tatashin , Alexander Potapenko Subject: Re: [PATCH RFC v3 4/9] mm: Export alloc_contig_range() / free_contig_range() Message-ID: <20191016112051.GW317@dhcp22.suse.cz> References: <20190919142228.5483-1-david@redhat.com> <20190919142228.5483-5-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190919142228.5483-5-david@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) 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 Thu 19-09-19 16:22:23, David Hildenbrand wrote: > A virtio-mem device wants to allocate memory from the memory region it > manages in order to unplug it in the hypervisor - similar to > a balloon driver. Also, it might want to plug previously unplugged > (allocated) memory and give it back to Linux. alloc_contig_range() / > free_contig_range() seem to be the perfect interface for this task. > > In contrast to existing balloon devices, a virtio-mem device operates > on bigger chunks (e.g., 4MB) and only on physical memory it manages. It > tracks which chunks (subblocks) are still plugged, so it can go ahead > and try to alloc_contig_range()+unplug them on unplug request, or > plug+free_contig_range() unplugged chunks on plug requests. > > A virtio-mem device will use alloc_contig_range() / free_contig_range() > only on ranges that belong to the same node/zone in at least > MAX(MAX_ORDER - 1, pageblock_order) order granularity - e.g., 4MB on > x86-64. The virtio-mem device added that memory, so the memory > exists and does not contain any holes. virtio-mem will only try to allocate > on ZONE_NORMAL, never on ZONE_MOVABLE, just like when allocating > gigantic pages (we don't put unmovable data into the movable zone). Is there any real reason to export as GPL rather than generic EXPORT_SYMBOL? In other words do we need to restrict the usage this interface only to GPL modules and why if so. All other allocator APIs are EXPORT_SYMBOL so there should better be a good reason for this one to differ. I can understand that this one is slightly different by requesting a specific range of the memory but it is still under a full control of the core MM to say no. > Cc: Andrew Morton > Cc: Michal Hocko > Cc: Vlastimil Babka > Cc: Oscar Salvador > Cc: Mel Gorman > Cc: Mike Rapoport > Cc: Dan Williams > Cc: Alexander Duyck > Cc: Pavel Tatashin > Cc: Alexander Potapenko > Signed-off-by: David Hildenbrand Other than that, I do not think exporting this function is harmful. It would be worse to reinvent it and do it wrong. I usually prefer to add a caller in the same patch, though, because it makes the usage explicit and clear. Acked-by: Michal Hocko # to export contig range allocator API > --- > mm/page_alloc.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3334a769eb91..d5d7944954b3 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -8469,6 +8469,7 @@ int alloc_contig_range(unsigned long start, unsigned long end, > pfn_max_align_up(end), migratetype); > return ret; > } > +EXPORT_SYMBOL_GPL(alloc_contig_range); > #endif /* CONFIG_CONTIG_ALLOC */ > > void free_contig_range(unsigned long pfn, unsigned int nr_pages) > @@ -8483,6 +8484,7 @@ void free_contig_range(unsigned long pfn, unsigned int nr_pages) > } > WARN(count != 0, "%d pages are still in use!\n", count); > } > +EXPORT_SYMBOL_GPL(free_contig_range); > > #ifdef CONFIG_MEMORY_HOTPLUG > /* > -- > 2.21.0 -- Michal Hocko SUSE Labs