ia64/xen-unstable

changeset 11761:be6f5e262d84

[BLK] back: Allocate pages for foreign mappings individually rather
than in one large contiguous region.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Oct 05 22:11:24 2006 +0100 (2006-10-05)
parents 79b56c02b836
children 0cda1a7988ee
files linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/include/xen/balloon.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Thu Oct 05 16:48:28 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Thu Oct 05 22:11:24 2006 +0100
     1.3 @@ -606,6 +606,17 @@ void balloon_dealloc_empty_page_range(
     1.4  	schedule_work(&balloon_worker);
     1.5  }
     1.6  
     1.7 +struct page *balloon_alloc_empty_page(void)
     1.8 +{
     1.9 +	return balloon_alloc_empty_page_range(1);
    1.10 +}
    1.11 +
    1.12 +void balloon_free_empty_page(
    1.13 +	struct page *page)
    1.14 +{
    1.15 +	balloon_dealloc_empty_page_range(page, 1);
    1.16 +}
    1.17 +
    1.18  void balloon_release_driver_page(struct page *page)
    1.19  {
    1.20  	unsigned long flags;
    1.21 @@ -621,6 +632,8 @@ void balloon_release_driver_page(struct 
    1.22  EXPORT_SYMBOL_GPL(balloon_update_driver_allowance);
    1.23  EXPORT_SYMBOL_GPL(balloon_alloc_empty_page_range);
    1.24  EXPORT_SYMBOL_GPL(balloon_dealloc_empty_page_range);
    1.25 +EXPORT_SYMBOL_GPL(balloon_alloc_empty_page);
    1.26 +EXPORT_SYMBOL_GPL(balloon_free_empty_page);
    1.27  EXPORT_SYMBOL_GPL(balloon_release_driver_page);
    1.28  
    1.29  MODULE_LICENSE("Dual BSD/GPL");
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Thu Oct 05 16:48:28 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Thu Oct 05 22:11:24 2006 +0100
     2.3 @@ -56,8 +56,6 @@ static int blkif_reqs = 64;
     2.4  module_param_named(reqs, blkif_reqs, int, 0);
     2.5  MODULE_PARM_DESC(reqs, "Number of blkback requests to allocate");
     2.6  
     2.7 -static int mmap_pages;
     2.8 -
     2.9  /* Run-time switchable: /sys/module/blkback/parameters/ */
    2.10  static unsigned int log_stats = 0;
    2.11  static unsigned int debug_lvl = 0;
    2.12 @@ -87,8 +85,7 @@ static DECLARE_WAIT_QUEUE_HEAD(pending_f
    2.13  
    2.14  #define BLKBACK_INVALID_HANDLE (~0)
    2.15  
    2.16 -static unsigned long mmap_vstart;
    2.17 -static unsigned long *pending_vaddrs;
    2.18 +static struct page **pending_pages;
    2.19  static grant_handle_t *pending_grant_handles;
    2.20  
    2.21  static inline int vaddr_pagenr(pending_req_t *req, int seg)
    2.22 @@ -98,7 +95,8 @@ static inline int vaddr_pagenr(pending_r
    2.23  
    2.24  static inline unsigned long vaddr(pending_req_t *req, int seg)
    2.25  {
    2.26 -	return pending_vaddrs[vaddr_pagenr(req, seg)];
    2.27 +	unsigned long pfn = page_to_pfn(pending_pages[vaddr_pagenr(req, seg)]);
    2.28 +	return (unsigned long)pfn_to_kaddr(pfn);
    2.29  }
    2.30  
    2.31  #define pending_handle(_req, _seg) \
    2.32 @@ -506,52 +504,50 @@ static void make_response(blkif_t *blkif
    2.33  
    2.34  static int __init blkif_init(void)
    2.35  {
    2.36 -	struct page *page;
    2.37 -	int i;
    2.38 +	int i, mmap_pages;
    2.39  
    2.40  	if (!is_running_on_xen())
    2.41  		return -ENODEV;
    2.42  
    2.43 -	mmap_pages            = blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
    2.44 -
    2.45 -	page = balloon_alloc_empty_page_range(mmap_pages);
    2.46 -	if (page == NULL)
    2.47 -		return -ENOMEM;
    2.48 -	mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    2.49 +	mmap_pages = blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
    2.50  
    2.51  	pending_reqs          = kmalloc(sizeof(pending_reqs[0]) *
    2.52  					blkif_reqs, GFP_KERNEL);
    2.53  	pending_grant_handles = kmalloc(sizeof(pending_grant_handles[0]) *
    2.54  					mmap_pages, GFP_KERNEL);
    2.55 -	pending_vaddrs        = kmalloc(sizeof(pending_vaddrs[0]) *
    2.56 +	pending_pages         = kmalloc(sizeof(pending_pages[0]) *
    2.57  					mmap_pages, GFP_KERNEL);
    2.58 -	if (!pending_reqs || !pending_grant_handles || !pending_vaddrs) {
    2.59 -		kfree(pending_reqs);
    2.60 -		kfree(pending_grant_handles);
    2.61 -		kfree(pending_vaddrs);
    2.62 -		printk("%s: out of memory\n", __FUNCTION__);
    2.63 -		return -ENOMEM;
    2.64 +	if (!pending_reqs || !pending_grant_handles || !pending_pages)
    2.65 +		goto out_of_memory;
    2.66 +
    2.67 +	for (i = 0; i < mmap_pages; i++) {
    2.68 +		pending_pages[i] = balloon_alloc_empty_page();
    2.69 +		if (pending_pages[i] == NULL) {
    2.70 +			while (--i >= 0)
    2.71 +				balloon_free_empty_page(pending_pages[i]);
    2.72 +			goto out_of_memory;
    2.73 +		}
    2.74 +		pending_grant_handles[i] = BLKBACK_INVALID_HANDLE;
    2.75  	}
    2.76  
    2.77  	blkif_interface_init();
    2.78 -	
    2.79 -	printk("%s: reqs=%d, pages=%d, mmap_vstart=0x%lx\n",
    2.80 -	       __FUNCTION__, blkif_reqs, mmap_pages, mmap_vstart);
    2.81 -	BUG_ON(mmap_vstart == 0);
    2.82 -	for (i = 0; i < mmap_pages; i++) {
    2.83 -		pending_vaddrs[i] = mmap_vstart + (i << PAGE_SHIFT);
    2.84 -		pending_grant_handles[i] = BLKBACK_INVALID_HANDLE;
    2.85 -	}
    2.86  
    2.87  	memset(pending_reqs, 0, sizeof(pending_reqs));
    2.88  	INIT_LIST_HEAD(&pending_free);
    2.89  
    2.90  	for (i = 0; i < blkif_reqs; i++)
    2.91  		list_add_tail(&pending_reqs[i].free_list, &pending_free);
    2.92 -    
    2.93 +
    2.94  	blkif_xenbus_init();
    2.95  
    2.96  	return 0;
    2.97 +
    2.98 + out_of_memory:
    2.99 +	kfree(pending_reqs);
   2.100 +	kfree(pending_grant_handles);
   2.101 +	kfree(pending_pages);
   2.102 +	printk("%s: out of memory\n", __FUNCTION__);
   2.103 +	return -ENOMEM;
   2.104  }
   2.105  
   2.106  module_init(blkif_init);
     3.1 --- a/linux-2.6-xen-sparse/include/xen/balloon.h	Thu Oct 05 16:48:28 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/include/xen/balloon.h	Thu Oct 05 22:11:24 2006 +0100
     3.3 @@ -38,23 +38,19 @@
     3.4   * Inform the balloon driver that it should allow some slop for device-driver
     3.5   * memory activities.
     3.6   */
     3.7 -void
     3.8 -balloon_update_driver_allowance(
     3.9 -	long delta);
    3.10 +void balloon_update_driver_allowance(long delta);
    3.11  
    3.12  /* Allocate an empty low-memory page range. */
    3.13 -struct page *
    3.14 -balloon_alloc_empty_page_range(
    3.15 -	unsigned long nr_pages);
    3.16 +struct page *balloon_alloc_empty_page_range(unsigned long nr_pages);
    3.17  
    3.18  /* Deallocate an empty page range, adding to the balloon. */
    3.19 -void
    3.20 -balloon_dealloc_empty_page_range(
    3.21 +void balloon_dealloc_empty_page_range(
    3.22  	struct page *page, unsigned long nr_pages);
    3.23  
    3.24 -void
    3.25 -balloon_release_driver_page(
    3.26 -	struct page *page);
    3.27 +struct page *balloon_alloc_empty_page(void);
    3.28 +void balloon_free_empty_page(struct page *page);
    3.29 +
    3.30 +void balloon_release_driver_page(struct page *page);
    3.31  
    3.32  /*
    3.33   * Prevent the balloon driver from changing the memory reservation during