xen-block: bug fixes for indirect-descriptors
Subsystems (3)
cover xen-block: bug fixes for indirect-descriptors
This series contains a small number of bug fixes and improvements for xen-block indirect descriptors.
PATCH 1/4 xen-blkback: workaround compiler bug in gcc 4.1
The code generat with gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54) creates an unbound loop for the second foreach_grant_safe loop in purge_persistent_gnt.
The workaround is to avoid having this second loop and instead perform all the work inside the first loop by adding a new variable, clean_used, that will be set when all the desired persistent grants have been removed and we need to iterate over the remaining ones to remove the WAS_ACTIVE flag.
--- drivers/block/xen-blkback/blkback.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
drivers/block/xen-blkback/blkback.c +14 -10
@@ -341,7 +341,7 @@ static void purge_persistent_gnt(struct xen_blkif *blkif)struct persistent_gnt *persistent_gnt;struct rb_node *n;unsigned int num_clean, total; -bool scan_used = false; +bool scan_used = false, clean_used = false;struct rb_root *root; if (blkif->persistent_gnt_c < xen_blkif_max_pgrants ||
@@ -358,9 +358,8 @@ static void purge_persistent_gnt(struct xen_blkif *blkif) num_clean = (xen_blkif_max_pgrants /100 ) *LRU_PERCENT_CLEAN ; num_clean = blkif->persistent_gnt_c - xen_blkif_max_pgrants + num_clean; num_clean =min (blkif->persistent_gnt_c, num_clean); -if (num_clean > - (blkif->persistent_gnt_c - -atomic_read (&blkif->persistent_gnt_in_use))) +if ((num_clean ==0 ) || + (num_clean > (blkif->persistent_gnt_c -atomic_read (&blkif->persistent_gnt_in_use))))return ;/*
@@ -383,6 +382,11 @@ purge_list:BUG_ON (persistent_gnt->handle ==BLKBACK_INVALID_HANDLE ); +if (clean_used) { +clear_bit (PERSISTENT_GNT_WAS_ACTIVE , persistent_gnt->flags); +continue ; + } +if (test_bit (PERSISTENT_GNT_ACTIVE , persistent_gnt->flags))continue ; if (!scan_used &&
@@ -400,18 +404,18 @@ purge_list:* grants that were used since last purge in order to cope * with the requested num */ -if (!scan_used) { +if (!scan_used && !clean_used) {pr_debug (DRV_PFX "Still missing %u purged frames\n" , num_clean); scan_used = true; goto purge_list; } finished: -/* Remove the "used" flag from all the persistent grants */ - foreach_grant_safe(persistent_gnt, n, root, node) { -BUG_ON (persistent_gnt->handle == -BLKBACK_INVALID_HANDLE ); -clear_bit (PERSISTENT_GNT_WAS_ACTIVE , persistent_gnt->flags); +if (!clean_used) { +pr_debug (DRV_PFX "Finished scanning for grants to clean, removing used flag\n" ); + clean_used = true; + goto purge_list; } + blkif->persistent_gnt_c -= (total - num_clean); blkif->vbd.overflow_max_grants =0 ;
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 1/4 xen-blkback: workaround compiler bug in gcc 4.1
In reply to Roger Pau MonneThe code generat with gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54) creates an unbound loop for the second foreach_grant_safe loop in purge_persistent_gnt.
The workaround is to avoid having this second loop and instead perform all the work inside the first loop by adding a new variable, clean_used, that will be set when all the desired persistent grants have been removed and we need to iterate over the remaining ones to remove the WAS_ACTIVE flag.
--- drivers/block/xen-blkback/blkback.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
drivers/block/xen-blkback/blkback.c +14 -10
@@ -341,7 +341,7 @@ static void purge_persistent_gnt(struct xen_blkif *blkif)struct persistent_gnt *persistent_gnt;struct rb_node *n;unsigned int num_clean, total; -bool scan_used = false; +bool scan_used = false, clean_used = false;struct rb_root *root; if (blkif->persistent_gnt_c < xen_blkif_max_pgrants ||
@@ -358,9 +358,8 @@ static void purge_persistent_gnt(struct xen_blkif *blkif) num_clean = (xen_blkif_max_pgrants /100 ) *LRU_PERCENT_CLEAN ; num_clean = blkif->persistent_gnt_c - xen_blkif_max_pgrants + num_clean; num_clean =min (blkif->persistent_gnt_c, num_clean); -if (num_clean > - (blkif->persistent_gnt_c - -atomic_read (&blkif->persistent_gnt_in_use))) +if ((num_clean ==0 ) || + (num_clean > (blkif->persistent_gnt_c -atomic_read (&blkif->persistent_gnt_in_use))))return ;/*
@@ -383,6 +382,11 @@ purge_list:BUG_ON (persistent_gnt->handle ==BLKBACK_INVALID_HANDLE ); +if (clean_used) { +clear_bit (PERSISTENT_GNT_WAS_ACTIVE , persistent_gnt->flags); +continue ; + } +if (test_bit (PERSISTENT_GNT_ACTIVE , persistent_gnt->flags))continue ; if (!scan_used &&
@@ -400,18 +404,18 @@ purge_list:* grants that were used since last purge in order to cope * with the requested num */ -if (!scan_used) { +if (!scan_used && !clean_used) {pr_debug (DRV_PFX "Still missing %u purged frames\n" , num_clean); scan_used = true; goto purge_list; } finished: -/* Remove the "used" flag from all the persistent grants */ - foreach_grant_safe(persistent_gnt, n, root, node) { -BUG_ON (persistent_gnt->handle == -BLKBACK_INVALID_HANDLE ); -clear_bit (PERSISTENT_GNT_WAS_ACTIVE , persistent_gnt->flags); +if (!clean_used) { +pr_debug (DRV_PFX "Finished scanning for grants to clean, removing used flag\n" ); + clean_used = true; + goto purge_list; } + blkif->persistent_gnt_c -= (total - num_clean); blkif->vbd.overflow_max_grants =0 ;
Signature · 1 line
1.7.7.5 (Apple Git-26)
PATCH 2/4 xen-blkfront: set blk_queue_max_hw_sectors correctly
In reply to Roger Pau MonneNow that indirect segments are enabled blk_queue_max_hw_sectors must be set to match the maximum number of sectors we can handle in a request.
--- drivers/block/xen-blkfront.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/block/xen-blkfront.c +1 -1
@@ -633,7 +633,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size,/* Hard sector size and max sectors impersonate the equiv. hardware. */ blk_queue_logical_block_size (rq, sector_size);blk_queue_physical_block_size (rq, physical_sector_size); -blk_queue_max_hw_sectors (rq,512 ); +blk_queue_max_hw_sectors (rq, (segments *PAGE_SIZE ) /512 );/* Each segment in a request is up to an aligned page in size. */ blk_queue_segment_boundary (rq,PAGE_SIZE -1 );
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 3/4 xen-blkback: check the number of iovecs before allocating a bios
In reply to Roger Pau MonneWith the introduction of indirect segments we can receive requests with a number of segments bigger than the maximum number of allowed iovecs in a bios, so make sure that blkback doesn't try to allocate a bios with more iovecs than BIO_MAX_PAGES
--- drivers/block/xen-blkback/blkback.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/block/xen-blkback/blkback.c +2 -1
@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs = (nseg-i) >BIO_MAX_PAGES ?BIO_MAX_PAGES : (nseg-i); + bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 3/4] xen-blkback: check the number of iovecs before allocating a bios
drivers/block/xen-blkback/blkback.c static int dispatch_rw_block_io(struct xen_blkif *blkif, · line 1239
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Roger Pau Monne
drivers/block/xen-blkback/blkback.c +1
-1@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs = (nseg-i) >BIO_MAX_PAGES ?BIO_MAX_PAGES : (nseg-i);
I'm sure this results in a compiler warning (declaration after statement).
And it surely would read much better if you used some form of min() - the shorter line would at once allow you to properly blank separate operands from operators.
Jan
Quoted 4 lines
drivers/block/xen-blkback/blkback.c +1
-0+ bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;
Re: [Xen-devel] [PATCH 3/4] xen-blkback: check the number of iovecs before allocating a bios
In reply to Roger Pau Monnedrivers/block/xen-blkback/blkback.c static int dispatch_rw_block_io(struct xen_blkif *blkif, · line 1239
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Roger Pau Monne
drivers/block/xen-blkback/blkback.c +1
-1@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs = (nseg-i) >BIO_MAX_PAGES ?BIO_MAX_PAGES : (nseg-i);
I'm sure this results in a compiler warning (declaration after statement).
And it surely would read much better if you used some form of min() - the shorter line would at once allow you to properly blank separate operands from operators.
Jan
Quoted 4 lines
drivers/block/xen-blkback/blkback.c +1
-0+ bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;
Re: [PATCH 3/4] xen-blkback: check the number of iovecs before allocating a bios
Quoted 10 lines · Jan Beulich
drivers/block/xen-blkback/blkback.c static int dispatch_rw_block_io(struct xen_blkif *blkif, · line 1239
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Roger Pau Monne
drivers/block/xen-blkback/blkback.c +1
-1@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs = (nseg-i) >BIO_MAX_PAGES ?BIO_MAX_PAGES : (nseg-i);I'm sure this results in a compiler warning (declaration after statement).
No, because it's the first statement inside the while loop.
Quoted 3 lines
And it surely would read much better if you used some form of
min()- the shorter line would at once allow you to properly blank separate operands from operators.
Sure, I will switch it to min, thanks for the comments.
Quoted 9 lines
Jan
Quoted 4 lines
drivers/block/xen-blkback/blkback.c +1
-0+ bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;
Re: [Xen-devel] [PATCH 3/4] xen-blkback: check the number of iovecs before allocating a bios
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
drivers/block/xen-blkback/blkback.c static int dispatch_rw_block_io(struct xen_blkif *blkif, · line 1239
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Roger Pau Monne
drivers/block/xen-blkback/blkback.c +1
-1@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs = (nseg-i) >BIO_MAX_PAGES ?BIO_MAX_PAGES : (nseg-i);I'm sure this results in a compiler warning (declaration after statement).
No, because it's the first statement inside the while loop.
Quoted 3 lines
And it surely would read much better if you used some form of
min()- the shorter line would at once allow you to properly blank separate operands from operators.
Sure, I will switch it to min, thanks for the comments.
Quoted 9 lines
Jan
Quoted 4 lines
drivers/block/xen-blkback/blkback.c +1
-0+ bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;
PATCH v2 3/4 xen-blkback: check the number of iovecs before allocating a bios
In reply to Roger Pau MonneWith the introduction of indirect segments we can receive requests with a number of segments bigger than the maximum number of allowed iovecs in a bios, so make sure that blkback doesn't try to allocate a bios with more iovecs than BIO_MAX_PAGES
--- drivers/block/xen-blkback/blkback.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/block/xen-blkback/blkback.c +2 -1
@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs =min_t (int, (nseg-i),BIO_MAX_PAGES ); + bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 3/4 xen-blkback: check the number of iovecs before allocating a bios
In reply to Roger Pau MonneWith the introduction of indirect segments we can receive requests with a number of segments bigger than the maximum number of allowed iovecs in a bios, so make sure that blkback doesn't try to allocate a bios with more iovecs than BIO_MAX_PAGES
--- drivers/block/xen-blkback/blkback.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/block/xen-blkback/blkback.c +2 -1
@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs =min_t (int, (nseg-i),BIO_MAX_PAGES ); + bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v2 3/4] xen-blkback: check the number of iovecs before allocating a bios
Quoted 4 lines · Roger Pau Monne
With the introduction of indirect segments we can receive requests with a number of segments bigger than the maximum number of allowed iovecs in a bios, so make sure that blkback doesn't try to allocate a bios with more iovecs than
BIO_MAX_PAGES
Shouldn't we just gate the feature-indirect-descriptor value to take this into account?
What happens if the nseg is > BIO_MAX_PAGES? Do we "lose" the request for the remaining segments?
Quoted 24 lines
Signed-off-by Roger Pau Monné <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>--- drivers/block/xen-blkback/blkback.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)drivers/block/xen-blkback/blkback.c +2
-1@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs =min_t (int, (nseg-i),BIO_MAX_PAGES ); + bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v2 3/4] xen-blkback: check the number of iovecs before allocating a bios
In reply to Roger Pau MonneQuoted 4 lines · Roger Pau Monne
With the introduction of indirect segments we can receive requests with a number of segments bigger than the maximum number of allowed iovecs in a bios, so make sure that blkback doesn't try to allocate a bios with more iovecs than
BIO_MAX_PAGES
Shouldn't we just gate the feature-indirect-descriptor value to take this into account?
What happens if the nseg is > BIO_MAX_PAGES? Do we "lose" the request for the remaining segments?
Quoted 24 lines
Signed-off-by Roger Pau Monné <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>--- drivers/block/xen-blkback/blkback.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)drivers/block/xen-blkback/blkback.c +2
-1@@ -1236,7 +1236,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, seg[i].nsec << 9, seg[i].offset) == 0)) { - bio =bio_alloc (GFP_KERNEL , nseg-i); +int nr_iovecs =min_t (int, (nseg-i),BIO_MAX_PAGES ); + bio =bio_alloc (GFP_KERNEL , nr_iovecs);if (unlikely (bio ==NULL )) goto fail_put_bio;Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v2 3/4] xen-blkback: check the number of iovecs before allocating a bios
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Roger Pau Monne
With the introduction of indirect segments we can receive requests with a number of segments bigger than the maximum number of allowed iovecs in a bios, so make sure that blkback doesn't try to allocate a bios with more iovecs than
BIO_MAX_PAGESShouldn't we just gate the feature-indirect-descriptor value to take this into account?
What happens if the nseg is >
BIO_MAX_PAGES? Do we "lose" the request for the remaining segments?
No, we just allocate several bios in order to send the request to the underlying device.
Re: [PATCH v2 3/4] xen-blkback: check the number of iovecs before allocating a bios
In reply to Konrad Rzeszutek WilkQuoted 11 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Roger Pau Monne
With the introduction of indirect segments we can receive requests with a number of segments bigger than the maximum number of allowed iovecs in a bios, so make sure that blkback doesn't try to allocate a bios with more iovecs than
BIO_MAX_PAGESShouldn't we just gate the feature-indirect-descriptor value to take this into account?
What happens if the nseg is >
BIO_MAX_PAGES? Do we "lose" the request for the remaining segments?
No, we just allocate several bios in order to send the request to the underlying device.
PATCH 4/4 xen-blkfront: increase the default number of indirect segments
In reply to Roger Pau MonneWhen using certain storage devices (like RAID) having a bigger number of segments per request provides better performance.
--- drivers/block/xen-blkfront.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/xen-blkfront.c +2 -2
@@ -94,9 +94,9 @@ static const struct block_device_operations xlvbd_block_fops;* by the backend driver. */ -static unsigned int xen_blkif_max_segments =32 ; +static unsigned int xen_blkif_max_segments =64 ;module_param_named (max, xen_blkif_max_segments, int,S_IRUGO ); -MODULE_PARM_DESC (max,"Maximum amount of segments in indirect requests (default is 32)" ); +MODULE_PARM_DESC (max,"Maximum amount of segments in indirect requests (default is 64)" );#define BLK_RING_SIZE __CONST_RING_SIZE(blkif, PAGE_SIZE)
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 4/4] xen-blkfront: increase the default number of indirect segments
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Roger Pau Monne
When using certain storage devices (like RAID) having a bigger number of segments per request provides better performance.
And there's no drawback (higher memory foot print if nothing else) on "certain other storage devices"? Adjusting defaults just because it is beneficial for some devices, but may adversely affect others is not really a good thing - in such an event, you'd be better off determining the default dynamically per device.
Jan
Quoted 23 lines
Signed-off-by Roger Pau Monné <[email protected]>Reported-by Steven Haigh <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>--- drivers/block/xen-blkfront.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)drivers/block/xen-blkfront.c +2
-2@@ -94,9 +94,9 @@ static const struct block_device_operations xlvbd_block_fops;* by the backend driver. */ -static unsigned int xen_blkif_max_segments =32 ; +static unsigned int xen_blkif_max_segments =64 ;module_param_named (max, xen_blkif_max_segments, int,S_IRUGO ); -MODULE_PARM_DESC(max, "Maximum amount of segments in indirect requests (default is 32)"); +MODULE_PARM_DESC(max, "Maximum amount of segments in indirect requests (default is 64)");
Quoted 10 lines
#define
BLK_RING_SIZE__CONST_RING_SIZE(blkif, PAGE_SIZE)Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH 4/4] xen-blkfront: increase the default number of indirect segments
In reply to Roger Pau MonneQuoted 3 lines
Quoted 1 line
Quoted 1 line · Roger Pau Monne
When using certain storage devices (like RAID) having a bigger number of segments per request provides better performance.
And there's no drawback (higher memory foot print if nothing else) on "certain other storage devices"? Adjusting defaults just because it is beneficial for some devices, but may adversely affect others is not really a good thing - in such an event, you'd be better off determining the default dynamically per device.
Jan
Quoted 33 lines
Signed-off-by Roger Pau Monné <[email protected]>Reported-by Steven Haigh <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>--- drivers/block/xen-blkfront.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)drivers/block/xen-blkfront.c +2
-2@@ -94,9 +94,9 @@ static const struct block_device_operations xlvbd_block_fops;* by the backend driver. */ -static unsigned int xen_blkif_max_segments =32 ; +static unsigned int xen_blkif_max_segments =64 ;module_param_named (max, xen_blkif_max_segments, int,S_IRUGO ); -MODULE_PARM_DESC(max, "Maximum amount of segments in indirect requests (default is 32)"); +MODULE_PARM_DESC(max, "Maximum amount of segments in indirect requests (default is 64)");#define
BLK_RING_SIZE__CONST_RING_SIZE(blkif, PAGE_SIZE)Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel