Skip to content

Commit

Permalink
delayacct: clear right task's flag after blkio completes
Browse files Browse the repository at this point in the history
When I was implementing a latency analyzer tool by using task->delays
and other things, I found an issue in delayacct.  The issue is it should
clear the target's flag instead of current's in delayacct_blkio_end().

When I git blame delayacct, I found there're some similar issues we have
fixed in delayacct_blkio_end().

 - Commit c96f547 ("delayacct: Account blkio completion on the
   correct task") fixed the issue that it should account blkio
   completion on the target task instead of current.

 - Commit b512719 ("delayacct: fix crash in delayacct_blkio_end()
   after delayacct init failure") fixed the issue that it should check
   target task's delays instead of current task'.

It seems that delayacct_blkio_{begin, end} are error prone.

So I introduce a new paratmeter - the target task 'p' - to these
helpers.  After that change, the callsite will specifilly set the right
task, which should make it less error prone.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Yafang Shao <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Josh Snyder <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
laoar authored and torvalds committed May 7, 2021
1 parent 6f1f942 commit 3d1c7fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions include/linux/delayacct.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
return 0;
}

static inline void delayacct_set_flag(int flag)
static inline void delayacct_set_flag(struct task_struct *p, int flag)
{
if (current->delays)
current->delays->flags |= flag;
if (p->delays)
p->delays->flags |= flag;
}

static inline void delayacct_clear_flag(int flag)
static inline void delayacct_clear_flag(struct task_struct *p, int flag)
{
if (current->delays)
current->delays->flags &= ~flag;
if (p->delays)
p->delays->flags &= ~flag;
}

static inline void delayacct_tsk_init(struct task_struct *tsk)
Expand All @@ -114,7 +114,7 @@ static inline void delayacct_tsk_free(struct task_struct *tsk)

static inline void delayacct_blkio_start(void)
{
delayacct_set_flag(DELAYACCT_PF_BLKIO);
delayacct_set_flag(current, DELAYACCT_PF_BLKIO);
if (current->delays)
__delayacct_blkio_start();
}
Expand All @@ -123,7 +123,7 @@ static inline void delayacct_blkio_end(struct task_struct *p)
{
if (p->delays)
__delayacct_blkio_end(p);
delayacct_clear_flag(DELAYACCT_PF_BLKIO);
delayacct_clear_flag(p, DELAYACCT_PF_BLKIO);
}

static inline int delayacct_add_tsk(struct taskstats *d,
Expand Down Expand Up @@ -166,9 +166,9 @@ static inline void delayacct_thrashing_end(void)
}

#else
static inline void delayacct_set_flag(int flag)
static inline void delayacct_set_flag(struct task_struct *p, int flag)
{}
static inline void delayacct_clear_flag(int flag)
static inline void delayacct_clear_flag(struct task_struct *p, int flag)
{}
static inline void delayacct_init(void)
{}
Expand Down
8 changes: 4 additions & 4 deletions mm/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
}


delayacct_set_flag(DELAYACCT_PF_SWAPIN);
delayacct_set_flag(current, DELAYACCT_PF_SWAPIN);
page = lookup_swap_cache(entry, vma, vmf->address);
swapcache = page;

Expand Down Expand Up @@ -3388,7 +3388,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
vmf->address, &vmf->ptl);
if (likely(pte_same(*vmf->pte, vmf->orig_pte)))
ret = VM_FAULT_OOM;
delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
delayacct_clear_flag(current, DELAYACCT_PF_SWAPIN);
goto unlock;
}

Expand All @@ -3402,13 +3402,13 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
* owner processes (which may be unknown at hwpoison time)
*/
ret = VM_FAULT_HWPOISON;
delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
delayacct_clear_flag(current, DELAYACCT_PF_SWAPIN);
goto out_release;
}

locked = lock_page_or_retry(page, vma->vm_mm, vmf->flags);

delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
delayacct_clear_flag(current, DELAYACCT_PF_SWAPIN);
if (!locked) {
ret |= VM_FAULT_RETRY;
goto out_release;
Expand Down

0 comments on commit 3d1c7fd

Please sign in to comment.