Windyland serving my blog

The Null Block Device

Linux Kernel provides null_blk module since 3.13, which can be used for benchmarking various block-layer implementations. Also it can be used as a dummy device to diagnostic storage system issues.

Check your kernel has null_blk module

  • grep CONFIG_BLK_DEV_NULL /boot/config-$(uname -r)
  • or grep CONFIG_BLK_DEV_NULL /proc/config

for example centos 7 has:


Use Null blk

the usage is much like zram, just insmod this module:

insmod null_blk

you can find two 250 GB-sized block device added

nullb0      251:0    0   250G  0 disk
nullb1      251:1    0   250G  0 disk

and run some benchmark on them:

  • dd if=/dev/zero of=/dev/nullb0 bs=4k oflag=direct
  • dd if=/dev/nullb0 of=/dev/null bs=4k iflag=direct
  • hdparm -tT /dev/nullb0
  • aio-stress -O -s 64m -r 256k -i 1024 -b 1024 /dev/nullb0
  • fio --ioengine=libaio --readwrite=randread --bs=4k --filename /dev/nullb0 --name journal_test --thread --norandommap --numjobs=200 --iodepth=64 --runtime=30 --time_based --group_reporting
  • fio --ioengine=libaio --readwrite=randwrite --bs=4k --filename /dev/nullb0 --name journal_test --thread --norandommap --numjobs=200 --iodepth=64 --runtime=30 --time_based --group_reporting

if you turn on scsi_mq, you will find incredible iops on your fio benchmarks, such as 5M iops on randread on my machine.

Advanced Usage

null_blk module has many parameters provided, use can tune:

  • submit_queues: the number of submission queues
  • gb: size in GiB
  • bs: block size in bytes
  • nr_devices: number of devices to register
  • completion_nsec: time in ns to complete a request in hardware
  • hw_queue_depth: queue depth for each hardware queue

for the case for debian backported 4.6.0 kernel:

sudo modinfo null_blk
filename: /lib/modules/4.6.0-0.bpo.1-amd64/kernel/drivers/block/null_blk.ko
license:        GPL
author:         Jens Axboe <>
intree:         Y
vermagic:       4.6.0-0.bpo.1-amd64 SMP mod_unload modversions
parm:           submit_queues:Number of submission queues (int)
parm:           home_node:Home node for the device (int)
parm:           queue_mode:Block interface to use (0=bio,1=rq,2=multiqueue)
parm:           gb:Size in GB (int)
parm:           bs:Block size (in bytes) (int)
parm:           nr_devices:Number of devices to register (int)
parm:           use_lightnvm:Register as a LightNVM device (bool)
parm:           irqmode:IRQ completion handler. 0-none, 1-softirq, 2-timer
parm:           completion_nsec:Time in ns to complete a request in hardware.  Default: 10,000ns (ulong)
parm:           hw_queue_depth:Queue depth for each hardware queue. Default: 64
parm:           use_per_node_hctx:Use per-node allocation for hardware context queues. Default: false (bool)

there parameters are also described in null blk kernel documentation