From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 37E528017D for ; Wed, 14 Oct 2026 11:18:07 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69EBGtZl031165; Wed, 14 Oct 2026 14:16:56 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69EBGtZl031165 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="q3j5SlKt" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69EBGaiO031116 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 14 Oct 2026 14:16:36 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69EBGaiO031116 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48dee35b50aso341275f8f.2 for ; Wed, 14 Oct 2026 04:16:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBwl4FMqrE04aoPZO3mPCJexam26/QsdEuhWs9t/9LI/YIU7pLJqVM9yD9cF5Rmn7ZSQxo7TEA==@openvz.org X-Gm-Message-State: AFq9FYKwksupn+in/erQF4HkU56lqhncdivUpJpCoAagkf88gK5fWVVB 4WH203I4HeW4K7B9Ff83YV5F3IDlEsqjiYuI+K5R2ZxJRGiBqR3Yl5gUrE3FojkAYnCjBDFqvt4 /rG83rJVXRkun47xkDIInfv5aoKVWUQ3s9Cjm4GnQCqeBbLigNg7iHQ== X-Gm-Gg: AYBFou1frbhmSEiIrLZkPT6M2OtzVAL6D+a4XSvpMTSe/I4s2LwmA6fra5dRFFsvKW1 eSLdlayMjZsUScbNBw7k4YtXpim53Izke09G+szTzh5En8MYreabhxUPG9wxkO45XyoZSi+eMab iCXH6VDADA0CtWnt77OcMha2Xq5P5MunmTAoWiPhCL9kkaF9fEkKTSjuNncjWnYP15bYF/BxG24 Piouo+k5D4RF3WpkI3Ceb0AtT+/vh/G07HZfNITDVudHLe5GyxWNVb9PlAbKdmnJAZiUG6kOlpz IFVLquBGXmwXvetfNx9SZgCDkCZPTZ6k3fOS13diXPZNoSQ+9kgg00c/iAidxlBb4lL2YbW4qym 9pLE7ztJxS3cDna3Fqqprns/gtPkvDQ== X-Received: by 2002:a05:6000:400e:b0:48d:eb6b:9d12 with SMTP id ffacd0b85a97d-48deb6b9e7dmr2560079f8f.16.1791976596207; Wed, 14 Oct 2026 04:16:36 -0700 (PDT) X-Received: by 2002:a05:6000:400e:b0:48d:eb6b:9d12 with SMTP id ffacd0b85a97d-48deb6b9e7dmr2560014f8f.16.1791976595595; Wed, 14 Oct 2026 04:16:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791976595; cv=none; d=google.com; s=arc-20260327; b=GDvlRnEO0RF4y75SjDmJRY62c/wBS8feQ5O7HTWFSnveIBZbJq1bTTjB2QWDH3T+PL NQwii0rE+uEVgc9CCxMgUkGgrJKeed4bx+U4GjN9kts2/0PFjvYoYuHR6GeKJSCUpbjw A5b/yG/MXRYG3uveD+tkbBB1Jr69ukFlO0jR+x86AsVIEdpH+RohluJpePjadvdeQonS vsxjZJODYArjKWBgKdkxa3DGBP+XS23qHvP+KoAJFMHZNdOrOp7IEqszWKs9YJZ7KOJV h4S650Xrw4Vgo3rqKUr/R/xB6/EADykuRcZKMhsEjlCsai6xjcGlkIdOu5VufivnS2jX O49Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=vL8f9Duu1TZ3cCYejmOyEDLziUdbo9LRXf6jRN9L0eE=; fh=YUVjC/9FtpTN0Is9ifTJrOsbz/J/onroleA8inR1Ce8=; b=T/oFGjdQj39oTqLByJxsB0pUceSlQlCwJL5VNVQUwhK9HqSVmSBL9CVRawLBSQKiG8 8wpPCDtn1hLBTFWvnwJvRQ40A9awYynbqJMo2u/koZ5znd/yKn4IGZ1dUET4DZCsjNQC uPlDuloCqFQQTzurO1xCEOdAX+Yf+CwqQt/4PF2zmJqBHEGTipr6pNk4HQeaXuti3BQw i1MziGE6DLxIJB/ZfeA5nQNtLuzcgcExXt4IACfoFVO/G1p/jEsqiX5TtsScV4G64sGn Rd1WhKVd7TdDBo0AYXq0CI0WE+MtpwixdnMHnoY6tNxxuYHmQUfMMlVjT9dkEGhw6czP BHeQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=q3j5SlKt; spf=pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.almpanis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48de0965eefsi11206602f8f.35.2026.10.14.04.16.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2026 04:16:35 -0700 (PDT) Received-SPF: pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=q3j5SlKt; spf=pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.almpanis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=vL8f9Duu1TZ3cCYejmOyEDLziUdbo9LRXf6jRN9L0eE=; b=q3j5SlKtkao/N/Ty6/d +9G+aW/j7geqEezRVq7acObizqaLTGRlMW89KK1BQ/gK8AnuDaYJrZHyqtXWUforEdrFvykpU4a1F WRm5azcm3OjKNrv0i3A6/vjfknCb6GPkqpNG2JRZw8FJIXirOuPHU0G9CQz3vt8QOZdbaR2gTctVQ RgaTyEmBjCYnFw9C11RL5xZxkXjpw2/7hOKzaWltGNxkLz/6PQB8VyGiTIJGBUXjN2CL3JYMoMZUI vqgmAsmLYyI44QFPIB9DOQ4aBt0SnwnxAIoYcBiYq2Eh4AlPsxQyWyIjPtE9RfvhP7WfNOAlo9w/W 0Dljd/SfriOoLPg==; Received: from [130.117.225.5] (helo=dev010.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xGwus-001CVN-1N; Wed, 14 Oct 2026 13:16:34 +0200 From: Vasileios Almpanis Date: Wed, 14 Oct 2026 11:16:24 +0000 MIME-Version: 1.0 Message-Id: <20261014-ct-iowait-v1-1-9d65fe37cf89@virtuozzo.com> References: <20261014-ct-iowait-v1-0-9d65fe37cf89@virtuozzo.com> In-Reply-To: <20261014-ct-iowait-v1-0-9d65fe37cf89@virtuozzo.com> To: Konstantin Khorenko , Pavel Tikhomirov X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1791976595; l=4404; i=vasileios.almpanis@virtuozzo.com; s=20260812; h=from:subject:message-id; bh=OvuqaGosjr5uvKlb/arW977WyfrBP8l5ptEwVlQsG0Y=; b=BuyckDaulCn25RjlWMRIfM2306C3mBhV+ZQL+lsMonNm3rdCA9gT+ePyMoa4GIvoxTqeeAowz elBqhoZiXJBC057IqI9JVQSOYawnp5SXdbF/Hk0rPaMESq3KMRFaZ4t X-Developer-Key: i=vasileios.almpanis@virtuozzo.com; a=ed25519; pk=HhuHDXAcPva9A8zccWEMRsb36reu+y4IVbBjXKxNUjw= X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 1/4] sched: fix cfs_rq::nr_iowait leak on the remote wakeup path X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org try_to_wake_up() decrements cfs_rq::nr_iowait only after the p->on_cpu check. If the task's CPU is still in schedule(), the wakeup is queued with ttwu_queue_wakelist() and try_to_wake_up() returns early, so the counter is never decremented. It keeps growing and shows up as a bogus procs_blocked in the CT's /proc/stat: # grep procs_blocked /proc/stat procs_blocked 70 With NO_TTWU_QUEUE the leak goes away. Fix it by doing the decrement where rq::nr_iowait is handled: in try_to_wake_up() before set_task_cpu() for migrating wakeups, and in ttwu_do_activate() for all others, which also covers the wakelist. This way non migrating wakeups don't take the rq lock for it anymore. A task on the wakelist is TASK_WAKING but still counted, so add task_in_nr_iowait() and use it in sched_move_task() instead of skipping every TASK_WAKING task. https://virtuozzo.atlassian.net/browse/VSTOR-147823 Fixes: 415fe063c53e ("sched: Account cfs_rq::nr_iowait") Signed-off-by: Vasileios Almpanis Feature: sched: enhance task states granularity and accounting --- kernel/sched/core.c | 26 +++++++++++++------------- kernel/sched/sched.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 9275501bc3ad..dc016d264d19 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3775,6 +3775,8 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, if (p->in_iowait) { delayacct_blkio_end(p); atomic_dec(&task_rq(p)->nr_iowait); + if (p->sched_class->nr_iowait_dec) + p->sched_class->nr_iowait_dec(p); } if (p->sched_interruptible_sleep) @@ -4355,20 +4357,20 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) */ smp_cond_load_acquire(&p->on_cpu, !VAL); - if (p->in_iowait && p->sched_class->nr_iowait_dec) { - struct rq_flags rf; - struct rq *rq; - - rq = __task_rq_lock(p, &rf); - p->sched_class->nr_iowait_dec(p); - __task_rq_unlock(rq, &rf); - } - cpu = select_task_rq(p, p->wake_cpu, &wake_flags); if (task_cpu(p) != cpu) { if (p->in_iowait) { delayacct_blkio_end(p); atomic_dec(&task_rq(p)->nr_iowait); + /* On the old CPU, see also ttwu_do_activate() */ + if (p->sched_class->nr_iowait_dec) { + struct rq_flags rf; + struct rq *rq; + + rq = __task_rq_lock(p, &rf); + p->sched_class->nr_iowait_dec(p); + __task_rq_unlock(rq, &rf); + } } wake_flags |= WF_MIGRATED; @@ -9139,8 +9141,7 @@ void sched_move_task(struct task_struct *tsk, bool for_autogroup) if (queued) dequeue_task(rq, tsk, queue_flags); else { - if (!(READ_ONCE(tsk->__state) == TASK_WAKING) && tsk->in_iowait && - tsk->sched_class->nr_iowait_dec) + if (task_in_nr_iowait(tsk) && tsk->sched_class->nr_iowait_dec) tsk->sched_class->nr_iowait_dec(tsk); if (tsk->sched_contributes_to_load) @@ -9159,8 +9160,7 @@ void sched_move_task(struct task_struct *tsk, bool for_autogroup) if (queued) enqueue_task(rq, tsk, queue_flags); else { - if (!(READ_ONCE(tsk->__state) == TASK_WAKING) && tsk->in_iowait && - tsk->sched_class->nr_iowait_inc) + if (task_in_nr_iowait(tsk) && tsk->sched_class->nr_iowait_inc) tsk->sched_class->nr_iowait_inc(tsk); if (tsk->sched_contributes_to_load) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 2a3f73933456..176077ba4201 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2337,6 +2337,18 @@ static inline int task_on_rq_queued(struct task_struct *p) return READ_ONCE(p->on_rq) == TASK_ON_RQ_QUEUED; } +/* + * A sleeping iowait task stays counted in nr_iowait of its sched class until + * it is woken up: a migrating wakeup drops it in try_to_wake_up(), any other + * in ttwu_do_activate(), which for a wakelist wakeup runs later while the + * task is TASK_WAKING. Called with p->pi_lock and the task's rq lock held. + */ +static inline bool task_in_nr_iowait(struct task_struct *p) +{ + return p->in_iowait && !task_on_rq_queued(p) && + (READ_ONCE(p->__state) != TASK_WAKING || !p->sched_remote_wakeup); +} + static inline int task_on_rq_migrating(struct task_struct *p) { return READ_ONCE(p->on_rq) == TASK_ON_RQ_MIGRATING; -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel