[Devel] [PATCH RH9 03/12] kernel: Account nr_zombie and nr_dead

Alexander Mikhalitsyn alexander.mikhalitsyn at virtuozzo.com
Thu Sep 23 14:31:27 MSK 2021


From: Kirill Tkhai <ktkhai at virtuozzo.com>

Extracted from "Initial patch".

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>

https://jira.sw.ru/browse/PSBM-133986

(cherry picked from commit b097bc8d02100cc6c8fa55433fc7a059b04c37fb)
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
 include/linux/sched.h |  3 +++
 kernel/exit.c         | 14 ++++++++++++++
 kernel/fork.c         |  1 +
 3 files changed, 18 insertions(+)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 7d8d66996ac6..3d67bb65bf77 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -219,6 +219,9 @@ struct ve_struct;
 /* Task command name length: */
 #define TASK_COMM_LEN			16
 
+extern atomic_t nr_dead;
+extern unsigned long nr_zombie;
+
 extern void scheduler_tick(void);
 
 #define	MAX_SCHEDULE_TIMEOUT		LONG_MAX
diff --git a/kernel/exit.c b/kernel/exit.c
index 9a89e7f36acb..c53bc727d01e 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -69,6 +69,12 @@
 #include <asm/unistd.h>
 #include <asm/mmu_context.h>
 
+unsigned long nr_zombie = 0;   /* protected by tasklist_lock */
+EXPORT_SYMBOL(nr_zombie);
+
+atomic_t nr_dead = ATOMIC_INIT(0);
+EXPORT_SYMBOL(nr_dead);
+
 static void __unhash_process(struct task_struct *p, bool group_dead)
 {
 	nr_threads--;
@@ -197,6 +203,8 @@ void release_task(struct task_struct *p)
 	ptrace_release_task(p);
 	thread_pid = get_pid(p->thread_pid);
 	__exit_signal(p);
+	nr_zombie--;
+	atomic_inc(&nr_dead);
 
 	/*
 	 * If we are the last non-leader member of the thread
@@ -689,6 +697,12 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 		list_add(&tsk->ptrace_entry, &dead);
 	}
 
+	/*
+	 * Increment nr_zombie even in case of EXIT_DEAD as
+	 * release_task() below expects that.
+	 */
+	nr_zombie++;
+
 	/* mt-exec, de_thread() is waiting for group leader */
 	if (unlikely(tsk->signal->notify_count < 0))
 		wake_up_process(tsk->signal->group_exit_task);
diff --git a/kernel/fork.c b/kernel/fork.c
index 44f4c2d83763..578635d75959 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -744,6 +744,7 @@ void __put_task_struct(struct task_struct *tsk)
 	put_signal_struct(tsk->signal);
 	sched_core_free(tsk);
 
+	atomic_dec(&nr_dead);
 	if (!profile_handoff_task(tsk))
 		free_task(tsk);
 }
-- 
2.31.1



More information about the Devel mailing list