Direct io on block device has performance regression on 2.6.x kernel - pseudo disk driver
The pseudo disk driver that I used to stress the kernel I/O stack (anything above block layer, AIO/DIO/BIO).
- Ken
blknull.c +97 -0
@@ -0,0 +1,97 @@ +#include <linux/module.h> +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/major.h> +#include <linux/fs.h> +#include <linux/bio.h> +#include <linux/blkpg.h> +#include <linux/spinlock.h> + +#include <linux/blkdev.h> +#include <linux/genhd.h> + +#define BLK_NULL_MAJOR 60 +#define BLK_NULL_NAME "blknull" + + +MODULE_AUTHOR ("Ken Chen" ); +MODULE_DESCRIPTION ("null block driver" ); +MODULE_LICENSE ("GPL" ); + + +spinlock_t driver_lock; +struct request_queue *q; +struct gendisk *disk; + + +static int null_open (struct inode *inode,struct file *filp) +{ +return 0 ; +} + +static int null_release (struct inode *inode,struct file *filp) +{ +return 0 ; +} + +static struct block_device_operations null_fops = { + .owner =THIS_MODULE , + .open = null_open, + .release = null_release, +}; + +static void do_null_request (request_queue_t *q) +{ +struct request *req; + +while (!blk_queue_plugged (q)) { + req =elv_next_request (q); +if (!req) +break ; + +blkdev_dequeue_request (req); + +end_that_request_first (req,1 , req->nr_sectors); +end_that_request_last (req); + } +} + +static int __init init_blk_null_module (void ) +{ + +if (register_blkdev (BLK_NULL_MAJOR ,BLK_NULL_NAME )) { +printk (KERN_ERR "Unable to register null blk device\n" ); +return 0 ; + } + +spin_lock_init (&driver_lock); + q =blk_init_queue (do_null_request, &driver_lock); +if (q) { + disk =alloc_disk (1 ); + +if (disk) { + disk->major =BLK_NULL_MAJOR ; + disk->first_minor =0 ; + disk->fops = &null_fops; + disk->capacity =1 <<30 ; + disk->queue = q; +memcpy (disk->disk_name,BLK_NULL_NAME ,sizeof (BLK_NULL_NAME )); +add_disk (disk); +return 1 ; + } + +blk_cleanup_queue (q); + } +unregister_blkdev (BLK_NULL_MAJOR ,BLK_NULL_NAME ); +return 0 ; +} + +static void __exit exit_blk_null_module(void) +{ +del_gendisk (disk); +blk_cleanup_queue (q); +unregister_blkdev (BLK_NULL_MAJOR ,BLK_NULL_NAME ); +} + +module_init (init_blk_null_module); +module_exit (exit_blk_null_module);
Makefile +1 -0
@@ -0,0 +1 @@ +obj-m := blknull.o