Skip to content

Commit b8e24a9

Browse files
hnazaxboe
authored andcommitted
block: annotate refault stalls from IO submission
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>
1 parent 73d9c8d commit b8e24a9

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

block/bio.c

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

807807
bio->bi_iter.bi_size += len;
808808
bio->bi_vcnt++;
809+
810+
if (!bio_flagged(bio, BIO_WORKINGSET) && unlikely(PageWorkingset(page)))
811+
bio_set_flag(bio, BIO_WORKINGSET);
809812
}
810813
EXPORT_SYMBOL_GPL(__bio_add_page);
811814

block/blk-core.c

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

4041
#define CREATE_TRACE_POINTS
4142
#include <trace/events/block.h>
@@ -1134,6 +1135,10 @@ EXPORT_SYMBOL_GPL(direct_make_request);
11341135
*/
11351136
blk_qc_t submit_bio(struct bio *bio)
11361137
{
1138+
bool workingset_read = false;
1139+
unsigned long pflags;
1140+
blk_qc_t ret;
1141+
11371142
if (blkcg_punt_bio_submit(bio))
11381143
return BLK_QC_T_NONE;
11391144

@@ -1152,6 +1157,8 @@ blk_qc_t submit_bio(struct bio *bio)
11521157
if (op_is_write(bio_op(bio))) {
11531158
count_vm_events(PGPGOUT, count);
11541159
} else {
1160+
if (bio_flagged(bio, BIO_WORKINGSET))
1161+
workingset_read = true;
11551162
task_io_account_read(bio->bi_iter.bi_size);
11561163
count_vm_events(PGPGIN, count);
11571164
}
@@ -1166,7 +1173,21 @@ blk_qc_t submit_bio(struct bio *bio)
11661173
}
11671174
}
11681175

1169-
return generic_make_request(bio);
1176+
/*
1177+
* If we're reading data that is part of the userspace
1178+
* workingset, count submission time as memory stall. When the
1179+
* device is congested, or the submitting cgroup IO-throttled,
1180+
* submission can be a significant part of overall IO time.
1181+
*/
1182+
if (workingset_read)
1183+
psi_memstall_enter(&pflags);
1184+
1185+
ret = generic_make_request(bio);
1186+
1187+
if (workingset_read)
1188+
psi_memstall_leave(&pflags);
1189+
1190+
return ret;
11701191
}
11711192
EXPORT_SYMBOL(submit_bio);
11721193

include/linux/blk_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ enum {
209209
BIO_BOUNCED, /* bio is a bounce bio */
210210
BIO_USER_MAPPED, /* contains user pages */
211211
BIO_NULL_MAPPED, /* contains invalid user pages */
212+
BIO_WORKINGSET, /* contains userspace workingset pages */
212213
BIO_QUIET, /* Make BIO Quiet */
213214
BIO_CHAIN, /* chained bio, ->bi_remaining in effect */
214215
BIO_REFFED, /* bio has elevated ->bi_cnt */

0 commit comments

Comments
 (0)