bio size is always 4096

Pranay Srivastava pranjas at gmail.com
Tue May 14 01:28:59 EDT 2013


Hi Neha

On 5/13/13, neha naik <nehanaik27 at gmail.com> wrote:
> Hi,
>    I was under the impression that when the bio comes to a block device
> driver its size is variable. But, after writing a block device driver i
> realized that such is not the case and it always is 4096.

Your Filesystem block size is usually page size so from file system
point of view your bios would be that of block size that the
filesystem understands. Try having a file system block size other than
PAGE_SIZE (must be multiple of 512 and <=PAGE_SIZE) though.

> Does this mean that by default if i don't use any merge function the bio
> will always have size 4096(meaning it will have only 1 page!!!!).

I guess it's not about that if you don't use a merge function. Bios
would be given by file system to your driver depending on the block
size of the file system. Now there would most probably be a mismatch
of granularity of file system block size and your device's block size.

If every thing is default and File System block size == PAGE_SIZE and
by default the block size for your device is taken to be 512 (kernel
always works in 512 bytes for block device). This means 4096/512 = 8
sectors per bio.

Actually if you see this,

--------> set_min_blocksize

This would make it clear that the block size of the file system would
be larger of the block size of block size of your device and the block
size of your file system. I guess while formatting the mkfs would also
try to match it like that or it may be fixed.

You can change the block size of your device by doing
blk_queue_logical_block_size before you make you add your disk. Again,
if you do this your request handling function must be able to
translate everything to/from 512 bytes since for kernel everything is
in 512 size sectors.

So you can check
 a) By changing the block size of file system first.
 b) By changing the block size of device.
 c) Do both
By changing i mean don't use PAGE_SIZE for file system and don't use
512 bytes for device's block size.

>
>
> Regards,
> Neha
>

    ---P.K.S
-- 
Pranay Srivastava



More information about the Kernelnewbies mailing list