Re: [PATCH 6/7] psi: pressure stall information for CPU, memory, and IO

Peter Zijlstra
2018-05-09T10:21:00Z

On Mon, May 07, 2018 at 05:01:34PM -0400, Johannes Weiner wrote:
> +/**
> + * psi_memstall_enter - mark the beginning of a memory stall section
> + * @flags: flags to handle nested sections
> + *
> + * Marks the calling task as being stalled due to a lack of memory,
> + * such as waiting for a refault or performing reclaim.
> + */
> +void psi_memstall_enter(unsigned long *flags)
> +{
> + struct rq_flags rf;
> + struct rq *rq;
> +
> + *flags = current->flags & PF_MEMSTALL;
> + if (*flags)
> + return;
> + /*
> + * PF_MEMSTALL setting & accounting needs to be atomic wrt
> + * changes to the task's scheduling state, otherwise we can
> + * race with CPU migration.
> + */
> + local_irq_disable();
> + rq = this_rq();
> + raw_spin_lock(&rq->lock);
> + rq_pin_lock(rq, &rf);

Given that churn in sched.h, you seen rq_lock() and friends.

Either write this like:

local_irq_disable();
rq = this_rq();
rq_lock(rq, &rf);

Or instroduce "rq = this_rq_lock_irq()", which we could also use in
do_sched_yield().

> + update_rq_clock(rq);
> +
> + current->flags |= PF_MEMSTALL;
> + psi_task_change(current, rq_clock(rq), 0, TSK_MEMSTALL);
> +
> + rq_unpin_lock(rq, &rf);
> + raw_spin_unlock(&rq->lock);
> + local_irq_enable();

That's called rq_unlock_irq().

> +}
> +
> +/**
> + * psi_memstall_leave - mark the end of an memory stall section
> + * @flags: flags to handle nested memdelay sections
> + *
> + * Marks the calling task as no longer stalled due to lack of memory.
> + */
> +void psi_memstall_leave(unsigned long *flags)
> +{
> + struct rq_flags rf;
> + struct rq *rq;
> +
> + if (*flags)
> + return;
> + /*
> + * PF_MEMSTALL clearing & accounting needs to be atomic wrt
> + * changes to the task's scheduling state, otherwise we could
> + * race with CPU migration.
> + */
> + local_irq_disable();
> + rq = this_rq();
> + raw_spin_lock(&rq->lock);
> + rq_pin_lock(rq, &rf);
> +
> + update_rq_clock(rq);
> +
> + current->flags &= ~PF_MEMSTALL;
> + psi_task_change(current, rq_clock(rq), TSK_MEMSTALL, 0);
> +
> + rq_unpin_lock(rq, &rf);
> + raw_spin_unlock(&rq->lock);
> + local_irq_enable();
> +}

Idem.