Skip to contentSkip to conversation

proc, coredump: add CoreDumping flag to /proc/pid/status

RFC Superseded Roman Gushchin 3 participants 9 messages Sep 7, 2017 – Sep 28, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 proc, coredump: add CoreDumping flag to /proc/pid/status

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Example:

$ cat core.sh
  #!/bin/sh

echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern sleep 1000 &
PID=$!

cat /proc/$PID/status | grep CoreDumping
kill -ABRT $PID
sleep 1
cat /proc/$PID/status | grep CoreDumping

$ ./core.sh
  CoreDumping:	0
  CoreDumping:	1
---
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/proc/array.c +6 -0
index 88c355574aa0..fc4a0aa7f487 100644
@@ -369,6 +369,11 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
 		   cpumask_pr_args(&task->cpus_allowed));
 }
 
+static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm)
+{
+	seq_printf(m, "CoreDumping:\t%d\n", !!mm->core_state);
+}
+
 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 			struct pid *pid, struct task_struct *task)
 {
@@ -379,6 +384,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 
 	if (mm) {
 		task_mem(m, mm);
+		task_core_dumping(m, mm);
 		mmput(mm);
 	}
 	task_sig(m, task);
Signature · 1 line
2.13.5
#1 lore raw
Quoted 10 lines · Roman Gushchin

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

Quoted 4 lines

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Ping?

#2 lore raw
In reply to Roman Gushchin

Adding Andrew Morton and Oleg Nesterov to cc.

Quoted 67 lines · Roman Gushchin

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Example:

$ cat core.sh
  #!/bin/sh

echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern sleep 1000 &
PID=$!

cat /proc/$PID/status | grep CoreDumping
kill -ABRT $PID
sleep 1
cat /proc/$PID/status | grep CoreDumping

$ ./core.sh
  CoreDumping:	0
  CoreDumping:	1
---
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/proc/array.c +6 -0
index 88c355574aa0..fc4a0aa7f487 100644
@@ -369,6 +369,11 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
 		   cpumask_pr_args(&task->cpus_allowed));
 }
 
+static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm)
+{
+	seq_printf(m, "CoreDumping:\t%d\n", !!mm->core_state);
+}
+
 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 			struct pid *pid, struct task_struct *task)
 {
@@ -379,6 +384,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 
 	if (mm) {
 		task_mem(m, mm);
+		task_core_dumping(m, mm);
 		mmput(mm);
 	}
 	task_sig(m, task);
Signature · 1 line
2.13.5
#3 lore raw

PATCH RESEND 1/1 proc, coredump: add CoreDumping flag to /proc/pid/status

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Example:

$ cat core.sh
  #!/bin/sh

echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern sleep 1000 &
PID=$!

cat /proc/$PID/status | grep CoreDumping
kill -ABRT $PID
sleep 1
cat /proc/$PID/status | grep CoreDumping

$ ./core.sh
  CoreDumping:	0
  CoreDumping:	1
---
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/proc/array.c +6 -0
index 88c355574aa0..fc4a0aa7f487 100644
@@ -369,6 +369,11 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
 		   cpumask_pr_args(&task->cpus_allowed));
 }
 
+static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm)
+{
+	seq_printf(m, "CoreDumping:\t%d\n", !!mm->core_state);
+}
+
 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 			struct pid *pid, struct task_struct *task)
 {
@@ -379,6 +384,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 
 	if (mm) {
 		task_mem(m, mm);
+		task_core_dumping(m, mm);
 		mmput(mm);
 	}
 	task_sig(m, task);
Signature · 7 lines
2.13.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw
Quoted 10 lines · Roman Gushchin

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

Quoted 3 lines

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Makes sense.

Maybe print this line only when task actually makes dump? And probably expose pid of coredump helper.

Add Oleg into CC.

Quoted 55 lines

Example:

$ cat core.sh
  #!/bin/sh

echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern sleep 1000 &
PID=$!

cat /proc/$PID/status | grep CoreDumping
kill -ABRT $PID
sleep 1
cat /proc/$PID/status | grep CoreDumping

$ ./core.sh
  CoreDumping:  0
  CoreDumping:  1
---
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/proc/array.c +6 -1
index 88c355574aa0..fc4a0aa7f487 100644
@@ -369,6 +369,11 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
                   cpumask_pr_args(&task->cpus_allowed));
 }
 
+static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm)
+{
+       seq_printf(m, "CoreDumping:\t%d\n", !!mm->core_state);
+}
+
 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
                        struct pid *pid, struct task_struct *task)
 {
@@ -379,6 +384,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 
        if (mm) {
                task_mem(m, mm);
+               task_core_dumping(m, mm);
                mmput(mm);
        }
        task_sig(m, task);
--

2.13.5

Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 11 lines · Konstantin Khlebnikov
Quoted 10 lines · Roman Gushchin

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

Quoted 7 lines
Quoted 3 lines

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Makes sense.

Maybe print this line only when task actually makes dump?

I don't think we do this trick with any other fields...

Quoted 1 line

And probably expose pid of coredump helper.

It will be racy in most cases, so I'm not sure it worth it. What's the usecase?
In any case, it sounds like a separate feature.

Quoted 2 lines

Add Oleg into CC.

Thank you!

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
In reply to Roman Gushchin

Hi, Andrew!

As there are no objections, can you, please, pick this patch?

Thank you!

Quoted 68 lines · Roman Gushchin

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Example:

$ cat core.sh
  #!/bin/sh

echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern sleep 1000 &
PID=$!

cat /proc/$PID/status | grep CoreDumping
kill -ABRT $PID
sleep 1
cat /proc/$PID/status | grep CoreDumping

$ ./core.sh
  CoreDumping:	0
  CoreDumping:	1
---
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/proc/array.c +6 -0
index 88c355574aa0..fc4a0aa7f487 100644
@@ -369,6 +369,11 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
 		   cpumask_pr_args(&task->cpus_allowed));
 }
 
+static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm)
+{
+	seq_printf(m, "CoreDumping:\t%d\n", !!mm->core_state);
+}
+
 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 			struct pid *pid, struct task_struct *task)
 {
@@ -379,6 +384,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
 
 	if (mm) {
 		task_mem(m, mm);
+		task_core_dumping(m, mm);
 		mmput(mm);
 	}
 	task_sig(m, task);
Signature · 1 line
2.13.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#7 lore raw
In reply to Roman Gushchin
Quoted 22 lines · On Wed, 20 Sep 2017 16:06:34 -0700 Roman Gushchin <[email protected]> wrote:

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Example:

$ cat core.sh
  #!/bin/sh

echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern sleep 1000 &
PID=$!

Quoted 8 lines

cat /proc/$PID/status | grep CoreDumping
kill -ABRT $PID
sleep 1
cat /proc/$PID/status | grep CoreDumping

$ ./core.sh
  CoreDumping:	0
  CoreDumping:	1

I assume you have some real-world use case which benefits from this.

Quoted 2 lines
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)

A Documentation/ would be appropriate? Include a brief mention of
*why* someone might want to use this...

#8 lore raw
Quoted 29 lines · Andrew Morton
Quoted 27 lines · On Wed, 20 Sep 2017 16:06:34 -0700 Roman Gushchin <[email protected]> wrote:

Right now there is no convenient way to check if a process is being coredumped at the moment.

It might be necessary to recognize such state to prevent killing the process and getting a broken coredump.
Writing a large core might take significant time, and the process is unresponsive during it, so it might be killed by timeout, if another process is monitoring and killing/restarting hanging tasks.

To provide an ability to detect if a process is in the state of being coreduped, we can expose a boolean CoreDumping flag in /proc/pid/status.

Example:

$ cat core.sh
  #!/bin/sh

echo "|/usr/bin/sleep 10" > /proc/sys/kernel/core_pattern sleep 1000 &
PID=$!

cat /proc/$PID/status | grep CoreDumping
kill -ABRT $PID
sleep 1
cat /proc/$PID/status | grep CoreDumping

Quoted 5 lines
Quoted 3 lines
$ ./core.sh
  CoreDumping:	0
  CoreDumping:	1

I assume you have some real-world use case which benefits from this.

Sure, we're getting a sensible number of corrupted coredump files on machines in our fleet, just because processes are being killed by timeout in the middle of the core writing process.

We do have a process health check, and some agent is responsible for restarting processes which are not responding for health check requests. Writing a large coredump to the disk can easily exceed the reasonable timeout (especially on an overloaded machine).

This flag will allow the agent to distinguish processes which are being coredumped, extend the timeout for them, and let them produce a full coredump file.

Quoted 8 lines
Quoted 3 lines
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)

A Documentation/ would be appropriate? Include a brief mention of
*why* someone might want to use this...

Here it is. Thank you!

--