* [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status
@ 2017-09-07 11:17 Roman Gushchin
2017-09-13 22:05 ` Roman Gushchin
2017-09-14 22:44 ` Roman Gushchin
0 siblings, 2 replies; 7+ messages in thread
From: Roman Gushchin @ 2017-09-07 11:17 UTC (permalink / raw)
To: linux-kernel; +Cc: Roman Gushchin, Alexander Viro, Ingo Molnar, kernel-team
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: 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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status
2017-09-07 11:17 Roman Gushchin
@ 2017-09-13 22:05 ` Roman Gushchin
2017-09-14 22:44 ` Roman Gushchin
1 sibling, 0 replies; 7+ messages in thread
From: Roman Gushchin @ 2017-09-13 22:05 UTC (permalink / raw)
To: linux-kernel; +Cc: Alexander Viro, Ingo Molnar, kernel-team
On Thu, Sep 07, 2017 at 12:17:15PM +0100, 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.
>
Ping?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status
@ 2017-09-13 22:15 Alexey Dobriyan
2017-09-13 22:21 ` Roman Gushchin
0 siblings, 1 reply; 7+ messages in thread
From: Alexey Dobriyan @ 2017-09-13 22:15 UTC (permalink / raw)
To: Roman Gushchin; +Cc: linux-kernel
> 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.
Or add "State: C" ?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status
2017-09-13 22:15 [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status Alexey Dobriyan
@ 2017-09-13 22:21 ` Roman Gushchin
2017-09-13 22:46 ` Alexey Dobriyan
0 siblings, 1 reply; 7+ messages in thread
From: Roman Gushchin @ 2017-09-13 22:21 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-kernel
On Thu, Sep 14, 2017 at 01:15:26AM +0300, Alexey Dobriyan wrote:
> > 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.
>
> Or add "State: C" ?
A program in such state can also sleep and run, so it's not
a state in terms of process states.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status
2017-09-13 22:21 ` Roman Gushchin
@ 2017-09-13 22:46 ` Alexey Dobriyan
2017-09-13 23:07 ` Roman Gushchin
0 siblings, 1 reply; 7+ messages in thread
From: Alexey Dobriyan @ 2017-09-13 22:46 UTC (permalink / raw)
To: Roman Gushchin; +Cc: linux-kernel
On Wed, Sep 13, 2017 at 03:21:59PM -0700, Roman Gushchin wrote:
> On Thu, Sep 14, 2017 at 01:15:26AM +0300, Alexey Dobriyan wrote:
> > > 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.
> >
> > Or add "State: C" ?
>
> A program in such state can also sleep and run, so it's not
> a state in terms of process states.
Well, maybe something will break from seeing unknown process state.
Regardless, symlink /proc/$PID/coredump pointing to either "0" or "1"
is faster than open+read+parse+close.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status
2017-09-13 22:46 ` Alexey Dobriyan
@ 2017-09-13 23:07 ` Roman Gushchin
0 siblings, 0 replies; 7+ messages in thread
From: Roman Gushchin @ 2017-09-13 23:07 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-kernel
On Thu, Sep 14, 2017 at 01:46:43AM +0300, Alexey Dobriyan wrote:
> On Wed, Sep 13, 2017 at 03:21:59PM -0700, Roman Gushchin wrote:
> > On Thu, Sep 14, 2017 at 01:15:26AM +0300, Alexey Dobriyan wrote:
> > > > 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.
> > >
> > > Or add "State: C" ?
> >
> > A program in such state can also sleep and run, so it's not
> > a state in terms of process states.
>
> Well, maybe something will break from seeing unknown process state.
>
> Regardless, symlink /proc/$PID/coredump pointing to either "0" or "1"
> is faster than open+read+parse+close.
Performance doesn't really matter in this case: nobody should check
this flag often. An expected usecase is described above: check the flag
once before killing the process by timeout.
So, it doesn't look deserving a separate entity in procfs.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status
2017-09-07 11:17 Roman Gushchin
2017-09-13 22:05 ` Roman Gushchin
@ 2017-09-14 22:44 ` Roman Gushchin
1 sibling, 0 replies; 7+ messages in thread
From: Roman Gushchin @ 2017-09-14 22:44 UTC (permalink / raw)
To: linux-kernel
Cc: Alexander Viro, Ingo Molnar, kernel-team, Andrew Morton,
Oleg Nesterov
Adding Andrew Morton and Oleg Nesterov to cc.
On Thu, Sep 07, 2017 at 12:17:15PM +0100, 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: 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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-09-14 22:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-13 22:15 [RFC] proc, coredump: add CoreDumping flag to /proc/pid/status Alexey Dobriyan
2017-09-13 22:21 ` Roman Gushchin
2017-09-13 22:46 ` Alexey Dobriyan
2017-09-13 23:07 ` Roman Gushchin
-- strict thread matches above, loose matches on Subject: below --
2017-09-07 11:17 Roman Gushchin
2017-09-13 22:05 ` Roman Gushchin
2017-09-14 22:44 ` 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).