From: Liang Li <liang.z.li@intel.com>
To: mst@redhat.com, linux-kernel@vger.kernel.org
Cc: ehabkost@redhat.com, kvm@vger.kernel.org, quintela@redhat.com,
Liang Li <liang.z.li@intel.com>,
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
Date: Thu, 3 Mar 2016 18:46:58 +0800 [thread overview]
Message-ID: <1457002019-15998-2-git-send-email-liang.z.li@intel.com> (raw)
In-Reply-To: <1457002019-15998-1-git-send-email-liang.z.li@intel.com>
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 <liang.z.li@intel.com>
---
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;
--
1.8.3.1
next prev parent reply other threads:[~2016-03-03 10:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-03 10:46 [Qemu-devel] [RFC kernel 0/2]A PV solution for KVM live migration optimization Liang Li
2016-03-03 10:46 ` Liang Li [this message]
2016-03-03 10:46 ` [Qemu-devel] [RFC kernel 2/2] virtio-balloon: extend balloon driver to support a new feature Liang Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457002019-15998-2-git-send-email-liang.z.li@intel.com \
--to=liang.z.li@intel.com \
--cc=akpm@linux-foundation.org \
--cc=amit.shah@redhat.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@twiddle.net \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).