The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Gabriele Monaco <gmonaco@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v13 2/3] sched: Move task_mm_cid_work to mm work_struct
Date: Tue, 20 May 2025 13:34:34 +0200	[thread overview]
Message-ID: <a1256a49992f1feabdcf36b286b6bd6dac94075d.camel@redhat.com> (raw)
In-Reply-To: <e53ac875-da6a-42ce-8714-d74f77775279@efficios.com>



On Mon, 2025-04-14 at 11:28 -0400, Mathieu Desnoyers wrote:
> On 2025-04-14 08:36, Gabriele Monaco wrote:
> > Currently, the task_mm_cid_work function is called in a task work
> > triggered by a scheduler tick to frequently compact the mm_cids of
> > each
> > process. This can delay the execution of the corresponding thread
> > for
> > the entire duration of the function, negatively affecting the
> > response
> > in case of real time tasks. In practice, we observe
> > task_mm_cid_work
> > increasing the latency of 30-35us on a 128 cores system, this order
> > of
> > magnitude is meaningful under PREEMPT_RT.
> > 
> > Run the task_mm_cid_work in a new work_struct connected to the
> > mm_struct rather than in the task context before returning to
> > userspace.
> > 
> > This work_struct is initialised with the mm and disabled before
> > freeing
> > it. The queuing of the work happens while returning to userspace in
> > __rseq_handle_notify_resume, maintaining the checks to avoid
> > running
> > more frequently than MM_CID_SCAN_DELAY.
> > To make sure this happens predictably also on long running tasks,
> > we
> > trigger a call to __rseq_handle_notify_resume also from the
> > scheduler
> > tick if the runtime exceeded a 100ms threshold.
> > 
> > The main advantage of this change is that the function can be
> > offloaded
> > to a different CPU and even preempted by RT tasks.
> > 
> > Moreover, this new behaviour is more predictable with periodic
> > tasks
> > with short runtime, which may rarely run during a scheduler tick.
> > Now, the work is always scheduled when the task returns to
> > userspace.
> > 
> > The work is disabled during mmdrop, since the function cannot sleep
> > in
> > all kernel configurations, we cannot wait for possibly running work
> > items to terminate. We make sure the mm is valid in case the task
> > is
> > terminating by reserving it with mmgrab/mmdrop, returning
> > prematurely if
> > we are really the last user while the work gets to run.
> > This situation is unlikely since we don't schedule the work for
> > exiting
> > tasks, but we cannot rule it out.
> 
> The implementation looks good to me. Peter, how does it look from
> your end ?
> 

Peter, Ingo, this could we bring this series in?

Thanks,
Gabriele


  parent reply	other threads:[~2025-05-20 11:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14 12:36 [PATCH v13 0/3] sched: Restructure task_mm_cid_work for predictability Gabriele Monaco
2025-04-14 12:36 ` [PATCH v13 1/3] sched: Add prev_sum_exec_runtime support for RT, DL and SCX classes Gabriele Monaco
2025-04-14 12:36 ` [PATCH v13 2/3] sched: Move task_mm_cid_work to mm work_struct Gabriele Monaco
2025-04-14 15:28   ` Mathieu Desnoyers
2025-04-22  9:27     ` Gabriele Monaco
2025-05-08  9:11     ` Gabriele Monaco
2025-05-20 11:34     ` Gabriele Monaco [this message]
2025-04-14 12:36 ` [PATCH v13 3/3] selftests/rseq: Add test for mm_cid compaction Gabriele Monaco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a1256a49992f1feabdcf36b286b6bd6dac94075d.camel@redhat.com \
    --to=gmonaco@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@redhat.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox