linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] block: set per bio io-priority in blk-lib
@ 2019-04-15  5:57 Chaitanya Kulkarni
  2019-04-15  5:57 ` [PATCH 1/2] block: adjust code for get_task_ioprio() Chaitanya Kulkarni
  2019-04-15  5:57 ` [PATCH 2/2] block: add task priority to init bio iopriority Chaitanya Kulkarni
  0 siblings, 2 replies; 3+ messages in thread
From: Chaitanya Kulkarni @ 2019-04-15  5:57 UTC (permalink / raw)
  To: linux-block; +Cc: Chaitanya Kulkarni

Hi,

While experimenting with the ionice I came across the scenario where
I cannot see the bio's priority field been set when use blkdiscard
for REQ_OP_DISCARD and REQ_OP_WRITE_ZEROES.

This is a small patch-series which initializes the bio->bi_ioprio
(iopriority) field under different operations like REQ_OP_DISCARD and
REQ_OP_WRITE_ZEROES. It helps to track the priority when debugging.

In order to test this I've modified the null_blk and enabled the
write_zeroes through module param. Following are the results.

Without this patches :- 

# git log -1 --oneline
4443f8e6ac77 (HEAD -> master, origin/master, origin/HEAD) Merge tag 'for-linus-20190412' of git://git.kernel.dk/linux-block
# modprobe null_blk gb=5 nr_devices=1 write_zeroes=1
# for prio in `seq 0 3`; do ionice -c ${prio} blkdiscard -z -o 0 -l 4096 /dev/nullb0; done
# dmesg  -c 
[  402.958458] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 0
[  402.966024] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 0
[  402.973960] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 0
[  402.981373] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 0
# 

After thiese patches :-

# git log --oneline -2 
7a54a31cad5c (HEAD -> master) block: add task priority to init bio iopriority
149603fbd421 block: adjust code for get_task_ioprio()
# modprobe null_blk gb=5 nr_devices=1 write_zeroes=1
# for prio in `seq 0 3`; do ionice -c ${prio} blkdiscard -z -o 0 -l 4096 /dev/nullb0; done 
# dmesg  -c 
[ 1426.091772] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 0
[ 1426.100177] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 1
[ 1426.108035] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 2
[ 1426.115768] null_handle_cmd 1220 REQ_OP_WRITE_ZEROES priority class 3
# 

Regards,
Chaitanya

Chaitanya Kulkarni (2):
  block: adjust code for get_task_ioprio()
  block: add task priority to init bio iopriority

 block/blk-lib.c        |  6 ++++++
 block/ioprio.c         | 20 ++++++++++++++++----
 include/linux/ioprio.h |  2 ++
 3 files changed, 24 insertions(+), 4 deletions(-)

-- 
2.19.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] block: adjust code for get_task_ioprio()
  2019-04-15  5:57 [PATCH 0/2] block: set per bio io-priority in blk-lib Chaitanya Kulkarni
@ 2019-04-15  5:57 ` Chaitanya Kulkarni
  2019-04-15  5:57 ` [PATCH 2/2] block: add task priority to init bio iopriority Chaitanya Kulkarni
  1 sibling, 0 replies; 3+ messages in thread
From: Chaitanya Kulkarni @ 2019-04-15  5:57 UTC (permalink / raw)
  To: linux-block; +Cc: Chaitanya Kulkarni

This is a preparation patch which adjusts the code and exports
get_task_ioprio().

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 block/ioprio.c         | 20 ++++++++++++++++----
 include/linux/ioprio.h |  2 ++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/block/ioprio.c b/block/ioprio.c
index f9821080c92c..9853e9077022 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -156,7 +156,7 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
 	return ret;
 }
 
-static int get_task_ioprio(struct task_struct *p)
+static int __get_task_ioprio(struct task_struct *p)
 {
 	int ret;
 
@@ -172,6 +172,18 @@ static int get_task_ioprio(struct task_struct *p)
 	return ret;
 }
 
+int get_task_ioprio(struct task_struct *p)
+{
+	int ret;
+
+	rcu_read_lock();
+	ret = __get_task_ioprio(p);
+	rcu_read_unlock();
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(get_task_ioprio);
+
 int ioprio_best(unsigned short aprio, unsigned short bprio)
 {
 	if (!ioprio_valid(aprio))
@@ -199,7 +211,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
 			else
 				p = find_task_by_vpid(who);
 			if (p)
-				ret = get_task_ioprio(p);
+				ret = __get_task_ioprio(p);
 			break;
 		case IOPRIO_WHO_PGRP:
 			if (!who)
@@ -207,7 +219,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
 			else
 				pgrp = find_vpid(who);
 			do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
-				tmpio = get_task_ioprio(p);
+				tmpio = __get_task_ioprio(p);
 				if (tmpio < 0)
 					continue;
 				if (ret == -ESRCH)
@@ -230,7 +242,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
 				if (!uid_eq(task_uid(p), user->uid) ||
 				    !task_pid_vnr(p))
 					continue;
-				tmpio = get_task_ioprio(p);
+				tmpio = __get_task_ioprio(p);
 				if (tmpio < 0)
 					continue;
 				if (ret == -ESRCH)
diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index e9bfe6972aed..1384446c614d 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -90,6 +90,8 @@ extern int ioprio_best(unsigned short aprio, unsigned short bprio);
 
 extern int set_task_ioprio(struct task_struct *task, int ioprio);
 
+extern int get_task_ioprio(struct task_struct *p);
+
 #ifdef CONFIG_BLOCK
 extern int ioprio_check_cap(int ioprio);
 #else
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] block: add task priority to init bio iopriority
  2019-04-15  5:57 [PATCH 0/2] block: set per bio io-priority in blk-lib Chaitanya Kulkarni
  2019-04-15  5:57 ` [PATCH 1/2] block: adjust code for get_task_ioprio() Chaitanya Kulkarni
@ 2019-04-15  5:57 ` Chaitanya Kulkarni
  1 sibling, 0 replies; 3+ messages in thread
From: Chaitanya Kulkarni @ 2019-04-15  5:57 UTC (permalink / raw)
  To: linux-block; +Cc: Chaitanya Kulkarni

This uses the current process's ioprioty and initializes the bios
issued in the discard, write-zeroes and write-same operations.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 block/blk-lib.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 5f2c429d4378..12c340e7637c 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -7,6 +7,7 @@
 #include <linux/bio.h>
 #include <linux/blkdev.h>
 #include <linux/scatterlist.h>
+#include <linux/ioprio.h>
 
 #include "blk.h"
 
@@ -64,6 +65,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		bio->bi_iter.bi_sector = sector;
 		bio_set_dev(bio, bdev);
 		bio_set_op_attrs(bio, op, 0);
+		bio_set_prio(bio, get_task_ioprio(current));
 
 		bio->bi_iter.bi_size = req_sects << 9;
 		sector += req_sects;
@@ -162,6 +164,7 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
 		bio->bi_io_vec->bv_offset = 0;
 		bio->bi_io_vec->bv_len = bdev_logical_block_size(bdev);
 		bio_set_op_attrs(bio, REQ_OP_WRITE_SAME, 0);
+		bio_set_prio(bio, get_task_ioprio(current));
 
 		if (nr_sects > max_write_same_sectors) {
 			bio->bi_iter.bi_size = max_write_same_sectors << 9;
@@ -234,6 +237,8 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
 		bio->bi_iter.bi_sector = sector;
 		bio_set_dev(bio, bdev);
 		bio->bi_opf = REQ_OP_WRITE_ZEROES;
+		bio_set_prio(bio, get_task_ioprio(current));
+
 		if (flags & BLKDEV_ZERO_NOUNMAP)
 			bio->bi_opf |= REQ_NOUNMAP;
 
@@ -286,6 +291,7 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
 		bio->bi_iter.bi_sector = sector;
 		bio_set_dev(bio, bdev);
 		bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
+		bio_set_prio(bio, get_task_ioprio(current));
 
 		while (nr_sects != 0) {
 			sz = min((sector_t) PAGE_SIZE, nr_sects << 9);
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-15  5:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-15  5:57 [PATCH 0/2] block: set per bio io-priority in blk-lib Chaitanya Kulkarni
2019-04-15  5:57 ` [PATCH 1/2] block: adjust code for get_task_ioprio() Chaitanya Kulkarni
2019-04-15  5:57 ` [PATCH 2/2] block: add task priority to init bio iopriority Chaitanya Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).