From patchwork Thu Mar 3 10:46:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 591389 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6DC8714017E for ; Thu, 3 Mar 2016 21:54:43 +1100 (AEDT) Received: from localhost ([::1]:33830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abQu1-0006WK-L3 for incoming@patchwork.ozlabs.org; Thu, 03 Mar 2016 05:54:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abQsf-0004CQ-RN for qemu-devel@nongnu.org; Thu, 03 Mar 2016 05:53:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abQsc-0007Z5-Ju for qemu-devel@nongnu.org; Thu, 03 Mar 2016 05:53:17 -0500 Received: from mga04.intel.com ([192.55.52.120]:45476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abQsc-0007Yv-EB for qemu-devel@nongnu.org; Thu, 03 Mar 2016 05:53:14 -0500 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 03 Mar 2016 02:53:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,532,1449561600"; d="scan'208";a="59026876" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by fmsmga004.fm.intel.com with ESMTP; 03 Mar 2016 02:53:11 -0800 From: Liang Li To: mst@redhat.com, linux-kernel@vger.kernel.org Date: Thu, 3 Mar 2016 18:46:58 +0800 Message-Id: <1457002019-15998-2-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457002019-15998-1-git-send-email-liang.z.li@intel.com> References: <1457002019-15998-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Cc: ehabkost@redhat.com, kvm@vger.kernel.org, quintela@redhat.com, Liang Li , qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, amit.shah@redhat.com, pbonzini@redhat.com, akpm@linux-foundation.org, dgilbert@redhat.com, rth@twiddle.net Subject: [Qemu-devel] [RFC kernel 1/2] mm: Add the functions used to get free pages information X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org get_total_pages_count() tries to get the page count of the system RAM. get_free_pages() is intend to construct a free pages bitmap by traversing the free_list. The free pages information will be sent to QEMU through virtio and used for live migration optimization. Signed-off-by: Liang Li --- mm/page_alloc.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 838ca8bb..81922e6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3860,6 +3860,63 @@ void show_free_areas(unsigned int filter) show_swap_cache_info(); } +#define PFN_4G (0x100000000 >> PAGE_SHIFT) + +unsigned long get_total_pages_count(unsigned long low_mem) +{ + if (max_pfn >= PFN_4G) { + unsigned long pfn_gap = PFN_4G - (low_mem >> PAGE_SHIFT); + + return max_pfn - pfn_gap; + } else + return max_pfn; +} +EXPORT_SYMBOL(get_total_pages_count); + +static void mark_free_pages_bitmap(struct zone *zone, + unsigned long *free_page_bitmap, unsigned long pfn_gap) +{ + unsigned long pfn, flags, i; + unsigned int order, t; + struct list_head *curr; + + if (zone_is_empty(zone)) + return; + + spin_lock_irqsave(&zone->lock, flags); + + for_each_migratetype_order(order, t) { + list_for_each(curr, &zone->free_area[order].free_list[t]) { + + pfn = page_to_pfn(list_entry(curr, struct page, lru)); + for (i = 0; i < (1UL << order); i++) { + if ((pfn + i) >= PFN_4G) + set_bit_le(pfn + i - pfn_gap, + free_page_bitmap); + else + set_bit_le(pfn + i, free_page_bitmap); + } + } + } + + spin_unlock_irqrestore(&zone->lock, flags); +} + +void get_free_pages(unsigned long *free_page_bitmap, + unsigned long *free_pages_count, + unsigned long low_mem) +{ + struct zone *zone; + unsigned long pfn_gap; + + pfn_gap = PFN_4G - (low_mem >> PAGE_SHIFT); + for_each_populated_zone(zone) + mark_free_pages_bitmap(zone, free_page_bitmap, pfn_gap); + + *free_pages_count = global_page_state(NR_FREE_PAGES); +} +EXPORT_SYMBOL(get_free_pages); + static void zoneref_set_zone(struct zone *zone, struct zoneref *zoneref) { zoneref->zone = zone;