From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70F71C3601E for ; Thu, 10 Apr 2025 14:36:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5AF7280106; Thu, 10 Apr 2025 10:36:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0A86280103; Thu, 10 Apr 2025 10:36:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AA51280106; Thu, 10 Apr 2025 10:36:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7D59F280103 for ; Thu, 10 Apr 2025 10:36:23 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 32BCA1A0CF7 for ; Thu, 10 Apr 2025 14:36:23 +0000 (UTC) X-FDA: 83318384646.27.D4619E3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 00BAD4000E for ; Thu, 10 Apr 2025 14:36:20 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gxUUXoKU; spf=pass (imf07.hostedemail.com: domain of gmonaco@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gmonaco@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744295781; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=S/upH0pTMSzQmCqeCJThNbVfgePuchqM9nG9SvDpQg8=; b=Nxh7LoMWGsdxvKsQdECDBdZFvZNebgtP0IKrlGV9YQufItHPgui2aUCqxgovRHF9KFKDdl ZG4zB9WtmrJk+yv+BMYlQ4ZIp0ZutHAMQEt5nvtJAgPz53DSU+4osiRu5uPQszr5tuPO+O fpbMLQlsee8v2pI3/7/7HszqDOYUbgY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gxUUXoKU; spf=pass (imf07.hostedemail.com: domain of gmonaco@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=gmonaco@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744295781; a=rsa-sha256; cv=none; b=DXbD5J845FGsBOLX3xJyhDAR0PcmQsAC+SI0ADBAvK76HFpTXzak0jStMvkf6O94E+Tdvj W1Uta64PmTO638b/jyuhNNBrVXYk6LuQDZG+bT45xEDhmI/ZAjkli6YQXxsHitIlpPdzzt 4pYb7Kf2vo0akJ7PRYDcT7pCACDu75w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744295780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=S/upH0pTMSzQmCqeCJThNbVfgePuchqM9nG9SvDpQg8=; b=gxUUXoKU6fS1N+NjBrUDrpm0axj/aYoi89R7WLL1uxJzZlPmhc4VtL6HuxExTBjx4000Ss q2iseDkAIf87riY29XC52qsz5faZOfm1/bi98jIEOk23RSBSMZoZ+EUxCJ/Dyhd0rGJHlS cGEUNfXY1fB72rVf5UBnpsDkBjFYWlA= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-arQPO5w0Pj2F5ToLkoZGzQ-1; Thu, 10 Apr 2025 10:36:17 -0400 X-MC-Unique: arQPO5w0Pj2F5ToLkoZGzQ-1 X-Mimecast-MFC-AGG-ID: arQPO5w0Pj2F5ToLkoZGzQ_1744295776 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43d734da1a3so5355615e9.0 for ; Thu, 10 Apr 2025 07:36:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744295776; x=1744900576; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=impxG+rtr5+xwnAKb7IYp+OHvXVcrzOLS0hW8AHHzXk=; b=DLCraaEYI8297AvYixpojrSsSWVhncCwkzDPBKdCHKh7iP5GQCnFg3NDpP58hlscUr 9fRZmsj8do33UMatQYgw11MlYo41em95PlqRvWy0iy4sJxMlWko/k3GqzJbKa5chT6wQ BvMBqYsjn5t2EKYx0GQInDLES6JZsE2C6ngTvm6h8D4XqZi/23pAYkAjoQHex4vVXrS3 ZV7NcfjFGObVyXIiQOyPqm4fJOxRindl5VlU9EnEjzWzl/yNiVdOSOTsqGES+B/cjQVm KSDLnLV6UJJPGD2NsrbfLLtwiArMmE8D72EMel+cvCggGBoLKUXebxra7Q/1bCVkiMe8 bxpg== X-Forwarded-Encrypted: i=1; AJvYcCXCB5sibmG16G7/WJIiZBhcxOfUb1kbCS07PQGi54tzriTbgFPRSuAzvWCK6TQ75Fkspf38yBQ6qw==@kvack.org X-Gm-Message-State: AOJu0YxG5wRO9YmrXx3NqjiBycsa4vxq7WRO7cTSHG1xbqQykweJq9So hafEnr0mM33/zBOEMb+0RcU84XZL9EOwVutaVQ5hqsraVx8o1DSTTGJ53XYcJlDRSyw/Nq6zMak vqo9NQ03KSnqm64B7trS+/8P/lV/D0muP7f2qg2u8WBSOyBZR X-Gm-Gg: ASbGncv/MtC3Tsb/YojEdphRm/IfdfTXMW7NuafcZWr6ZY7pxV6e7Qe+yeEU2KxlN7P WUIF6wCvK1GDrU0j5xSeMU4cRk7jUgh1xXW5of7rKsee9WkEMcC9Vb61TljU/l0gJMZmKaQOUjb D3EJDdBsnLJhAAdfy1/YBd9G1ZBtmFf5O316yA9yD5b4U53hH/yQLUGtblHK8CJou/CP4SyZzVe 5fWaAPM/28yymtSR8FYn9VaNAvvB1WPtzmhKbMBeiYXVQuZj4Ud/cuDH1kZk8rq/EWMaFRONwtw bh0oImbsdkYQ70976tkgFgY7wqWD6/QFcWrMtA== X-Received: by 2002:a05:6000:250d:b0:391:3f4f:a169 with SMTP id ffacd0b85a97d-39d8f498f95mr2584049f8f.32.1744295776060; Thu, 10 Apr 2025 07:36:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCJOPgecAC5fxqxZj6KPgi3BRYvP6lBrjMMlF2qGlsLctnElncQpvruKRwXSIG3Qp9ckLMpQ== X-Received: by 2002:a05:6000:250d:b0:391:3f4f:a169 with SMTP id ffacd0b85a97d-39d8f498f95mr2584028f8f.32.1744295775709; Thu, 10 Apr 2025 07:36:15 -0700 (PDT) Received: from gmonaco-thinkpadt14gen3.rmtit.csb ([185.107.56.40]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43f206269c8sm59613665e9.16.2025.04.10.07.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 07:36:15 -0700 (PDT) Message-ID: <2ecb20a38644c853d4f008e6e7f2215f9391e6e4.camel@redhat.com> Subject: Re: [PATCH] fixup: [PATCH v12 2/3] sched: Move task_mm_cid_work to mm work_struct From: Gabriele Monaco To: Mathieu Desnoyers , peterz@infradead.org, Ingo Molnar , linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, linux-mm@kvack.org, paulmck@kernel.org, shuah@kernel.org Date: Thu, 10 Apr 2025 16:36:13 +0200 In-Reply-To: <82c5e8c3-09a5-499a-bae2-7f5c70725a29@efficios.com> References: <20250410125030.215239-1-gmonaco@redhat.com> <82c5e8c3-09a5-499a-bae2-7f5c70725a29@efficios.com> Autocrypt: addr=gmonaco@redhat.com; prefer-encrypt=mutual; keydata=mDMEZuK5YxYJKwYBBAHaRw8BAQdAmJ3dM9Sz6/Hodu33Qrf8QH2bNeNbOikqYtxWFLVm0 1a0JEdhYnJpZWxlIE1vbmFjbyA8Z21vbmFjb0ByZWRoYXQuY29tPoiZBBMWCgBBFiEEysoR+AuB3R Zwp6j270psSVh4TfIFAmbiuWMCGwMFCQWjmoAFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgk Q70psSVh4TfJzZgD/TXjnqCyqaZH/Y2w+YVbvm93WX2eqBqiVZ6VEjTuGNs8A/iPrKbzdWC7AicnK xyhmqeUWOzFx5P43S1E1dhsrLWgP User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: inHOjFJq4sZydROuswxDuCEsT0X8WdPKt0Gjs5Kp7qU_1744295776 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 00BAD4000E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: uyfircer1woomputmsifjoahwzhpjbmq X-HE-Tag: 1744295780-23801 X-HE-Meta: U2FsdGVkX18MZuoXE85d/C8p/6UXXBLZ8Nj7ld9Qeue0g2F4GU1vbXMCr1pCsPHmB2j/jJecsilvSNSJhP61V2qVxvPC2ojXeNZ4TeeR6wcnEW2nM1OPD23E30Iiwx7TQB/oBU+61YC2YywfAD34Ueqx9O1qbQMaSoyP1XJi5fOkV599jnR1GGhCavRT2nHnq4lev8W7Pcz+fbQHeSeww4/oQnoKwKTWHfi+GtOtgIZZ7wNj163pqfbCUbNBSKqZCE45y7fePD9pzMfDAR3pU7dI6bk7O40PFbcp660oGs21eO8vu1JxEWeMG8+CbIr3hH7m8jqJSZoSD9l2EaH2vEOMq0hh0s6VMoRNVfkLV+PbH3tC6h5M3vxVW2l48Dmgf3LrIWgl+lmTwhpE8njVBifYp+fBUlt3NndVqo8hVyySKnjXU9Tog8dTAEQuzte7wd+8U/mFwv+vsKqqnT6+6zSDaN6z6CMI7omFQjRx+UsBD+Rj0R3rqsuOTBEOJGZHPqSRiJzD0JGbabtSrAT9WWudZgpe7qvqBUOFgHn/DSVe+ctThOqagcTu3lJweCuMR5MyxPVQb36nVgcrLiucy+C8spYjJiuHOQn/IZSKOAV/M7nuZoOtsVsWPJKm1kWeGYb7APNKBcs9SFsAtHT/GkXgHJHCjxnIeDYURfc+zmeUa7vHzSCbeudpaDO0XbbP3Thr3myLntQAO+nQPDW+tI+vo0bBLgOJNjBkUu57oqSi+39KZafyYh0DXKWr5ciAtwAGG7zlh0PbjzA3Bonzq8a/jztkYOK7LIpk5fz195l5Ft1BUXv0IvuDrN+g2YA3qh7sJEFDJBFDvx6VSjJUvUPmd51aIL9MMSuF1/br3q7K1K1wSQDt4dTAjieZG+fCacISFpkeKOFGfi3XBYjVYxNFnf7+IZg099xPH0kmACl5RBouwV+fyROJAvj5IemRYOirSkOu+wpRLEqPTiw 9QD7dE67 M8soZsfGLtu0smrAP1xDhWQbVzfbz6cK9gF4rPfYoOmL2GSo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, 2025-04-10 at 10:04 -0400, Mathieu Desnoyers wrote: > On 2025-04-10 08:50, Gabriele Monaco wrote: > > Thanks both for the comments, I tried to implement what Mathieu > > suggested. This patch applies directly on 2/3 but I'm sending it > > here > > first to get feedback. > >=20 > > Essentially, I refactored a bit to avoid the need to add more > > dependencies to rseq, the rseq_tick is now called task_tick_mm_cid > > (as > > before the series) and it does the two things you mentioned: > > =C2=A0 * A) trigger the mm_cid recompaction > > =C2=A0 * B) trigger an update of the task's rseq->mm_cid field at some > > point > > =C2=A0=C2=A0=C2=A0 after recompaction, so it can get a mm_cid value clo= ser to 0. > >=20 > > Now, A occurs only after the scan time elapsed, which means it > > could > > potentially run multiple times in case the work is not scheduled > > before > > the next tick, I'm not sure adding more checks to make sure it > > happens once and only once really makes sense here. >=20 > The scan is gated by two checks now: >=20 > > +=09if (t->mm && rtime > RSEQ_UNPREEMPTED_THRESHOLD) { > > +=09=09if (mm_cid_needs_scan(t->mm)) >=20 > And likewise for the periodic check for preemption: >=20 Alright, I could add another flag here to prevent re-scheduling, > > +=09if (t->mm && rtime > RSEQ_UNPREEMPTED_THRESHOLD) { > [...] > > +=09=09else if (time_after(jiffies, t->last_rseq_preempt > > + > > +=09=09=09=09=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 > > msecs_to_jiffies(MM_CID_SCAN_DELAY))) { >=20 > Those second levels of time checks would prevent adding significant > overhead on every tick after the threshold is reached. >=20 But I'm not sure what to do here: in my understanding, this second branch can only run once for task t and may run despite the previous path was skipped (let's assume two long running threads share the mm, the first thread schedules the work and it completes before the second threads meets a qualifying tick). > >=20 > > B is occurring after the work updates the last scan time, so we are > > in a > > condition where the runtime is above threshold but the (next) scan > > time > > did not expire yet. > > I tried to account for multiple threads updating the mm_cid (not > > necessarily the long running one, or in case more are long > > running), for > > this I'm tracking the last time we updated the mm_cid, if that > > occurred > > before the last mm_cid scan, we need to update (and preempt). > >=20 > > Does this make sense to you? >=20 > It makes sense. Note that it adds overhead to rseq_preempt() (a store > to t->last_rseq_preempt), which is a fast path. I don't know if we > should care. Well, I'm trying to track the last time a reset occurred, that happens rather in mm_cid_get, which doesn't look like a fast path to me. I could then rename it to last_rseq_reset since it won't be related to preemption. >=20 > Also part of task_tick_mm_cid could be moved to a helper, e.g.: >=20 > static > void task_reset_mm_cid(struct rq *rq, struct task_struct *t) > { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int old_cid =3D t->mm_ci= d; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!t->mm_cid_active) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 return; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mm_cid_snapshot_time(rq,= t->mm); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mm_cid_put_lazy(t); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 t->last_mm_cid =3D t->mm= _cid =3D mm_cid_get(rq, t, t->mm); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (old_cid =3D=3D t->mm= _cid) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 return; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rseq_preempt(t); > } Yeah good point Thanks, Gabriele