Add iodepth_batch setting

This allows controlling how much IO we submit in one go
independent of the iodepth set.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/HOWTO b/HOWTO
index 237b3ad..de4b0a9 100644
--- a/HOWTO
+++ b/HOWTO
@@ -294,6 +294,10 @@
 		job, can be overridden with a larger value for higher
 		concurrency.
 
+iodepth_batch=int This defines how many pieces of IO to submit at once.
+		It defaults to the same as iodepth, but can be set lower
+		if one so desires.
+
 iodepth_low=int	The low water mark indicating when to start filling
 		the queue again. Defaults to the same as iodepth, meaning
 		that fio will attempt to keep the queue full at all times.
diff --git a/fio.c b/fio.c
index b095527..c5b85ae 100644
--- a/fio.c
+++ b/fio.c
@@ -433,6 +433,8 @@
 			 */
 			if (td->io_ops->commit == NULL)
 				io_u_queued(td, io_u);
+			else if (td->io_u_queued >= td->iodepth_batch)
+				ret = td_io_commit(td);
 			break;
 		case FIO_Q_BUSY:
 			requeue_io_u(td, &io_u);
diff --git a/fio.h b/fio.h
index 57d1b6b..6d0c9e3 100644
--- a/fio.h
+++ b/fio.h
@@ -351,6 +351,7 @@
 	unsigned int numjobs;
 	unsigned int iodepth;
 	unsigned int iodepth_low;
+	unsigned int iodepth_batch;
 	os_cpu_mask_t cpumask;
 	unsigned int iolog;
 	unsigned int read_iolog;
@@ -389,6 +390,7 @@
 	struct list_head io_u_freelist;
 	struct list_head io_u_busylist;
 	struct list_head io_u_requeues;
+	unsigned int io_u_queued;
 
 	/*
 	 * Rate state
diff --git a/init.c b/init.c
index 8efb24a..636e957 100644
--- a/init.c
+++ b/init.c
@@ -113,6 +113,12 @@
 		.def	= "1",
 	},
 	{
+		.name	= "iodepth_batch",
+		.type	= FIO_OPT_INT,
+		.off1	= td_var_offset(iodepth_batch),
+		.help	= "Number of IO to submit in one go",
+	},
+	{
 		.name	= "iodepth_low",
 		.type	= FIO_OPT_INT,
 		.off1	= td_var_offset(iodepth_low),
@@ -704,6 +710,12 @@
 	 */
 	if (td->iodepth_low > td->iodepth || !td->iodepth_low)
 		td->iodepth_low = td->iodepth;
+
+	/*
+	 * If batch number isn't set, default to the same as iodepth
+	 */
+	if (td->iodepth_batch > td->iodepth || !td->iodepth_batch)
+		td->iodepth_batch = td->iodepth;
 }
 
 /*
diff --git a/ioengines.c b/ioengines.c
index 727981f..2cc3288 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -216,6 +216,9 @@
 
 	ret = td->io_ops->queue(td, io_u);
 
+	if (ret == FIO_Q_QUEUED)
+		td->io_u_queued++;
+
 	if ((td->io_ops->flags & FIO_SYNCIO) == 0) {
 		fio_gettime(&io_u->issue_time, NULL);
 
@@ -242,6 +245,8 @@
 {
 	if (!td->cur_depth)
 		return 0;
+
+	td->io_u_queued = 0;
 	if (td->io_ops->commit)
 		return td->io_ops->commit(td);