From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B2BB24DCF7; Thu, 7 Aug 2025 12:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568884; cv=none; b=SbD2CkFHkK9ZnXVmE6ea+0HkEt6Gc6FmvXqqdBR6xLKbvF6WMaeyF+HpelhnwnQLoGPT/+Xs0Jp01MIwul4JbVx26vEFe/5+SIqQiBRtDk6bv4g4MrYwwQBXqyOApTvAlxSdx7rIwLD+1rKuI6Fjnjq0SUL4BLNdk/LA/zC0q1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568884; c=relaxed/simple; bh=gRVc2fe+3PNVteons7idTWlBfHRJwpmfsetmM1+rzHc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M9V/KxN841QD8yNAvrnWAwhr7dizkwM+NlUoZvSTDcAZH4LAlPHwZ51RuXPDZLDxC1Oz82zfrkbEAZE7HkTudJNMRv02BVLUFWKEUR2S68AjjTw1QplEPCT6+eX1NVZl4MBo3QVGr97yRITVSGMCCv5Vu6Q5SU6lrovFW736IcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 14f1d57c738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:bddde5a2-6be7-407d-9019-230d29b98340,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6493067,CLOUDID:ac141f20124bc38f4d6b4969aa6a8eef,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 14f1d57c738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 351858400; Thu, 07 Aug 2025 20:14:35 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id E6B70E01A758; Thu, 7 Aug 2025 20:14:34 +0800 (CST) X-ns-mid: postfix-689498AA-78502062 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id 39E6CE0000B0; Thu, 7 Aug 2025 20:14:31 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 1/9] freezer: Introduce freeze_priority field in task_struct Date: Thu, 7 Aug 2025 20:14:10 +0800 Message-Id: <20250807121418.139765-2-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To improve the flexibility and correctness of the freezer subsystem, we introduce a new field `freeze_priority` in `task_struct`. This field will allow us to assign different freezing priorities to tasks, enabling prioritized traversal in future changes. This is particularly useful when dealing with complex inter-process dependencies in modern userspace workloads (e.g., service managers, IPC daemons). Although this patch does not change behavior yet, it provides the necessary infrastructure for upcoming logic to address issues like dependency stalls and D-state hangs. It also helps avoid potential race conditions by paving the way for deterministic freezing order. Signed-off-by: Zihuan Zhang --- include/linux/freezer.h | 7 +++++++ include/linux/sched.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/include/linux/freezer.h b/include/linux/freezer.h index b303472255be..6314f8b68035 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h @@ -16,6 +16,13 @@ DECLARE_STATIC_KEY_FALSE(freezer_active); extern bool pm_freezing; /* PM freezing in effect */ extern bool pm_nosig_freezing; /* PM nosig freezing in effect */ =20 +enum freeze_priority { + FREEZE_PRIORITY_HIGH =3D 0, + FREEZE_PRIORITY_NORMAL =3D 1, + FREEZE_PRIORITY_LOW =3D 2, + FREEZE_PRIORITY_NEVER =3D 4 +}; + /* * Timeout for stopping processes */ diff --git a/include/linux/sched.h b/include/linux/sched.h index 2b272382673d..7915e6214e50 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -910,6 +910,9 @@ struct task_struct { unsigned int btrace_seq; #endif =20 +#ifdef CONFIG_FREEZER + unsigned int freeze_priority; +#endif unsigned int policy; unsigned long max_allowed_capacity; int nr_cpus_allowed; --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E4F024679F; Thu, 7 Aug 2025 12:14:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568891; cv=none; b=esXoVnuyVEzfkZIzGRlJbR+bJztT8UtxxWxxib0zbmSAUB6OwZzCMiE6VJpzqYf/tHLbmP0OyjQXNx/X0HDSA56qQu4Z4MfMrswEeLkO3Bb8ItZm/yVMLa6LCKAznl0E95JDMeeAbq35zwIsvP3OmxKKg0wQwtPScmXnAvN/d+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568891; c=relaxed/simple; bh=j07iyAToycsE4btEpeudiPUxo8gvKtTEhxlqrACMHkQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XaDYY3czxU5Ut3pfxYIyeJJP2dIXyRorXxMDffQHzYZ3pbpXpod3UY6DP3ghXHI3fIRZcVtSSzXDeubJkMee/BcE06KLkspxKSy9EMTEZaN8pokcBnvnKr+h/WwnGSHoAzK2YASt/liskEME3r72/pJoudy7uOL5cLdJyFK050o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 19c82fb0738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:322cbd87-c348-47e9-af03-2fa2b18264f3,IP:0,U RL:0,TC:0,Content:0,EDM:-25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:6493067,CLOUDID:0af04b9c10a64e090692712e5936fd26,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:1,IP:n il,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LE S:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 19c82fb0738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1586284648; Thu, 07 Aug 2025 20:14:43 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 0D4FAE01A759; Thu, 7 Aug 2025 20:14:43 +0800 (CST) X-ns-mid: postfix-689498AF-52865563 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id D10C1E0000B0; Thu, 7 Aug 2025 20:14:35 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 2/9] freezer: Introduce API to set per-task freeze priority Date: Thu, 7 Aug 2025 20:14:11 +0800 Message-Id: <20250807121418.139765-3-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces the basic API for setting freeze priority on a per-ta= sk basis. The actual usage and policy for assigning specific priorities will be added= in subsequent patches. This change lays the groundwork for implementing a more flexible and dependency-aware freezer model. Signed-off-by: Zihuan Zhang --- include/linux/freezer.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/freezer.h b/include/linux/freezer.h index 6314f8b68035..f231a60c3120 100644 --- a/include/linux/freezer.h +++ b/include/linux/freezer.h @@ -46,6 +46,18 @@ static inline bool freezing(struct task_struct *p) return false; } =20 +static inline bool freeze_set_default_priority(struct task_struct *p, unsi= gned int prio) +{ + if ((p->flags & PF_KTHREAD) || prio > FREEZE_PRIORITY_NEVER) + return false; + + p->freeze_priority =3D prio; + + pr_debug("set default freeze priority for comm:%s pid:%d prio:%d\n", + p->comm, p->pid, p->freeze_priority); + return true; +} + /* Takes and releases task alloc lock using task_lock() */ extern void __thaw_task(struct task_struct *t); =20 @@ -80,6 +92,7 @@ static inline bool cgroup_freezing(struct task_struct *ta= sk) #else /* !CONFIG_FREEZER */ static inline bool frozen(struct task_struct *p) { return false; } static inline bool freezing(struct task_struct *p) { return false; } +static inline bool freeze_set_default_priority(struct task_struct *p, unsi= gned int prio) {} static inline void __thaw_task(struct task_struct *t) {} =20 static inline bool __refrigerator(bool check_kthr_stop) { return false; } --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F34C7248F70; Thu, 7 Aug 2025 12:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568896; cv=none; b=TLt0aY47UbjOK3rJxqK05mRNYp7lXDZATSM9TBj3TuIwGXufbkm5MA64ZW4EEVPLMuczo3UGCYw8VW5HCLMn0C4OQZdtVBSGzQ2efcNOtiG817o7h09pl/3CMXxeVui3FJIY1RccUQnRRLEArk5V9AAm1Aw5JcakYektN/o8qOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568896; c=relaxed/simple; bh=skg7Gh50I2yTJaxeatlW2LApBTmyDPXHk6dT0btuKa4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sMGNep/t//Z05TCUy2A79aiDr0Dqu4zUJ+1F9yQTm2AoxlhgdVET7nXhdpTYkgkyiSw91uHNGBD9nLc/ET+qOpHWHpk5rEgMxO91zZ+TGuDOrWFiBXnYIccjSXbmk1FkHg3FXd6N79yck+VsEDBNUy15X18FWHMoLJBcctVzoLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 1c51a676738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:1cdd2b89-b372-4194-b9aa-70d3449c1a06,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:6493067,CLOUDID:d3db5b041da0d758e8aa142411b5b99e,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 1c51a676738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1097566653; Thu, 07 Aug 2025 20:14:47 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 1CB2CE01A758; Thu, 7 Aug 2025 20:14:47 +0800 (CST) X-ns-mid: postfix-689498B6-91481065 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id A4A8AE0000B0; Thu, 7 Aug 2025 20:14:43 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 3/9] freezer: Add per-priority layered freeze logic Date: Thu, 7 Aug 2025 20:14:12 +0800 Message-Id: <20250807121418.139765-4-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current freezer traverses all user tasks in a single pass, without distinguishing between tasks that are easier or harder to freeze. This uniform treatment may cause suboptimal behavior when certain newly created tasks, service daemons, or system threads block the progress of freeze due to dependency ordering issues. This patch introduces a simple multi-pass traversal model in try_to_freeze_tasks(), where user tasks are grouped and frozen by their freeze_priority in descending order. Tasks marked with higher priority are attempted earlier, which can help break dependency cycles earlier and reduce retry iterations. Specifically: - A new loop iterates over priority levels. - In each round, only tasks with freeze_priority < current priority are vi= sited. - The behavior applies only to user task freezing (when user_only =3D=3D t= rue). This approach preserves compatibility with the current logic, while enabling fine-grained control via future enhancements (e.g., dynamic priority tuning= ). Signed-off-by: Zihuan Zhang --- kernel/power/process.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/power/process.c b/kernel/power/process.c index dc0dfc349f22..06eafdb32abb 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c @@ -32,10 +32,12 @@ static int try_to_freeze_tasks(bool user_only) struct task_struct *g, *p; unsigned long end_time; unsigned int todo; + unsigned int round =3D 0; bool wq_busy =3D false; ktime_t start, end, elapsed; unsigned int elapsed_msecs; bool wakeup =3D false; + bool has_freezable_task; int sleep_usecs =3D USEC_PER_MSEC; =20 pr_info("Freezing %s\n", what); @@ -47,13 +49,18 @@ static int try_to_freeze_tasks(bool user_only) if (!user_only) freeze_workqueues_begin(); =20 - while (true) { + while (round < FREEZE_PRIORITY_NEVER) { todo =3D 0; + has_freezable_task =3D false; read_lock(&tasklist_lock); for_each_process_thread(g, p) { + if (user_only && !(p->flags & PF_KTHREAD) && round < p->freeze_priority) + continue; + if (p =3D=3D current || !freeze_task(p)) continue; =20 + has_freezable_task =3D true; todo++; } read_unlock(&tasklist_lock); @@ -63,6 +70,12 @@ static int try_to_freeze_tasks(bool user_only) todo +=3D wq_busy; } =20 + round++; + + /* sleep only if need to freeze tasks */ + if (user_only && !has_freezable_task) + continue; + if (!todo || time_after(jiffies, end_time)) break; =20 --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F348125A2DA; Thu, 7 Aug 2025 12:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568899; cv=none; b=CODlAvgjGQjlkGbGpk1KhmKCrS7bOmzuSJIukdmpVFFM+xxH4wXYJO5C9TdP1s+zuHCYcySVbiMRLOdpjFCv58m2Z71LOBlQzBzzDPBvy/k9eXZkXN3f8DcdnMjG64FExaA3hDn6gNWZ/LdAqCHW2gW73HyCJy4T+qKZaciZvYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568899; c=relaxed/simple; bh=+D+4U6y8lDfJCNvLyRYrz4+ASP1ZVSoxECednpKOg4w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NzeUjMfxXb12O5A9FtRnCHmqQWjfPtkXygF1IiIwcuVMH5QQjPDwweB6Jfz1pGiyoeX+RaQKCqvRH41s1efLEoKjqpjEEZRhmDcwUUbGxYUXN2QcstzM7Ga62GGPuHIpp26nsawnAruIeQtvw7WWf95GG66iQTqjEKfoetC218k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 1eaed2cc738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:c0d1405b-f86a-4b76-964c-fd303404ddc2,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6493067,CLOUDID:bd05ea79dd1398b27cc4daca19b4d0dc,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 1eaed2cc738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1109964960; Thu, 07 Aug 2025 20:14:51 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 4513CE01A758; Thu, 7 Aug 2025 20:14:51 +0800 (CST) X-ns-mid: postfix-689498BB-10757666 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id B9D61E0000B0; Thu, 7 Aug 2025 20:14:47 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 4/9] freezer: Set default freeze priority for userspace tasks Date: Thu, 7 Aug 2025 20:14:13 +0800 Message-Id: <20250807121418.139765-5-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The freezer framework now supports per-task freeze priorities. To ensure consistent behavior, this patch assigns a default freeze priority (FREEZE_PRIORITY_NORMAL) to all newly created userspace tasks. This helps maintain deterministic freezing order and prepares the ground for future enhancements based on priority-aware freezing logic. Kernel threads are not affected by this change, since they are excluded. Signed-off-by: Zihuan Zhang --- kernel/fork.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/fork.c b/kernel/fork.c index 9ce93fd20f82..04af5390af25 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2422,6 +2422,7 @@ __latent_entropy struct task_struct *copy_process( =20 copy_oom_score_adj(clone_flags, p); =20 + freeze_set_default_priority(p, FREEZE_PRIORITY_NORMAL); return p; =20 bad_fork_core_free: --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4477B25BEF8; Thu, 7 Aug 2025 12:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568904; cv=none; b=WV7yJZ2W3+5O7APZUxLs/IGuiiKYB7VNeqTwzYyVqWC6XpncE7cvzbjpAODzR2Bn14zBY6cq9Lx5XXh73Pp/PzCDDhqu5uG0p5CnTSU2PJGhSykKsuBrOzfHppT5kQxib4nHxpFNcRIxbZ5gEjlrVmg/FCcOy/UVL2tc5yKn6Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568904; c=relaxed/simple; bh=1k3Xoc4SLZQp+ojYSPnjMqj1UYbiAPh1DFzrfR5rr1o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dNmnZsWq5LhPB/1vqUf4tUJLeRRJ/qhS0WJyIv+fp8LmGQd6h0+dCj7hWyDyVQY+eXNht2UGdxQ7UGXBSjxmsjdTiPBAJ8bFKttCo3zRNCjHS21veaTEMFAgfEJV79Ad6hANcvQUlp+7jFr3ga5uOR0DzlA6RbfWkU9I8aPg8TY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 21419812738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:bb2b8d20-fc11-4a08-a86e-c3ccd7360bda,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6493067,CLOUDID:051d5319b82a10187433fbc93a60ff3c,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 21419812738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 2002267490; Thu, 07 Aug 2025 20:14:55 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 8F097E01A758; Thu, 7 Aug 2025 20:14:55 +0800 (CST) X-ns-mid: postfix-689498BF-34637367 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id 1DCC0E0000B0; Thu, 7 Aug 2025 20:14:52 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 5/9] freezer: set default freeze priority for PF_SUSPEND_TASK processes Date: Thu, 7 Aug 2025 20:14:14 +0800 Message-Id: <20250807121418.139765-6-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Tasks marked with PF_SUSPEND_TASK are involved in system suspend or hibernate operations. These tasks must not be frozen, as they are responsible for coordinating or executing parts of the suspend/resume sequence. This patch explicitly sets their freeze_priority to FREEZE_PRIORITY_NEVER during initialization. This makes their exemption from the freezer logic clear in the new freeze-priority model and avoids redundant evaluations during process traversal. Signed-off-by: Zihuan Zhang --- kernel/power/process.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/power/process.c b/kernel/power/process.c index 06eafdb32abb..21bbca7040cf 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c @@ -147,6 +147,7 @@ int freeze_processes(void) =20 pm_wakeup_clear(0); pm_freezing =3D true; + freeze_set_default_priority(current, FREEZE_PRIORITY_NEVER); error =3D try_to_freeze_tasks(true); if (!error) __usermodehelper_set_disable_depth(UMH_DISABLED); @@ -218,6 +219,7 @@ void thaw_processes(void) WARN_ON(!(curr->flags & PF_SUSPEND_TASK)); curr->flags &=3D ~PF_SUSPEND_TASK; =20 + freeze_set_default_priority(current, FREEZE_PRIORITY_NORMAL); usermodehelper_enable(); =20 schedule(); --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E59325392D; Thu, 7 Aug 2025 12:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568908; cv=none; b=qZ0ebwcM2XQzGaSOP4ApS/GsKDoJkLr/7xGUrGFk30YXdkVUbiPuv6AFiiqIWl8yxz1RJjlMbX0Xzh5MVHuqg/KJLkS3STe5vr2f8ChZEv8KXmbZSe31hGEdxWwGz3W4GiD7l+idLxlRLeOVTD49ZCBgyED6vsJOW9KSYM2drJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568908; c=relaxed/simple; bh=3GeUnTuI9VYv4J8qHSrp9VCfqL9y2LFf0Fxsh01NN9o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dzOLOmBG9UWNUhayiiAbqgHr8st0/++qX5cqXjq0xhxzWn+2EaBbG6iPIhbbxoxV/f6bK4uF2enSL/aedlEf2CPCFdPnfNSjDorwBeDI6VwugfY1gySqFRjw8NYh1GcYK0iVVO6sJSwJvUCIeB6dPmARMa4i1Yabusvx6yLI+vU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 24704682738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:1d12fb1f-37f4-4fb7-923e-1f3c2fe62e61,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6493067,CLOUDID:12a84b3772c0745d9275fc58a33b6108,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 24704682738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1815612336; Thu, 07 Aug 2025 20:15:01 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id E676AE01A758; Thu, 7 Aug 2025 20:15:00 +0800 (CST) X-ns-mid: postfix-689498C3-49482168 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id 3D9FFE0000B0; Thu, 7 Aug 2025 20:14:56 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 6/9] freezer: Set default freeze priority for zombie tasks Date: Thu, 7 Aug 2025 20:14:15 +0800 Message-Id: <20250807121418.139765-7-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Zombie processes are not subject to freezing, but they are still part of the global task list. During freeze traversal, tasks are examined for priority and eligibility, which may involve unnecessary locking even for non-freezable tasks like zombies. This patch assigns a default freeze priority to zombie tasks during exit, so that the freezer can skip priority setup and locking for them in subsequent iterations. This helps reduce overhead during freeze traversal, especially when many zombie processes exist in the system. Signed-off-by: Zihuan Zhang --- kernel/sched/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index be00629f0ba4..5a26d7511047 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -6980,6 +6981,7 @@ void __noreturn do_task_dead(void) current->flags |=3D PF_NOFREEZE; =20 __schedule(SM_NONE); + freeze_set_default_priority(current, FREEZE_PRIORITY_NEVER); BUG(); =20 /* Avoid "noreturn function does return" - but don't continue if BUG() is= a NOP: */ --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 622AD25F784; Thu, 7 Aug 2025 12:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568912; cv=none; b=aM0MsWkxUMUo0QxEox5afFV3Gp3PY/8wO2a9SXYreQvQM62PilLMIG/65eDcTUClBBZmQiqVO5a6Uxg++LnXvPmS709OvgCf2UL0o7n9X5q24DlnHIJtcrMTjv8QZE8F/yRwdZMBQ83BK58ecJ8nSy+bBdPuSO0a/OB9QyX9xO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568912; c=relaxed/simple; bh=sFimRWDFPtU0UMdeq9hQYUbd5AEv8F8fdClIH6UHJcg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AcmWORtAJqihJW2pAhV0Y4P2tiEwAyVPw8YuI5DJWX6GwBHAT4CTWpXDQUpw72TNHjbHft+NjAcVp5Pl4zJXpfv0QXkChB+ZUnAxA4iWLrgc9lWrlyNuJiiJP5+d9jH8aQVKlzC5hZn95nZuniIx/AUH5OoJNuckjR/9sxAOlPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 26cd0758738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:646277c4-9eba-4eb9-97cc-c44329b1bfc5,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6493067,CLOUDID:9863bd1b1b17eaa9329cc40525016c7a,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 26cd0758738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1728304931; Thu, 07 Aug 2025 20:15:05 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id DDDB5E01A758; Thu, 7 Aug 2025 20:15:04 +0800 (CST) X-ns-mid: postfix-689498C8-67532670 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id 76606E0000B0; Thu, 7 Aug 2025 20:15:01 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 7/9] freezer: raise freeze priority of tasks failed to freeze last time Date: Thu, 7 Aug 2025 20:14:16 +0800 Message-Id: <20250807121418.139765-8-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If there are tasks that fail to freeze in the current suspend attempt, we raise their freeze priority for the next attempt. This change ensures that such tasks are frozen earlier in the next round, helping to reduce retry counts and avoid persistent D-state tasks due to dependency misordering. Signed-off-by: Zihuan Zhang --- kernel/power/process.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/power/process.c b/kernel/power/process.c index 21bbca7040cf..9d3cbde905b9 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c @@ -111,8 +111,10 @@ static int try_to_freeze_tasks(bool user_only) if (!wakeup || pm_debug_messages_on) { read_lock(&tasklist_lock); for_each_process_thread(g, p) { - if (p !=3D current && freezing(p) && !frozen(p)) + if (p !=3D current && freezing(p) && !frozen(p)) { + freeze_set_default_priority(p, FREEZE_PRIORITY_HIGH); sched_show_task(p); + } } read_unlock(&tasklist_lock); } --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C45724E4C4; Thu, 7 Aug 2025 12:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568918; cv=none; b=RcBp2/9MWxJhEspMmtj2NZX8ZOgh1rFjCirXiQ2QM/gWiYJumQFRjcPVKYuQVs9JISDYDDH0t+4qTuhUjo/sxVF7AnozLzuAb8BAPrwQOawX38ae9U/htDh7FgeFPjloVVUlYX4esgTG9fKEzyCPSbrj9s/4jceRXWrmQ0BXsxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568918; c=relaxed/simple; bh=Y07qHfD4ZP5Bm0+LfEuCzbJWvBpVw2jBKzjVM++wXlU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kyLZLEmPF+StJxyYlX83ZniOfg3i8xoLSenyhfoPxi6PBfuuRx01cNpjUfsm2cSlmPMxgfSQjNaO6JrzPE7u1ZiJM7vVharGeD6qxolWPmrzZFAFnS0dqYSK4N+pprjvV8TkLiygcfuKBPC9ouYjP9GLfF0OYUFLQrNulRRriZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 2a575130738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:8d6ed8b6-5bb8-4587-9ed8-6f90c86146e6,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6493067,CLOUDID:9fe1de7d8afd90c484327fd77a29b260,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 2a575130738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1577606970; Thu, 07 Aug 2025 20:15:11 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id B8029E01A758; Thu, 7 Aug 2025 20:15:10 +0800 (CST) X-ns-mid: postfix-689498CD-2766471 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id 88C2FE0000B0; Thu, 7 Aug 2025 20:15:05 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 8/9] freezer: Add retry count statistics for freeze pass iterations Date: Thu, 7 Aug 2025 20:14:17 +0800 Message-Id: <20250807121418.139765-9-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Freezer retry loops during suspend are often triggered by tasks entering D-state (TASK_UNINTERRUPTIBLE), which cannot be frozen. This patch adds a simple retry counter to freeze_processes() to help quantify how many attempts were required before all tasks entered the frozen state. This is useful for performance tuning and debugging unpredictable suspend delays. A new dmesg log is added for visibility: freeze round: xx, tasks to freeze: xx This message allows users to correlate freeze instability with system state. Signed-off-by: Zihuan Zhang --- kernel/power/process.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/power/process.c b/kernel/power/process.c index 9d3cbde905b9..442d2ebba3ed 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c @@ -76,6 +76,8 @@ static int try_to_freeze_tasks(bool user_only) if (user_only && !has_freezable_task) continue; =20 + pr_info("freeze round: %d, task to freeze: %d\n", round, todo); + if (!todo || time_after(jiffies, end_time)) break; =20 --=20 2.25.1 From nobody Sun Oct 5 07:21:18 2025 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96467246779; Thu, 7 Aug 2025 12:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568925; cv=none; b=iH6dZstbC/ghJThPSObIf8tQGMCPVm6qvwxWB037khyCPMGHNF7EzoM220l6VMpJRlPjIxLRybD0MoMawcBMrG4dwQ9g0Rrwg7NGM0PLBgmd2Tb7dwkFtBTu3VInvS2gtKevT4ffaYlj431+CG3w9OvVJNJeeOPT6KrNmGuEkcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754568925; c=relaxed/simple; bh=l38keMA1spohuhmIndrpLKx86PGXdFzls9phBtXxR30=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LT1OVRQLWQHpLxHnMAmKnwZvbzAp1FZfJHC4NSqbHngoKPMIZ5bMXm1d4xs+XW1/CdMh+FzsIoBRsVf9ERzXb1aG+Me6ebuwtW9/PS+wjLk03o1arf1wQ8jaYRDGq1JkNBTaBM/xjHvhpamabsDJ5H0EGQitattrGrsJPZ7XNrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 2dda5884738811f0b29709d653e92f7d-20250807 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:c9f6a6e8-399a-490e-8347-7d1f4825cb24,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6493067,CLOUDID:6169b3659762d4f1f45ccf9d34c3b578,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3,IP: nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,L ES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 2dda5884738811f0b29709d653e92f7d-20250807 Received: from mail.kylinos.cn [(10.44.16.175)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1235472273; Thu, 07 Aug 2025 20:15:17 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 93F64E01A758; Thu, 7 Aug 2025 20:15:16 +0800 (CST) X-ns-mid: postfix-689498D4-37051772 Received: from localhost.localdomain (unknown [172.25.120.24]) by mail.kylinos.cn (NSMail) with ESMTPA id 07760E0000B0; Thu, 7 Aug 2025 20:15:12 +0800 (CST) From: Zihuan Zhang To: "Rafael J . Wysocki" , Peter Zijlstra , Oleg Nesterov , David Hildenbrand , Michal Hocko , Jonathan Corbet Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , len brown , pavel machek , Kees Cook , Andrew Morton , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Catalin Marinas , Nico Pache , xu xin , wangfushuai , Andrii Nakryiko , Christian Brauner , Thomas Gleixner , Jeff Layton , Al Viro , Adrian Ratiu , linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Zihuan Zhang Subject: [RFC PATCH v1 9/9] proc: Add /proc//freeze_priority interface Date: Thu, 7 Aug 2025 20:14:18 +0800 Message-Id: <20250807121418.139765-10-zhangzihuan@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250807121418.139765-1-zhangzihuan@kylinos.cn> References: <20250807121418.139765-1-zhangzihuan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces a new proc file `/proc/[pid]/freeze_priority` that allows reading and writing the freeze priority of a task. This is useful for process freezing mechanisms that wish to prioritize which tasks to freeze first during suspend or hibernation. To avoid misuse and for system integrity, userspace is not permitted to assign the `FREEZE_PRIORITY_NEVER` level to any task. Signed-off-by: Zihuan Zhang --- Documentation/filesystems/proc.rst | 14 ++++++- fs/proc/base.c | 64 ++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems= /proc.rst index 2971551b7235..4b7bc695b249 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -48,7 +48,8 @@ fixes/update part 1.1 Stefani Seibold June 9 2009 3.11 /proc//patch_state - Livepatch patch operation state 3.12 /proc//arch_status - Task architecture specific information 3.13 /proc//fd - List of symlinks to open files - 3.14 /proc//ksm_stat - Information about the process's ksm status + 3.15 /proc//freeze_priority - Information about freeze_priority. =20 4 Configuring procfs 4.1 Mount options @@ -2349,6 +2350,17 @@ applicable to KSM. More information about KSM can be found in Documentation/admin-guide/mm/ksm.rst. =20 +3.15 /proc//freeze_priority - Information about freeze_priority +----------------------------------------------------------------------- +This file exposes the `freeze_priority` value of a given task. + +The freezer subsystem uses `freeze_priority` to determine the order +in which tasks are frozen during suspend/hibernate. Tasks with +lower values are frozen earlier. Higher values defer the task to +later freeze rounds. + +Writing a value to this file allows user space to adjust the +priority of the task in the freezer traversal. =20 Chapter 4: Configuring procfs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D diff --git a/fs/proc/base.c b/fs/proc/base.c index 62d35631ba8c..724145356128 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -86,6 +86,7 @@ #include #include #include +#include #include #include #include @@ -3290,6 +3291,66 @@ static int proc_pid_ksm_stat(struct seq_file *m, str= uct pid_namespace *ns, } #endif /* CONFIG_KSM */ =20 +#ifdef CONFIG_FREEZER +static int freeze_priority_show(struct seq_file *m, void *v) +{ + struct inode *inode =3D m->private; + struct task_struct *p; + + p =3D get_proc_task(inode); + if (!p) + return -ESRCH; + + task_lock(p); + seq_printf(m, "%u\n", p->freeze_priority); + task_unlock(p); + + put_task_struct(p); + + return 0; +} + +static ssize_t freeze_priority_write(struct file *file, const char __user = *buf, + size_t count, loff_t *ppos) +{ + struct inode *inode =3D file_inode(file); + struct task_struct *p; + u64 freeze_priority; + int err; + + err =3D kstrtoull_from_user(buf, count, 10, &freeze_priority); + if (err < 0) + return err; + + if (freeze_priority >=3D FREEZE_PRIORITY_NEVER) + return -EINVAL; + + p =3D get_proc_task(inode); + if (!p) + return -ESRCH; + + task_lock(p); + p->freeze_priority =3D freeze_priority; + task_unlock(p); + + put_task_struct(p); + return count; +} + +static int freeze_priority_open(struct inode *inode, struct file *filp) +{ + return single_open(filp, freeze_priority_show, inode); +} + +static const struct file_operations proc_pid_freeze_priority =3D { + .open =3D freeze_priority_open, + .read =3D seq_read, + .write =3D freeze_priority_write, + .llseek =3D seq_lseek, + .release =3D single_release, +}; +#endif /* CONFIG_FREEZER */ + #ifdef CONFIG_KSTACK_ERASE_METRICS static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task) @@ -3407,6 +3468,9 @@ static const struct pid_entry tgid_base_stuff[] =3D { REG("timers", S_IRUGO, proc_timers_operations), #endif REG("timerslack_ns", S_IRUGO|S_IWUGO, proc_pid_set_timerslack_ns_operatio= ns), +#ifdef CONFIG_FREEZER + REG("freeze_priority", S_IRUGO|S_IWUSR, proc_pid_freeze_priority), +#endif #ifdef CONFIG_LIVEPATCH ONE("patch_state", S_IRUSR, proc_pid_patch_state), #endif --=20 2.25.1