Skip to contentSkip to conversation

Fix discard requests accounting in the diskstats

PATCH In review Nikanth Karthikesan 4 participants 6 messages Apr 17, 2009 – Apr 23, 2009 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix discard requests accounting in the diskstats

When 2 discard requests are merged, the stats gets updated, but we do not update statistics normally when a discard request is issued or completed. For example the in_flight counter would be decremented when 2 discard requests are merged, but it was not at all incremented when they were issued, and in_flight counter will not be decremented, when they are completed as well.

This patch fixes this by adding discard requests to the statistics.

---

block/blk-core.c +2 -2
index 07ab754..ee960a7 100644
@@ -68,7 +68,7 @@ static void drive_stat_acct(struct request *rq, int new_io)
 	int rw = rq_data_dir(rq);
 	int cpu;
 
-	if (!blk_fs_request(rq) || !blk_do_io_stat(rq))
+	if (!rq_accountable(rq) || !blk_do_io_stat(rq))
 		return;
 
 	cpu = part_stat_lock();
@@ -1698,7 +1698,7 @@ static void blk_account_io_done(struct request *req)
 	 * IO on queueing nor completion.  Accounting the containing
 	 * request is enough.
 	 */
-	if (blk_fs_request(req) && req != &req->q->bar_rq) {
+	if (rq_accountable(req) && req != &req->q->bar_rq) {
 		unsigned long duration = jiffies - req->start_time;
 		const int rw = rq_data_dir(req);
 		struct hd_struct *part;
include/linux/blkdev.h +3 -1
index ba54c83..9483c02 100644
@@ -667,7 +667,9 @@ static inline void blk_clear_queue_full(struct request_queue *q, int sync)
 	(REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER | REQ_SOFTBARRIER)
 #define rq_mergeable(rq)	\
 	(!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
-	 (blk_discard_rq(rq) || blk_fs_request((rq))))
+	 (blk_discard_rq(rq) || blk_fs_request(rq)))
+#define rq_accountable(rq)	\
+	(blk_discard_rq(rq) || blk_fs_request(rq))
 
 /*
  * q->prep_rq_fn return values
#1 lore raw
Quoted 7 lines · Nikanth Karthikesan

When 2 discard requests are merged, the stats gets updated, but we do not update statistics normally when a discard request is issued or completed. For example the in_flight counter would be decremented when 2 discard requests are merged, but it was not at all incremented when they were issued, and in_flight counter will not be decremented, when they are completed as well.

This patch fixes this by adding discard requests to the statistics.

This needs rebasing on top of this one:

http://lkml.org/lkml/2009/4/16/159

whenever that gets resubmitted as a proper, working patch.

Quoted 43 lines

---

block/blk-core.c +2 -2
index 07ab754..ee960a7 100644
@@ -68,7 +68,7 @@ static void drive_stat_acct(struct request *rq, int new_io)
 	int rw = rq_data_dir(rq);
 	int cpu;
 
-	if (!blk_fs_request(rq) || !blk_do_io_stat(rq))
+	if (!rq_accountable(rq) || !blk_do_io_stat(rq))
 		return;
 
 	cpu = part_stat_lock();
@@ -1698,7 +1698,7 @@ static void blk_account_io_done(struct request *req)
 	 * IO on queueing nor completion.  Accounting the containing
 	 * request is enough.
 	 */
-	if (blk_fs_request(req) && req != &req->q->bar_rq) {
+	if (rq_accountable(req) && req != &req->q->bar_rq) {
 		unsigned long duration = jiffies - req->start_time;
 		const int rw = rq_data_dir(req);
 		struct hd_struct *part;
include/linux/blkdev.h +3 -1
index ba54c83..9483c02 100644
@@ -667,7 +667,9 @@ static inline void blk_clear_queue_full(struct request_queue *q, int sync)
 	(REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER | REQ_SOFTBARRIER)
 #define rq_mergeable(rq)	\
 	(!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
-	 (blk_discard_rq(rq) || blk_fs_request((rq))))
+	 (blk_discard_rq(rq) || blk_fs_request(rq)))
+#define rq_accountable(rq)	\
+	(blk_discard_rq(rq) || blk_fs_request(rq))
 
 /*
  * q->prep_rq_fn return values
Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 8 lines · On Friday 17 April 2009 12:19:12 Jens Axboe wrote:
Quoted 7 lines · Nikanth Karthikesan

When 2 discard requests are merged, the stats gets updated, but we do not update statistics normally when a discard request is issued or completed. For example the in_flight counter would be decremented when 2 discard requests are merged, but it was not at all incremented when they were issued, and in_flight counter will not be decremented, when they are completed as well.

Quoted 8 lines
Quoted 1 line

This patch fixes this by adding discard requests to the statistics.

This needs rebasing on top of this one:

http://lkml.org/lkml/2009/4/16/159

whenever that gets resubmitted as a proper, working patch.

Ok. I will resend after Jerome resubmits that patch.

Thanks
Nikanth

Quoted 41 lines
Quoted 41 lines

---

block/blk-core.c +2 -2
index 07ab754..ee960a7 100644
@@ -68,7 +68,7 @@ static void drive_stat_acct(struct request *rq, int
 new_io) int rw = rq_data_dir(rq);
 	int cpu;
 
-	if (!blk_fs_request(rq) || !blk_do_io_stat(rq))
+	if (!rq_accountable(rq) || !blk_do_io_stat(rq))
 		return;
 
 	cpu = part_stat_lock();
@@ -1698,7 +1698,7 @@ static void blk_account_io_done(struct request
 *req) * IO on queueing nor completion.  Accounting the containing
 	 * request is enough.
 	 */
-	if (blk_fs_request(req) && req != &req->q->bar_rq) {
+	if (rq_accountable(req) && req != &req->q->bar_rq) {
 		unsigned long duration = jiffies - req->start_time;
 		const int rw = rq_data_dir(req);
 		struct hd_struct *part;
include/linux/blkdev.h +0 -0
index ba54c83..9483c02 100644
@@ -667,7 +667,9 @@ static inline void blk_clear_queue_full(struct

request_queue *q, int sync) (REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER
| REQ_SOFTBARRIER) #define rq_mergeable(rq) \

include/linux/blkdev.h +3 -1
 	(!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
-	 (blk_discard_rq(rq) || blk_fs_request((rq))))
+	 (blk_discard_rq(rq) || blk_fs_request(rq)))
+#define rq_accountable(rq)	\
+	(blk_discard_rq(rq) || blk_fs_request(rq))
 
 /*
  * q->prep_rq_fn return values
#3 lore raw
Quoted 11 lines · Nikanth Karthikesan
Quoted 10 lines · On Friday 17 April 2009 12:19:12 Jens Axboe wrote:
Quoted 8 lines · Nikanth Karthikesan

When 2 discard requests are merged, the stats gets updated, but we do not update statistics normally when a discard request is issued or completed. For example the in_flight counter would be decremented when 2 discard requests are merged, but it was not at all incremented when they were issued, and in_flight counter will not be decremented, when they are completed as well.

This patch fixes this by adding discard requests to the statistics.

Quoted 8 lines
Quoted 6 lines

This needs rebasing on top of this one:

http://lkml.org/lkml/2009/4/16/159

whenever that gets resubmitted as a proper, working patch.

Ok. I will resend after Jerome resubmits that patch.

There are more interesting issues with discard requests and elevators for now, such as the fact that elevators only actually prevent write requests from crossing each other on the queue if the {start,end} range precisely matches, not merely if they happen to overlap.

So all discard requests are submitted as soft barriers for now anyway.

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#4 lore raw
Quoted 19 lines · David Woodhouse
Quoted 18 lines · Nikanth Karthikesan
Quoted 16 lines · On Friday 17 April 2009 12:19:12 Jens Axboe wrote:
Quoted 8 lines · Nikanth Karthikesan

When 2 discard requests are merged, the stats gets updated, but we do not update statistics normally when a discard request is issued or completed. For example the in_flight counter would be decremented when 2 discard requests are merged, but it was not at all incremented when they were issued, and in_flight counter will not be decremented, when they are completed as well.

This patch fixes this by adding discard requests to the statistics.

This needs rebasing on top of this one:

http://lkml.org/lkml/2009/4/16/159

whenever that gets resubmitted as a proper, working patch.

Quoted 8 lines
Quoted 1 line

Ok. I will resend after Jerome resubmits that patch.

There are more interesting issues with discard requests and elevators for now, such as the fact that elevators only actually prevent write requests from crossing each other on the queue if the {start,end} range precisely matches, not merely if they happen to overlap.

So all discard requests are submitted as soft barriers for now anyway.

But they are still marked mergeable, so the accounting should be correct regardless.

Signature · 1 line
Jens Axboe
#5 lore raw
In reply to Nikanth Karthikesan

include/linux/blkdev.h static inline void blk_clear_queue_full(struct request_queue *q, int sync) · line 672

Quoted 10 lines · On Fri, 17 Apr 2009 11:44:49 +0530 Nikanth Karthikesan <[email protected]> wrote:
include/linux/blkdev.h +3 -1
@@ -667,7 +667,9 @@ static inline void blk_clear_queue_full(struct request_queue *q, int sync)
 	(REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER | REQ_SOFTBARRIER)
 #define rq_mergeable(rq)	\
 	(!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
-	 (blk_discard_rq(rq) || blk_fs_request((rq))))
+	 (blk_discard_rq(rq) || blk_fs_request(rq)))
+#define rq_accountable(rq)	\
+	(blk_discard_rq(rq) || blk_fs_request(rq))

Both these macros reference their argument multiple times and are potentially buggy and/or inefficient if passed an expression with side-effects.

There was (afaict) no reason for them to have been implemented as macros.