Add multi-page shared ring support to xen-blkfront/back
Subsystems (3)
These patches add support for multi-page shared rings to xen-blkfront/back. Shared rings must always be a power of 2 in size and so the size is controlled by the new 'max_ring_page_order' module parameter of xen-blkback. This defaults to 0 so operationally there should be no difference with these patches in place. The maximum value of 'max_ring_page_order' is currently limited to 2 (i.e. 4 pages).
xen-blkfront will always use the largest shared ring size supported by the back end. To override this and continue to use a single page ring, as before, set the 'allow_multi_page_ring' module parameter to 0.
PATCH 1/2 Add multi-page ring support to xen-blkback.
--- drivers/xen/blkback/common.h | 10 +++- drivers/xen/blkback/interface.c | 113 +++++++++++++++++++++++++++----------- drivers/xen/blkback/xenbus.c | 100 ++++++++++++++++++++++++++++++----- 3 files changed, 174 insertions(+), 49 deletions(-)
drivers/xen/blkback/common.h +7 -3
@@ -58,6 +58,9 @@ struct vbd {struct backend_info ; +#define BLKIF_MAX_RING_PAGE_ORDER 2 +#define BLKIF_MAX_RING_PAGES (1<<BLKIF_MAX_RING_PAGE_ORDER) + typedef struct blkif_st { /* Unique identifier for this interface. */ domid_t domid;
@@ -92,14 +95,15 @@ typedef struct blkif_st {wait_queue_head_t waiting_to_free; -grant_handle_t shmem_handle; -grant_ref_t shmem_ref; +unsigned int nr_shared_pages; +grant_handle_t shmem_handle[BLKIF_MAX_RING_PAGES ]; } blkif_t;blkif_t *blkif_alloc (domid_t domid);void blkif_disconnect (blkif_t *blkif);void blkif_free (blkif_t *blkif); -int blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn); +int blkif_map (blkif_t *blkif,unsigned long shared_pages[], +unsigned int nr_shared_pages,unsigned int evtchn);#define blkif_get (_b) (atomic_inc(&(_b)->refcnt))#define blkif_put (_b) \
drivers/xen/blkback/interface.c +80 -33
173 lines not on this page · raw message
drivers/xen/blkback/xenbus.c +87 -13
144 lines not on this page · raw message
Signature · 1 line
1.5.6.5
PATCH 2/2 Add multi-page ring support to xen-blkfront
--- drivers/block/xen-blkfront.c | 137 ++++++++++++++++++++++++++++++++---------- 1 files changed, 105 insertions(+), 32 deletions(-)
drivers/block/xen-blkfront.c +105 -32
@@ -67,7 +67,25 @@ struct blk_shadow {static struct block_device_operations xlvbd_block_fops; -#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE) +#define BLK_RING_SIZE (_order) \ + __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE<<(_order)) + +#define BLKIF_MAX_RING_PAGE_ORDER 2 +#define MAX_BLK_RING_SIZE BLK_RING_SIZE(BLKIF_MAX_RING_PAGE_ORDER) + +#define BLKIF_MAX_RING_PAGES (1<<BLKIF_MAX_RING_PAGE_ORDER) + +/* +* Allow multi page shared ring to be used if the capability is advertised by +* the back end. +*/ +static int allow_multi_page_ring =1 ; +module_param_named (allow_multi_page_ring, + allow_multi_page_ring, + int, +0 ); +MODULE_PARM_DESC (allow_multi_page_ring, +"Allow multi page shared ring to be used" );/* * We have one of these per vbd, whether ide, scsi or 'other'. They
@@ -81,14 +99,15 @@ struct blkfront_infoint vdevice;blkif_vdev_t handle;enum blkif_state connected; -int ring_ref; +int ring_ref[BLKIF_MAX_RING_PAGES ]; +int ring_order;struct blkif_front_ring ring;struct scatterlist sg[BLKIF_MAX_SEGMENTS_PER_REQUEST ];unsigned int evtchn, irq;struct request_queue *rq;struct work_struct work;struct gnttab_free_callback callback; -struct blk_shadow shadow[BLK_RING_SIZE ]; +struct blk_shadow shadow[MAX_BLK_RING_SIZE ];unsigned long shadow_free;int feature_barrier;int is_ready;
@@ -102,8 +121,6 @@ struct blkfront_infostatic DEFINE_SPINLOCK (blkif_io_lock); -#define MAXIMUM_OUTSTANDING_BLOCK_REQS \ - (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE)#define GRANT_INVALID_REF 0#define PARTS_PER_DISK 16
@@ -122,7 +139,7 @@ static DEFINE_SPINLOCK(blkif_io_lock);static int get_id_from_freelist (struct blkfront_info *info) {unsigned long free = info->shadow_free; -BUG_ON (free >=BLK_RING_SIZE ); +BUG_ON (free >=MAX_BLK_RING_SIZE ); info->shadow_free = info->shadow[free].req.id; info->shadow[free].req.id =0x0fffffee ;/* debug */ return free;
@@ -495,6 +512,9 @@ static void blkif_restart_queue(struct work_struct *work)static void blkif_free (struct blkfront_info *info,int suspend) { +int i; +unsigned long sring = (unsigned long )info->ring.sring; +/* Prevent new requests being issued until we fix things up. */ spin_lock_irq (&blkif_io_lock); info->connected = suspend ?
@@ -510,12 +530,14 @@ static void blkif_free(struct blkfront_info *info, int suspend)flush_scheduled_work ();/* Free resources associated with old device channel. */ -if (info->ring_ref !=GRANT_INVALID_REF ) { -gnttab_end_foreign_access (info->ring_ref,0 , - (unsigned long )info->ring.sring); - info->ring_ref =GRANT_INVALID_REF ; - info->ring.sring =NULL ; +for (i =0 ; i < (1 <<info->ring_order); i++) { +if (info->ring_ref[i] !=GRANT_INVALID_REF ) { +gnttab_end_foreign_access (info->ring_ref[i],0 , + sring + (i<<PAGE_SHIFT )); + info->ring_ref[i] =GRANT_INVALID_REF ; + } } + info->ring.sring =NULL ;if (info->irq)unbind_from_irqhandler (info->irq, info); info->evtchn = info->irq =0 ;
@@ -605,28 +627,35 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)static int setup_blkring (struct xenbus_device *dev,struct blkfront_info *info) { -struct blkif_sring *sring; +int i; +unsigned long sring;int err; - info->ring_ref =GRANT_INVALID_REF ; +for (i =0 ; i < (1 <<info->ring_order); i++) + info->ring_ref[i] =GRANT_INVALID_REF ; - sring = (struct blkif_sring *)__get_free_page (GFP_NOIO | __GFP_HIGH); + sring =__get_free_pages (GFP_NOIO | __GFP_HIGH, info->ring_order);if (!sring) {xenbus_dev_fatal (dev, -ENOMEM ,"allocating shared ring" );return -ENOMEM ; } -SHARED_RING_INIT (sring); -FRONT_RING_INIT (&info->ring, sring,PAGE_SIZE ); +SHARED_RING_INIT ((struct blkif_sring *)sring); +FRONT_RING_INIT (&info->ring, (struct blkif_sring *)sring, +PAGE_SIZE <<info->ring_order);sg_init_table (info->sg,BLKIF_MAX_SEGMENTS_PER_REQUEST ); - err =xenbus_grant_ring (dev,virt_to_mfn (info->ring.sring)); -if (err <0 ) { -free_page ((unsigned long )sring); - info->ring.sring =NULL ; - goto fail; +for (i =0 ; i < (1 <<info->ring_order); i++) { +unsigned long addr = sring + (i<<PAGE_SHIFT ); + + err =xenbus_grant_ring (dev,virt_to_mfn (addr)); +if (err <0 ) { +free_pages (sring, info->ring_order); + info->ring.sring =NULL ; + goto fail; + } + info->ring_ref[i] = err; } - info->ring_ref = err; err =xenbus_alloc_evtchn (dev, &info->evtchn);if (err)
@@ -648,6 +677,9 @@ fail:return err; } +#ifndef MIN +#define MIN (a, b) (((a) < (b)) ? (a) : (b)) +#endif /* Common code used when first setting up, and when resuming. */ static int talk_to_blkback(struct xenbus_device *dev,
@@ -655,8 +687,24 @@ static int talk_to_blkback(struct xenbus_device *dev, {const char *message =NULL ;struct xenbus_transaction xbt; +int ring_order; +int single_page;int err; + err =xenbus_gather (XBT_NIL , info->xbdev->otherend, +"max-ring-page-order" ,"%u" , &ring_order, +NULL ); +if (err || !allow_multi_page_ring) { + single_page =1 ; + info->ring_order =0 ; +dev_dbg (&dev->dev,"using single-page handshake\n" ); + }else { + single_page =0 ; + info->ring_order =MIN (ring_order,BLKIF_MAX_RING_PAGE_ORDER ); +dev_dbg (&dev->dev,"using multi-page handshake (%d pages)\n" , + (1 <<info->ring_order)); + } +/* Create shared ring, alloc event channel. */ err =setup_blkring (dev, info);if (err)
@@ -669,18 +717,43 @@ again: goto destroy_blkring; } - err =xenbus_printf (xbt, dev->nodename, -"ring-ref" ,"%u" , info->ring_ref); -if (err) { - message ="writing ring-ref" ; - goto abort_transaction; +if (single_page) { + err =xenbus_printf (xbt, dev->nodename, +"ring-ref" ,"%u" , info->ring_ref[0 ]); +if (err) { + message ="writing ring-ref" ; + goto abort_transaction; + } + }else { +int i; + + err =xenbus_printf (xbt, dev->nodename, +"ring-page-order" ,"%u" , info->ring_order); +if (err) { + message ="writing ring-page-order" ; + goto abort_transaction; + } + +for (i =0 ; i < (1 <<info->ring_order); i++) { +char node[10 ]; + +snprintf (node,sizeof (node),"ring-ref%u" , i); + err =xenbus_printf (xbt, dev->nodename, node,"%u" , + info->ring_ref[i]); +if (err) { + message ="writing ring-ref" ; + goto abort_transaction; + } + } } + err =xenbus_printf (xbt, dev->nodename,"event-channel" ,"%u" , info->evtchn);if (err) { message ="writing event-channel" ; goto abort_transaction; } + err =xenbus_printf (xbt, dev->nodename,"protocol" ,"%s" ,XEN_IO_PROTO_ABI_NATIVE );if (err) {
@@ -747,9 +820,9 @@ static int blkfront_probe(struct xenbus_device *dev, info->connected =BLKIF_STATE_DISCONNECTED ;INIT_WORK (&info->work, blkif_restart_queue); -for (i =0 ; i <BLK_RING_SIZE ; i++) +for (i =0 ; i <MAX_BLK_RING_SIZE ; i++) info->shadow[i].req.id = i+1 ; - info->shadow[BLK_RING_SIZE -1 ].req.id =0x0fffffff ; + info->shadow[MAX_BLK_RING_SIZE -1 ].req.id =0x0fffffff ;/* Front end dir is a number, which is used as the id. */ info->handle =simple_strtoul (strrchr (dev->nodename,'/' )+1 ,NULL ,0 );
@@ -782,13 +855,13 @@ static int blkif_recover(struct blkfront_info *info)/* Stage 2: Set up free list. */ memset (&info->shadow,0 ,sizeof (info->shadow)); -for (i =0 ; i <BLK_RING_SIZE ; i++) +for (i =0 ; i <MAX_BLK_RING_SIZE ; i++) info->shadow[i].req.id = i+1 ; info->shadow_free = info->ring.req_prod_pvt; - info->shadow[BLK_RING_SIZE -1 ].req.id =0x0fffffff ; + info->shadow[MAX_BLK_RING_SIZE -1 ].req.id =0x0fffffff ;/* Stage 3: Find pending requests and requeue them. */ -for (i =0 ; i <BLK_RING_SIZE ; i++) { +for (i =0 ; i <MAX_BLK_RING_SIZE ; i++) {/* Not in use? */ if (copy[i].request ==0 )continue ;
Signature · 1 line
1.5.6.5
Quoted 10 lines · Paul Durrant
These patches add support for multi-page shared rings to xen-blkfront/back. Shared rings must always be a power of 2 in size and so the size is controlled by the new '
max_ring_page_order' module parameter of xen-blkback. This defaults to 0 so operationally there should be no difference with these patches in place. The maximum value of 'max_ring_page_order' is currently limited to 2 (i.e. 4 pages).
xen-blkfront will always use the largest shared ring size supported by the back end. To override this and continue to use a single page ring, as before, set the 'allow_multi_page_ring' module parameter to 0.
I don't know why git-send-email seems to have sent my patch series into a black hole. Here they are as attachments this time.
Paul
Signature · 10 lines
=============================== Paul Durrant, Software Engineer Citrix Systems (R&D) Ltd. First Floor, Building 101 Cambridge Science Park Milton Road Cambridge CB4 0FY United Kingdom ===============================
Quoted 1 line
From
6aea96d968f885fcdd252a17577a71b1742fac68Mon Sep 17 00:00:00 2001
From: Paul Durrant <[email protected]>
Date: Tue, 12 Jan 2010 17:25:25 +0000
Subject: [PATCH 1/2] Add multi-page ring support to xen-blkback.
--- drivers/xen/blkback/common.h | 10 +++- drivers/xen/blkback/interface.c | 113 +++++++++++++++++++++++++++----------- drivers/xen/blkback/xenbus.c | 100 ++++++++++++++++++++++++++++++----- 3 files changed, 174 insertions(+), 49 deletions(-)
drivers/xen/blkback/common.h +7 -3
@@ -58,6 +58,9 @@ struct vbd {struct backend_info ; +#define BLKIF_MAX_RING_PAGE_ORDER 2 +#define BLKIF_MAX_RING_PAGES (1<<BLKIF_MAX_RING_PAGE_ORDER) + typedef struct blkif_st { /* Unique identifier for this interface. */ domid_t domid;
@@ -92,14 +95,15 @@ typedef struct blkif_st {wait_queue_head_t waiting_to_free; -grant_handle_t shmem_handle; -grant_ref_t shmem_ref; +unsigned int nr_shared_pages; +grant_handle_t shmem_handle[BLKIF_MAX_RING_PAGES ]; } blkif_t;blkif_t *blkif_alloc (domid_t domid);void blkif_disconnect (blkif_t *blkif);void blkif_free (blkif_t *blkif); -int blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn); +int blkif_map (blkif_t *blkif,unsigned long shared_pages[], +unsigned int nr_shared_pages,unsigned int evtchn);#define blkif_get (_b) (atomic_inc(&(_b)->refcnt))#define blkif_put (_b) \
drivers/xen/blkback/interface.c +80 -33
173 lines not on this page · raw message
drivers/xen/blkback/xenbus.c +87 -13
144 lines not on this page · raw message
Signature · 1 line
1.5.6.5
Quoted 1 line
From
fe4d68a612ae740cef39ae0e3ce714c40e375cb9Mon Sep 17 00:00:00 2001
From: Paul Durrant <[email protected]>
Date: Tue, 12 Jan 2010 17:32:36 +0000
Subject: [PATCH 2/2] Add multi-page ring support to xen-blkfront
--- drivers/block/xen-blkfront.c | 137 ++++++++++++++++++++++++++++++++---------- 1 files changed, 105 insertions(+), 32 deletions(-)
drivers/block/xen-blkfront.c +105 -32
241 lines not on this page · raw message
Signature · 1 line
1.5.6.5
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
RE: Add multi-page shared ring support toxen-blkfront/back
Quoted 3 lines
Quoted 1 line · Paul Durrant
These patches add support for multi-page shared rings to
xen-blkfront/back.
Quoted 3 lines
Quoted 1 line
Shared rings must always be a power of 2 in size and so the size is
controlled
Quoted 1 line
by the new '
max_ring_page_order' module parameter of xen-blkback.
This
Quoted 2 lines
defaults
Quoted 1 line
to 0 so operationally there should be no difference with these
patches in
Quoted 4 lines
place.
Quoted 3 lines
The maximum value of '
max_ring_page_order' is currently limited to 2 (i.e. 4 pages).
xen-blkfront will always use the largest shared ring size supported
by the
Quoted 2 lines
back
Quoted 1 line
end. To override this and continue to use a single page ring, as
before, set
Quoted 5 lines
the
Quoted 2 lines
'
allow_multi_page_ring' module parameter to 0.I don't know why git-send-email seems to have sent my patch series
into
Quoted 2 lines
a black hole. Here they are as attachments this time.
I received the 1/2 and 2/2 emails containing the patches.
Is there any measurable performance increase with this update? I assume it means that you can have more read/write operations on the ring at once? What would be useful to me is larger read/write operations...
James
RE: Add multi-page shared ring support toxen-blkfront/back
Quoted 5 lines · James Harper
I received the 1/2 and 2/2 emails containing the patches.
Is there any measurable performance increase with this update? I assume it means that you can have more read/write operations on the ring at once? What would be useful to me is larger read/write operations...
Interesting. Why? Asking because ring space is spent on segments, not request headers. Do you see a notable difference somewhere, compared to a bunch of (virtually) consecutive request ranges? Or rather a convenience thing for the gpl PV drivers?
Cheers,
Daniel
RE: Add multi-page shared ring support toxen-blkfront/back
Quoted 14 lines · James Harper
Quoted 6 lines
I received the 1/2 and 2/2 emails containing the patches.
Is there any measurable performance increase with this update? I assume it means that you can have more read/write operations on the ring at once? What would be useful to me is larger read/write operations...
Interesting. Why? Asking because ring space is spent on segments, not request headers. Do you see a notable difference somewhere, compared to a bunch of (virtually) consecutive request ranges? Or rather a convenience thing for the gpl PV drivers?
Windows has a limit to the number of outstanding requests that it will issue. It is as low as 16 under some versions of their scsiport infrastructure. I think storport relaxes those limits a bit but I haven't gotten as far as a storport driver yet.
So larger requests would probably benefit windows more than more requests would.
It would be nice if the ring slots could be dynamic in size. Major rewrite of everything of course, but we'd get the best of both worlds.
James
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Haven't read the patch carefully, but a question:
Will blkback fall back safely to single-page allocation if fragmentation has occurred... and, if so, will this inability to allocate multi-page be dynamically propogated to blkfronts (rather than just the largest ring size "supported" by blkback)?
Quoted 44 lines
-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: Tuesday, January 12, 2010 10:52 AM
To: [email protected]
Subject: Re: [Xen-devel] Add multi-page shared ring support to xen-blkfront/backQuoted 1 line · Paul Durrant
These patches add support for multi-page shared rings to
xen-blkfront/back.
Quoted 1 line
Shared rings must always be a power of 2 in size and so the
size is controlled
Quoted 1 line
by the new '
max_ring_page_order' module parameter ofxen-blkback. This defaults
Quoted 1 line
to 0 so operationally there should be no difference with
these patches in place.
Quoted 3 lines
The maximum value of '
max_ring_page_order' is currently limited to 2 (i.e. 4 pages).
xen-blkfront will always use the largest shared ring sizesupported by the back
Quoted 1 line
end. To override this and continue to use a single page
ring, as before, set the
Quoted 2 lines
'
allow_multi_page_ring' module parameter to 0.I don't know why git-send-email seems to have sent my patch series into
a black hole. Here they are as attachments this time.Paul
Signature · 10 lines
=============================== Paul Durrant, Software Engineer Citrix Systems (R&D) Ltd. First Floor, Building 101 Cambridge Science Park Milton Road Cambridge CB4 0FY United Kingdom ===============================
Quoted 10 lines · Paul Durrant
Quoted 9 lines · Paul Durrant
These patches add support for multi-page shared rings to xen-blkfront/back. Shared rings must always be a power of 2 in size and so the size is controlled by the new '
max_ring_page_order' module parameter of xen-blkback. This defaults to 0 so operationally there should be no difference with these patches in place. The maximum value of 'max_ring_page_order' is currently limited to 2 (i.e. 4 pages).
xen-blkfront will always use the largest shared ring size supported by the back end. To override this and continue to use a single page ring, as before, set the 'allow_multi_page_ring' module parameter to 0.
Hey Paul,
Would it be possible to rebase this on 3.0? How is it different from the one posted some time ago by .. um, somebody else?