mutex_lock(&vb->balloon_lock);
for (vb->num_pfns = 0; vb->num_pfns < num;
vb->num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
- page = balloon_page_dequeue(vb_dev_info);
+ page = balloon_page_dequeue(vb_dev_info, true);
if (!page)
break;
set_page_pfns(vb->pfns + vb->num_pfns, page);
};
extern struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info);
-extern struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info);
+extern struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info,
+ bool strict);
extern struct balloon_dev_info *balloon_devinfo_alloc(
void *balloon_dev_descriptor);
* balloon_page_dequeue - removes a page from balloon's page list and returns
* the its address to allow the driver release the page.
* @b_dev_info: balloon device decriptor where we will grab a page from.
+ * @strict: strictly bookkeep number of pages.
*
* Driver must call it to properly de-allocate a previous enlisted balloon page
* before definetively releasing it back to the guest system.
* This function returns the page address for the recently dequeued page or
* NULL in the case we find balloon's page list temporarily empty due to
- * compaction isolated pages.
+ * compaction isolated pages. If @strict is set to true and caller asks for
+ * more pages than we have, BUG().
*/
-struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info)
+struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info,
+ bool strict)
{
struct page *page, *tmp;
unsigned long flags;
*/
spin_lock_irqsave(&b_dev_info->pages_lock, flags);
if (unlikely(list_empty(&b_dev_info->pages) &&
- !b_dev_info->isolated_pages))
+ !b_dev_info->isolated_pages) && strict)
BUG();
spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
page = NULL;