Skip to content

Commit 06b23f9

Browse files
committed
block: update cached timestamp post schedule/preemption
Mark the task as having a cached timestamp when set assign it, so we can efficiently check if it needs updating post being scheduled back in. This covers both the actual schedule out case, which would've flushed the plug, and the preemption case which doesn't touch the plugged requests (for many reasons, one of them being then we'd need to have preemption disabled around plug state manipulation). Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent da4c8c3 commit 06b23f9

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

block/blk-core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,8 @@ void __blk_flush_plug(struct blk_plug *plug, bool from_schedule)
11831183
*/
11841184
if (unlikely(!rq_list_empty(plug->cached_rq)))
11851185
blk_mq_free_plug_rqs(plug);
1186+
1187+
current->flags &= ~PF_BLOCK_TS;
11861188
}
11871189

11881190
/**

block/blk.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,10 @@ static inline u64 blk_time_get_ns(void)
529529
* a valid timestamp" separately, just accept that we'll do an extra
530530
* ktime_get_ns() if we just happen to get 0 as the current time.
531531
*/
532-
if (!plug->cur_ktime)
532+
if (!plug->cur_ktime) {
533533
plug->cur_ktime = ktime_get_ns();
534+
current->flags |= PF_BLOCK_TS;
535+
}
534536
return plug->cur_ktime;
535537
}
536538

include/linux/blkdev.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,18 @@ static inline void blk_flush_plug(struct blk_plug *plug, bool async)
973973
__blk_flush_plug(plug, async);
974974
}
975975

976+
/*
977+
* tsk == current here
978+
*/
979+
static inline void blk_plug_invalidate_ts(struct task_struct *tsk)
980+
{
981+
struct blk_plug *plug = tsk->plug;
982+
983+
if (plug)
984+
plug->cur_ktime = 0;
985+
current->flags &= ~PF_BLOCK_TS;
986+
}
987+
976988
int blkdev_issue_flush(struct block_device *bdev);
977989
long nr_blockdev_pages(void);
978990
#else /* CONFIG_BLOCK */
@@ -996,6 +1008,10 @@ static inline void blk_flush_plug(struct blk_plug *plug, bool async)
9961008
{
9971009
}
9981010

1011+
static inline void blk_plug_invalidate_ts(struct task_struct *tsk)
1012+
{
1013+
}
1014+
9991015
static inline int blkdev_issue_flush(struct block_device *bdev)
10001016
{
10011017
return 0;

include/linux/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ extern struct pid *cad_pid;
16421642
#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_mask */
16431643
#define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */
16441644
#define PF_MEMALLOC_PIN 0x10000000 /* Allocation context constrained to zones which allow long term pinning. */
1645-
#define PF__HOLE__20000000 0x20000000
1645+
#define PF_BLOCK_TS 0x20000000 /* plug has ts that needs updating */
16461646
#define PF__HOLE__40000000 0x40000000
16471647
#define PF_SUSPEND_TASK 0x80000000 /* This thread called freeze_processes() and should not be frozen */
16481648

kernel/sched/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6787,10 +6787,12 @@ static inline void sched_submit_work(struct task_struct *tsk)
67876787

67886788
static void sched_update_worker(struct task_struct *tsk)
67896789
{
6790-
if (tsk->flags & (PF_WQ_WORKER | PF_IO_WORKER)) {
6790+
if (tsk->flags & (PF_WQ_WORKER | PF_IO_WORKER | PF_BLOCK_TS)) {
6791+
if (tsk->flags & PF_BLOCK_TS)
6792+
blk_plug_invalidate_ts(tsk);
67916793
if (tsk->flags & PF_WQ_WORKER)
67926794
wq_worker_running(tsk);
6793-
else
6795+
else if (tsk->flags & PF_IO_WORKER)
67946796
io_wq_worker_running(tsk);
67956797
}
67966798
}

0 commit comments

Comments
 (0)