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=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 93A17C49ED7 for ; Thu, 19 Sep 2019 14:23:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5DEBA20882 for ; Thu, 19 Sep 2019 14:23:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DEBA20882 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 0C3FF6B0368; Thu, 19 Sep 2019 10:23:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 074D26B0369; Thu, 19 Sep 2019 10:23:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7DE86B036B; Thu, 19 Sep 2019 10:23:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id C07F16B0368 for ; Thu, 19 Sep 2019 10:23:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 70F62824376A for ; Thu, 19 Sep 2019 14:23:17 +0000 (UTC) X-FDA: 75951887634.24.crate19_91147e059695f X-HE-Tag: crate19_91147e059695f X-Filterd-Recvd-Size: 4226 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Sep 2019 14:23:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4B40C057F20; Thu, 19 Sep 2019 14:23:15 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0C6A60872; Thu, 19 Sep 2019 14:23:10 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Andrea Arcangeli , David Hildenbrand , Andrew Morton , Michal Hocko , Vlastimil Babka , Oscar Salvador , Mel Gorman , Mike Rapoport , Dan Williams , Alexander Duyck , Pavel Tatashin , Alexander Potapenko Subject: [PATCH RFC v3 4/9] mm: Export alloc_contig_range() / free_contig_range() Date: Thu, 19 Sep 2019 16:22:23 +0200 Message-Id: <20190919142228.5483-5-david@redhat.com> In-Reply-To: <20190919142228.5483-1-david@redhat.com> References: <20190919142228.5483-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 19 Sep 2019 14:23:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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: 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 alloca= te on ZONE_NORMAL, never on ZONE_MOVABLE, just like when allocating gigantic pages (we don't put unmovable data into the movable zone). 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 --- 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, unsigne= d long end, pfn_max_align_up(end), migratetype); return ret; } +EXPORT_SYMBOL_GPL(alloc_contig_range); #endif /* CONFIG_CONTIG_ALLOC */ =20 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 !=3D 0, "%d pages are still in use!\n", count); } +EXPORT_SYMBOL_GPL(free_contig_range); =20 #ifdef CONFIG_MEMORY_HOTPLUG /* --=20 2.21.0