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.9 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 autolearn=unavailable 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 D3908C3F2D7 for ; Mon, 2 Mar 2020 13:51:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A922221739 for ; Mon, 2 Mar 2020 13:51:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e/7/QIWS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727299AbgCBNvy (ORCPT ); Mon, 2 Mar 2020 08:51:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57045 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726872AbgCBNvy (ORCPT ); Mon, 2 Mar 2020 08:51:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583157112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FiCQRZVKNip0tJQTjyPcrPcjQQToViBOoP7sm23P5rA=; b=e/7/QIWSACrQf4vjSmtHcqqR9aivAvGmLAvhZTTwUA7FqIW612sssjoxODciGFP8a0fZCN ttgkyv1oOl2+ujphbVa3NbSEhuYrTEqUrfkwszEal4tpQZXgX7WQTsciBWtzN3CJgWk+of OyV3xjsbkAHlJ21/Q51uBWChp6xJV8s= 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-12-kOprc3jJMlih9pd5-Echgw-1; Mon, 02 Mar 2020 08:51:48 -0500 X-MC-Unique: kOprc3jJMlih9pd5-Echgw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C8D713F7; Mon, 2 Mar 2020 13:51:46 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-114.ams2.redhat.com [10.36.116.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A09227183; Mon, 2 Mar 2020 13:51:27 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Michal Hocko , Vlastimil Babka , Oscar Salvador , Mel Gorman , Mike Rapoport , Dan Williams , Alexander Duyck , Pavel Tatashin , Alexander Potapenko Subject: [PATCH v1 04/11] mm: Export alloc_contig_range() / free_contig_range() Date: Mon, 2 Mar 2020 14:49:34 +0100 Message-Id: <20200302134941.315212-5-david@redhat.com> In-Reply-To: <20200302134941.315212-1-david@redhat.com> References: <20200302134941.315212-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Michal Hocko # to export contig range allocat= or API 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 79e950d76ffc..8d7be3f33e26 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8597,6 +8597,7 @@ int alloc_contig_range(unsigned long start, unsigne= d long end, pfn_max_align_up(end), migratetype); return ret; } +EXPORT_SYMBOL(alloc_contig_range); =20 static int __alloc_contig_pages(unsigned long start_pfn, unsigned long nr_pages, gfp_t gfp_mask) @@ -8712,6 +8713,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(free_contig_range); =20 /* * The zone indicated has a new number of managed_pages; batch sizes and= percpu --=20 2.24.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: virtio-dev-return-6857-cohuck=redhat.com@lists.oasis-open.org Sender: List-Post: List-Help: List-Unsubscribe: List-Subscribe: Received: from lists.oasis-open.org (oasis-open.org [10.110.1.242]) by lists.oasis-open.org (Postfix) with ESMTP id ABCEE985CDE for ; Mon, 2 Mar 2020 13:51:53 +0000 (UTC) From: David Hildenbrand Date: Mon, 2 Mar 2020 14:49:34 +0100 Message-Id: <20200302134941.315212-5-david@redhat.com> In-Reply-To: <20200302134941.315212-1-david@redhat.com> References: <20200302134941.315212-1-david@redhat.com> MIME-Version: 1.0 Subject: [virtio-dev] [PATCH v1 04/11] mm: Export alloc_contig_range() / free_contig_range() Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Michal Hocko , Vlastimil Babka , Oscar Salvador , Mel Gorman , Mike Rapoport , Dan Williams , Alexander Duyck , Pavel Tatashin , Alexander Potapenko 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 allocate 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 Acked-by: Michal Hocko # to export contig range allocator= API 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 79e950d76ffc..8d7be3f33e26 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8597,6 +8597,7 @@ int alloc_contig_range(unsigned long start, unsigned = long end, =09=09=09=09pfn_max_align_up(end), migratetype); =09return ret; } +EXPORT_SYMBOL(alloc_contig_range); =20 static int __alloc_contig_pages(unsigned long start_pfn, =09=09=09=09unsigned long nr_pages, gfp_t gfp_mask) @@ -8712,6 +8713,7 @@ void free_contig_range(unsigned long pfn, unsigned in= t nr_pages) =09} =09WARN(count !=3D 0, "%d pages are still in use!\n", count); } +EXPORT_SYMBOL(free_contig_range); =20 /* * The zone indicated has a new number of managed_pages; batch sizes and p= ercpu --=20 2.24.1 --------------------------------------------------------------------- To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org