How to reduce Linux Block Storage IO sizes

A colleague recently asked me an interesting question, How can I reduce the size of a physical IO on Linux?

So here’s a blog that hopefully answers that question.

Linux Operating System

For this blog I will be using a Linux server with a Kernel that has a default maximum size of 1280KB (if you are running an older Kernel you may still be using 512KB, another reason to upgrade) connected to Pure Storage FlashArray which supports a maximum transfer size of 4MB.

The Linux Kernel has 2 parameters in the /sys/block file system used to manage physical block IO sizes: max_hw_sectors_kb and max_sectors_kb.

max_hw_sectors_kb (read-only)

This is the maximum number of kilobytes supported in a single data transfer by the underlying device.

This value is read-only. It is set by the driver to reflect the driver/hardware limit. The block layer will also enforce this limit and so it will take the minimum of the max_hw_sectors_kb and the kernel default block limit to make sure all I/O requests are within the size limit that the hardware/driver can support.

max_sectors_kb (read/write)

This is the maximum number of kilobytes that the block layer will allow for a filesystem request. This value can be overwritten, but it must be smaller than or equal to the maximum size allowed by the hardware.

From the above we can see max_sectors_kb is read-writable.

Using dd we can check the device throughput, for example.

Output from iostat -tkx 1 -d /dev/dm-18 shows the average request size (avgrq-sz) for my FlashArray volume never exceeds 8192 sectors or 4MB (8192*512B) as expected.

So let’s reduce the max_sectors_kb from 4096 to 128 and repeat the test.

Output from iostat -tkx 1 -d /dev/dm-18 shows the average request size (avgrq-sz) now never exceeds 256 sectors or 128KB (128*512B) as we hoped.

Great, OK what if we try to set max_sector_kb to a value higher than the storage device supports ?

Good news, if you try to use an unsupported value, you get a write error, and will need to lower the value to an acceptable value.

Summary

In this blog post I have shared how we can use the Linux Kernel to limit physical IO sizes, perform a test using the Linux dd command, and check results of the the change with iostat.

Leave a Reply

Create a website or blog at WordPress.com

Up ↑

Discover more from Ron Ekins' - Oracle Technology, DevOps and Kubernetes Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading