block: Swap request limit definitions
PATCH 1/1 block: Swap request limit definitions
Defining BDRV_REQUEST_MAX_SECTORS based on BDRV_REQUEST_MAX_BYTES is simpler than the other way around.
--- include/block/block.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
include/block/block.h +2 -3
@@ -114,9 +114,8 @@ typedef struct HDGeometry {#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1) -#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)/* * Allocation status flags
Signature · 1 line
2.11.0
Quoted 28 lines · Max Reitz
Defining
BDRV_REQUEST_MAX_SECTORSbased onBDRV_REQUEST_MAX_BYTESis simpler than the other way around.Signed-off-by Max Reitz <[email protected]>--- include/block/block.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/block/block.h +2
-3@@ -114,9 +114,8 @@ typedef struct HDGeometry {#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1) -#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)/* * Allocation status flags Signature · 1 line
2.11.0
include/block/block.h typedef struct HDGeometry { · line 118
Quoted 5 lines · Max Reitz
include/block/block.h +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)
I'm just pointing it out because I don't know if this can cause problems, but this patch would make BDRV_REQUEST_MAX_BYTES not a multiple of the sector size (INT_MAX is actually a prime number).
Berto
Quoted 11 lines · Alberto Garcia
include/block/block.h typedef struct HDGeometry { · line 118
Quoted 5 lines · Max Reitz
include/block/block.h +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)I'm just pointing it out because I don't know if this can cause problems, but this patch would make
BDRV_REQUEST_MAX_BYTESnot a multiple of the sector size (INT_MAXis actually a prime number).
Very good point. I don't think this could be an issue, though. For one thing, the use of BDRV_REQUEST_MAX_BYTES is very limited.
Apart from that, I guess the main issue would be that if you send an unaligned head/tail the automatic round-up would exceed BDRV_REQUEST_MAX_SECTORS. But this is a pre-existing issue, actually:
When you issue a request with an unaligned head and 2G - 512 bytes length, bdrv_co_pwritev() will align it to 2G (which is greater than INT_MAX).
(Can be tested trivially with:
$ qemu-io -c 'write 511 2147483136' --image-opts driver=null-co,size=4G
and some debugging code in block/io.c)
You can make the request even bigger by increasing the bs->bl.request_alignment.
Not a big issue, though, as bdrv_aligned_p{read,write}v() actually take an unsigned int and break down requests greater than INT_MAX automatically. As long as bs->bl.request_alignment stays under 1G or so we'll be fine (i.e. as long as we don't get an unsigned int overflow) -- and when it breaks it won't be because BDRV_REQUEST_MAX_BYTES is not aligned to sectors.
Max
Quoted 10 lines · Max Reitz
Quoted 9 lines
include/block/block.h typedef struct HDGeometry { · line 118
Quoted 5 lines
include/block/block.h +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)I'm just pointing it out because I don't know if this can cause problems, but this patch would make
BDRV_REQUEST_MAX_BYTESnot a multiple of the sector size (INT_MAXis actually a prime number).
Quoted 2 lines
Very good point. I don't think this could be an issue, though. For one thing, the use of
BDRV_REQUEST_MAX_BYTESis very limited.
Ok, but then I wonder what's the benefit of increasing BDRV_REQUEST_MAX_BYTES.
Berto
Quoted 12 lines · Alberto Garcia
Quoted 10 lines · Max Reitz
Quoted 9 lines
include/block/block.h typedef struct HDGeometry { · line 118
Quoted 5 lines
include/block/block.h +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)I'm just pointing it out because I don't know if this can cause problems, but this patch would make
BDRV_REQUEST_MAX_BYTESnot a multiple of the sector size (INT_MAXis actually a prime number).
Quoted 5 lines
Quoted 2 lines
Very good point. I don't think this could be an issue, though. For one thing, the use of
BDRV_REQUEST_MAX_BYTESis very limited.Ok, but then I wonder what's the benefit of increasing
BDRV_REQUEST_MAX_BYTES.
The benefit is that the definition looks cleaner.
Max
Am 15.02.2017 um 14:42 hat Max Reitz geschrieben:
Quoted 13 lines · Alberto Garcia
Quoted 12 lines · Max Reitz
Quoted 11 lines
Quoted 10 lines
include/block/block.h typedef struct HDGeometry { · line 118
Quoted 6 lines
include/block/block.h +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)I'm just pointing it out because I don't know if this can cause problems, but this patch would make
BDRV_REQUEST_MAX_BYTESnot a multiple of the sector size (INT_MAXis actually a prime number).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Very good point. I don't think this could be an issue, though. For one thing, the use of
BDRV_REQUEST_MAX_BYTESis very limited.Ok, but then I wonder what's the benefit of increasing
BDRV_REQUEST_MAX_BYTES.The benefit is that the definition looks cleaner.
Whatever way we want to write it, I think MAX_BYTES = MAX_SECTORS * 512 should be a given. Everything else is bound to confuse people and introduce bugs sooner or later.
Kevin
Quoted 17 lines · Kevin Wolf
Am 15.02.2017 um 14:42 hat Max Reitz geschrieben:
Quoted 16 lines · Alberto Garcia
Quoted 15 lines · Max Reitz
Quoted 13 lines
Quoted 10 lines
include/block/block.h typedef struct HDGeometry { · line 118
Quoted 6 lines
include/block/block.h +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)I'm just pointing it out because I don't know if this can cause problems, but this patch would make
BDRV_REQUEST_MAX_BYTESnot a multiple of the sector size (INT_MAXis actually a prime number).Very good point. I don't think this could be an issue, though. For one thing, the use of
BDRV_REQUEST_MAX_BYTESis very limited.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Ok, but then I wonder what's the benefit of increasing
BDRV_REQUEST_MAX_BYTES.The benefit is that the definition looks cleaner.
Whatever way we want to write it, I think
MAX_BYTES=MAX_SECTORS* 512 should be a given. Everything else is bound to confuse people and introduce bugs sooner or later.
Probably only sooner and not later, considering we are switching to byte granularity overall anyway. And if something confuses people, I'd argue it's the fact that we still have sector granularity all over the place and not that your requests can be a bit bigger if you submit them in bytes than if you submit them in sectors.
Anyway, if MAX_BYTES should be a multiple of the sector size, then I can't think of a much better way to write this than what we currently have and this patch is unneeded.
Max
Am 15.02.2017 um 17:48 hat Max Reitz geschrieben:
Quoted 33 lines · Kevin Wolf
Quoted 17 lines
Am 15.02.2017 um 14:42 hat Max Reitz geschrieben:
Quoted 16 lines · Alberto Garcia
Quoted 15 lines · Max Reitz
Quoted 13 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)I'm just pointing it out because I don't know if this can cause problems, but this patch would make
BDRV_REQUEST_MAX_BYTESnot a multiple of the sector size (INT_MAXis actually a prime number).Very good point. I don't think this could be an issue, though. For one thing, the use of
BDRV_REQUEST_MAX_BYTESis very limited.Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Ok, but then I wonder what's the benefit of increasing
BDRV_REQUEST_MAX_BYTES.The benefit is that the definition looks cleaner.
Whatever way we want to write it, I think
MAX_BYTES=MAX_SECTORS* 512 should be a given. Everything else is bound to confuse people and introduce bugs sooner or later.Probably only sooner and not later, considering we are switching to byte granularity overall anyway. And if something confuses people, I'd argue it's the fact that we still have sector granularity all over the place and not that your requests can be a bit bigger if you submit them in bytes than if you submit them in sectors.
Quoted 3 lines
Anyway, if
MAX_BYTESshould be a multiple of the sector size, then I can't think of a much better way to write this than what we currently have and this patch is unneeded.
Maybe we can just get rid of BDRV_REQUEST_MAX_SECTORS? Or do we need to do a few more conversion before that?
Kevin
Quoted 34 lines · Kevin Wolf
Am 15.02.2017 um 17:48 hat Max Reitz geschrieben:
Quoted 33 lines · Kevin Wolf
Quoted 17 lines
Am 15.02.2017 um 14:42 hat Max Reitz geschrieben:
Quoted 16 lines · Alberto Garcia
Quoted 15 lines · Max Reitz
Quoted 13 lines
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +2
-3-#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \ - INT_MAX >> BDRV_SECTOR_BITS) -#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) +#define BDRV_REQUEST_MAX_BYTES MIN(SIZE_MAX, INT_MAX) +#define BDRV_REQUEST_MAX_SECTORS (BDRV_REQUEST_MAX_BYTES >> BDRV_SECTOR_BITS)I'm just pointing it out because I don't know if this can cause problems, but this patch would make
BDRV_REQUEST_MAX_BYTESnot a multiple of the sector size (INT_MAXis actually a prime number).Very good point. I don't think this could be an issue, though. For one thing, the use of
BDRV_REQUEST_MAX_BYTESis very limited.Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Ok, but then I wonder what's the benefit of increasing
BDRV_REQUEST_MAX_BYTES.The benefit is that the definition looks cleaner.
Whatever way we want to write it, I think
MAX_BYTES=MAX_SECTORS* 512 should be a given. Everything else is bound to confuse people and introduce bugs sooner or later.Probably only sooner and not later, considering we are switching to byte granularity overall anyway. And if something confuses people, I'd argue it's the fact that we still have sector granularity all over the place and not that your requests can be a bit bigger if you submit them in bytes than if you submit them in sectors.
Quoted 6 lines
Quoted 3 lines
Anyway, if
MAX_BYTESshould be a multiple of the sector size, then I can't think of a much better way to write this than what we currently have and this patch is unneeded.Maybe we can just get rid of
BDRV_REQUEST_MAX_SECTORS? Or do we need to do a few more conversion before that?
We probably could, but it wouldn't make much sense. We have many places that use BDRV_REQUEST_MAX_SECTORS without multiplying it by 512 and if we decided to use *_MAX_BYTES dividing it by 512 in every one of those places, we could just as well define a central macro for that -- which would be *_MAX_SECTORS, so...
Max