Skip to content

Commit 4da7235

Browse files
hnazzhongjiang-ali
authored andcommitted
block: annotate refault stalls from IO submission
task #28327019 commit b8e24a9 upstream psi tracks the time tasks wait for refaulting pages to become uptodate, but it does not track the time spent submitting the IO. The submission part can be significant if backing storage is contended or when cgroup throttling (io.latency) is in effect - a lot of time is spent in submit_bio(). In that case, we underreport memory pressure. Annotate submit_bio() to account submission time as memory stall when the bio is reading userspace workingset pages. Tested-by: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: zhongjiang-ali <zhongjiang-ali@linux.alibaba.com> Reviewed-by: Xunlei Pang <xlpang@linux.alibaba.com>
1 parent 422652e commit 4da7235

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

block/bio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,9 @@ void __bio_add_page(struct bio *bio, struct page *page,
803803

804804
bio->bi_iter.bi_size += len;
805805
bio->bi_vcnt++;
806+
807+
if (!bio_flagged(bio, BIO_WORKINGSET) && unlikely(PageWorkingset(page)))
808+
bio_set_flag(bio, BIO_WORKINGSET);
806809
}
807810
EXPORT_SYMBOL_GPL(__bio_add_page);
808811

block/blk-core.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/blk-cgroup.h>
3636
#include <linux/debugfs.h>
3737
#include <linux/bpf.h>
38+
#include <linux/psi.h>
3839

3940
#define CREATE_TRACE_POINTS
4041
#include <trace/events/block.h>
@@ -2544,6 +2545,10 @@ EXPORT_SYMBOL_GPL(direct_make_request);
25442545
*/
25452546
blk_qc_t submit_bio(struct bio *bio)
25462547
{
2548+
bool workingset_read = false;
2549+
unsigned long pflags;
2550+
blk_qc_t ret;
2551+
25472552
/*
25482553
* If it's a regular read/write or a barrier with data attached,
25492554
* go through the normal accounting stuff before submission.
@@ -2559,6 +2564,8 @@ blk_qc_t submit_bio(struct bio *bio)
25592564
if (op_is_write(bio_op(bio))) {
25602565
count_vm_events(PGPGOUT, count);
25612566
} else {
2567+
if (bio_flagged(bio, BIO_WORKINGSET))
2568+
workingset_read = true;
25622569
task_io_account_read(bio->bi_iter.bi_size);
25632570
count_vm_events(PGPGIN, count);
25642571
}
@@ -2573,7 +2580,21 @@ blk_qc_t submit_bio(struct bio *bio)
25732580
}
25742581
}
25752582

2576-
return generic_make_request(bio);
2583+
/*
2584+
* If we're reading data that is part of the userspace
2585+
* workingset, count submission time as memory stall. When the
2586+
* device is congested, or the submitting cgroup IO-throttled,
2587+
* submission can be a significant part of overall IO time.
2588+
*/
2589+
if (workingset_read)
2590+
psi_memstall_enter(&pflags);
2591+
2592+
ret = generic_make_request(bio);
2593+
2594+
if (workingset_read)
2595+
psi_memstall_leave(&pflags);
2596+
2597+
return ret;
25772598
}
25782599
EXPORT_SYMBOL(submit_bio);
25792600

include/linux/blk_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ struct bio {
245245
#define BIO_TRACE_COMPLETION 10 /* bio_endio() should trace the final completion
246246
* of this bio. */
247247
#define BIO_QUEUE_ENTERED 11 /* can use blk_queue_enter_live() */
248+
#define BIO_WORKINGSET 12 /* contains userspace workingset pages */
248249

249250
/*
250251
* Extend bio flags should be added in here

0 commit comments

Comments
 (0)