From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Gabriele Monaco <gmonaco@redhat.com>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
linux-mm@kvack.org
Cc: Ingo Molnar <mingo@redhat.org>
Subject: Re: [PATCH v14 2/3] sched: Move task_mm_cid_work to mm timer
Date: Mon, 7 Jul 2025 11:19:25 -0400 [thread overview]
Message-ID: <f83ff5f1-596e-4a94-8a87-4941bb1c431e@efficios.com> (raw)
In-Reply-To: <20250707144824.117014-3-gmonaco@redhat.com>
On 2025-07-07 10:48, Gabriele Monaco wrote:
[...]
>
> -void task_tick_mm_cid(struct rq *rq, struct task_struct *curr)
> +void task_queue_mm_cid(struct task_struct *curr)
> {
> - struct callback_head *work = &curr->cid_work;
> - unsigned long now = jiffies;
> + int requeued;
>
> - if (!curr->mm || (curr->flags & (PF_EXITING | PF_KTHREAD)) ||
> - work->next != work)
> - return;
> - if (time_before(now, READ_ONCE(curr->mm->mm_cid_next_scan)))
> - return;
> -
> - /* No page allocation under rq lock */
> - task_work_add(curr, work, TWA_RESUME);
> + /*
> + * @curr must be a user thread and the timer must not be pending.
> + * Access to this timer is not serialised across threads sharing the
> + * same mm: ensure racing threads don't postpone enqueued timers and
> + * don't mmgrab() if they didn't enqueue the timer themselves.
> + * mmgrab() is necessary to ensure the mm exists until the timer runs.
> + */
> + requeued = timer_reduce(&curr->mm->cid_timer,
> + jiffies + msecs_to_jiffies(MM_CID_SCAN_DELAY));
> + if (!requeued && timer_pending(&curr->mm->cid_timer))
> + mmgrab(curr->mm);
> }
>
In v13 we had:
- task_work_add(curr, work, TWA_RESUME);
+/* Call only when curr is a user thread. */
+void task_queue_mm_cid(struct task_struct *curr)
+{
+ /* Ensure the mm exists when we run. */
+ mmgrab(curr->mm);
+ queue_work(system_unbound_wq, &curr->mm->cid_work);
}
The new pattern is to do mmgrab *after* timer_reduce has enqueued
the timer. This seems to be racy with timer execution. What prevents
the timer to run before mmgrab() is done ?
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
next prev parent reply other threads:[~2025-07-07 15:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 14:48 [PATCH v14 0/3] sched: Restructure task_mm_cid_work for predictability Gabriele Monaco
2025-07-07 14:48 ` [PATCH v14 1/3] sched: Add prev_sum_exec_runtime support for RT, DL and SCX classes Gabriele Monaco
2025-07-07 14:48 ` [PATCH v14 2/3] sched: Move task_mm_cid_work to mm timer Gabriele Monaco
2025-07-07 15:19 ` Mathieu Desnoyers [this message]
2025-07-10 4:56 ` kernel test robot
2025-07-10 13:23 ` Mathieu Desnoyers
2025-07-10 13:40 ` Gabriele Monaco
2025-07-10 14:18 ` Mathieu Desnoyers
2025-07-10 13:47 ` Gabriele Monaco
2025-07-07 14:48 ` [PATCH v14 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=f83ff5f1-596e-4a94-8a87-4941bb1c431e@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=gmonaco@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=mingo@redhat.org \
--cc=paulmck@kernel.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
all inboxes | Powered by JetHome®