linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status
       [not found] <20170914224431.GA9735@castle>
@ 2017-09-20 23:06 ` Roman Gushchin
  2017-09-22 15:44   ` Konstantin Khlebnikov
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Roman Gushchin @ 2017-09-20 23:06 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Linus Torvalds, linux-mm, Roman Gushchin, Alexander Viro,
	Ingo Molnar, kernel-team, linux-kernel

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

Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: kernel-team@fb.com
Cc: linux-kernel@vger.kernel.org
---
 fs/proc/array.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 88c355574aa0..fc4a0aa7f487 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -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

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status
  2017-09-20 23:06 ` [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status Roman Gushchin
@ 2017-09-22 15:44   ` Konstantin Khlebnikov
  2017-09-22 17:18     ` Roman Gushchin
  2017-09-26 12:39   ` Roman Gushchin
  2017-09-27 23:31   ` Andrew Morton
  2 siblings, 1 reply; 6+ messages in thread
From: Konstantin Khlebnikov @ 2017-09-22 15:44 UTC (permalink / raw)
  To: Roman Gushchin
  Cc: Andrew Morton, Linus Torvalds, linux-mm, Alexander Viro,
	Ingo Molnar, kernel-team, Linux Kernel Mailing List,
	Oleg Nesterov

On Thu, Sep 21, 2017 at 2:06 AM, Roman Gushchin <guro@fb.com> 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.

Makes sense.

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

Add Oleg into CC.

>
> 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
>
> Signed-off-by: Roman Gushchin <guro@fb.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: kernel-team@fb.com
> Cc: linux-kernel@vger.kernel.org
> ---
>  fs/proc/array.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/fs/proc/array.c b/fs/proc/array.c
> index 88c355574aa0..fc4a0aa7f487 100644
> --- a/fs/proc/array.c
> +++ b/fs/proc/array.c
> @@ -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
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status
  2017-09-22 15:44   ` Konstantin Khlebnikov
@ 2017-09-22 17:18     ` Roman Gushchin
  0 siblings, 0 replies; 6+ messages in thread
From: Roman Gushchin @ 2017-09-22 17:18 UTC (permalink / raw)
  To: Konstantin Khlebnikov
  Cc: Andrew Morton, Linus Torvalds, linux-mm, Alexander Viro,
	Ingo Molnar, kernel-team, Linux Kernel Mailing List,
	Oleg Nesterov

On Fri, Sep 22, 2017 at 06:44:12PM +0300, Konstantin Khlebnikov wrote:
> On Thu, Sep 21, 2017 at 2:06 AM, Roman Gushchin <guro@fb.com> 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.
> 
> Makes sense.
> 
> Maybe print this line only when task actually makes dump?

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

> 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.

> 
> Add Oleg into CC.

Thank you!

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status
  2017-09-20 23:06 ` [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status Roman Gushchin
  2017-09-22 15:44   ` Konstantin Khlebnikov
@ 2017-09-26 12:39   ` Roman Gushchin
  2017-09-27 23:31   ` Andrew Morton
  2 siblings, 0 replies; 6+ messages in thread
From: Roman Gushchin @ 2017-09-26 12:39 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Linus Torvalds, linux-mm, Alexander Viro, Ingo Molnar,
	Oleg Nesterov, kernel-team, linux-kernel

Hi, Andrew!

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

Thank you!

On Wed, Sep 20, 2017 at 04:06:34PM -0700, Roman Gushchin 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
> 
> $ ./core.sh
>   CoreDumping:	0
>   CoreDumping:	1
> 
> Signed-off-by: Roman Gushchin <guro@fb.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: kernel-team@fb.com
> Cc: linux-kernel@vger.kernel.org
> ---
>  fs/proc/array.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/proc/array.c b/fs/proc/array.c
> index 88c355574aa0..fc4a0aa7f487 100644
> --- a/fs/proc/array.c
> +++ b/fs/proc/array.c
> @@ -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
> 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status
  2017-09-20 23:06 ` [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status Roman Gushchin
  2017-09-22 15:44   ` Konstantin Khlebnikov
  2017-09-26 12:39   ` Roman Gushchin
@ 2017-09-27 23:31   ` Andrew Morton
  2017-09-28 13:53     ` Roman Gushchin
  2 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2017-09-27 23:31 UTC (permalink / raw)
  To: Roman Gushchin
  Cc: Linus Torvalds, linux-mm, Alexander Viro, Ingo Molnar,
	kernel-team, linux-kernel

On Wed, 20 Sep 2017 16:06:34 -0700 Roman Gushchin <guro@fb.com> 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
> 
> $ ./core.sh
>   CoreDumping:	0
>   CoreDumping:	1

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

>  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...


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status
  2017-09-27 23:31   ` Andrew Morton
@ 2017-09-28 13:53     ` Roman Gushchin
  0 siblings, 0 replies; 6+ messages in thread
From: Roman Gushchin @ 2017-09-28 13:53 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Linus Torvalds, linux-mm, Alexander Viro, Ingo Molnar,
	kernel-team, linux-kernel

On Wed, Sep 27, 2017 at 04:31:06PM -0700, Andrew Morton wrote:
> On Wed, 20 Sep 2017 16:06:34 -0700 Roman Gushchin <guro@fb.com> 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
> > 
> > $ ./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.

> 
> >  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!

--

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-09-28 13:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20170914224431.GA9735@castle>
2017-09-20 23:06 ` [RESEND] proc, coredump: add CoreDumping flag to /proc/pid/status Roman Gushchin
2017-09-22 15:44   ` Konstantin Khlebnikov
2017-09-22 17:18     ` Roman Gushchin
2017-09-26 12:39   ` Roman Gushchin
2017-09-27 23:31   ` Andrew Morton
2017-09-28 13:53     ` Roman Gushchin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).