Re: [PATCH v2] block: invalidate cached plug timestamp after task switch
From: Peter Zijlstra
Date: Fri Jun 12 2026 - 11:41:09 EST
On Fri, Jun 12, 2026 at 11:02:58AM +0100, Usama Arif wrote:
>
>
> On 12/06/2026 10:45, Peter Zijlstra wrote:
> > On Fri, Jun 12, 2026 at 02:40:42AM -0700, Usama Arif wrote:
> >
> >> +static __always_inline void blk_plug_invalidate_ts(void)
> >> {
> >> + if (unlikely(current->flags & PF_BLOCK_TS)) {
> >> + struct blk_plug *plug = current->plug;
> >>
> >> + if (plug)
> >> + plug->cur_ktime = 0;
> >> + current->flags &= ~PF_BLOCK_TS;
> >> + }
> >> }
> >
> > If you can guarantee PF_BLOCK_TS is only ever set when current->plug,
> > this can be reduced further.
>
> Thanks for the reviews!
>
> The invariant holds at set time (the only set in blk_time_get_ns() is
> gated by if (!plug)) and through the only legitimate plug clear in
> blk_finish_plug() (which goes through __blk_flush_plug() that clears
> PF_BLOCK_TS first).
>
> However, copy_process() sets p->plug = NULL for the child but doesn't
> strip PF_BLOCK_TS from the inherited flags.
>
> I think the if(plug) is a good defensive check, but can also do the below
> if you prefer?
I think that's worth the extra few lines.