Skip to contentSkip to conversation

accouting: account if a task was killed by OOM killer

RFC PATCH In review Xiaotian Feng 2 participants 3 messages Jan 11, 2010 – Jan 14, 2010

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

RFC PATCH 1/1 accouting: account if a task was killed by OOM killer

This patch introduces a new accounting flag which is set when a task was killed by OOM killer. taskstats can tell users when a job has been killed by the oomkiller.

Cc Andrew Morton <[email protected]>
Cc Michal Schmidt <[email protected]>
Cc David Howells <[email protected]>
Cc Serge Hallyn <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Frans Pop <[email protected]>
---
 Documentation/accounting/taskstats-struct.txt |    2 +-
 include/linux/acct.h                          |    1 +
 include/linux/taskstats.h                     |    2 +-
 kernel/acct.c                                 |    2 ++
 kernel/tsacct.c                               |    2 ++
 5 files changed, 7 insertions(+), 2 deletions(-)
Documentation/accounting/taskstats-struct.txt +1 -1
index e7512c0..c3cf3cf 100644
@@ -45,7 +45,7 @@ struct taskstats {
 	__u32	ac_exitcode;		/* Exit status */
 
   	/* The accounting flags of a task as defined in <linux/acct.h>
-	 * Defined values are AFORK, ASU, ACOMPAT, ACORE, and AXSIG.
+	 * Defined values are AFORK, ASU, ACOMPAT, ACORE, AXSIG, and AXOOM.
 	 */
 	__u8	ac_flag;		/* Record flags */
 
include/linux/acct.h +1 -0
index 882dc72..bbb5d7c 100644
@@ -106,6 +106,7 @@ struct acct_v3
 #define ACOMPAT		0x04	/* ... used compatibility mode (VAX only not used) */
 #define ACORE		0x08	/* ... dumped core */
 #define AXSIG		0x10	/* ... was killed by a signal */
+#define AXOOM		0x20	/* ... was killed by OOM killer */
 
 #ifdef __BIG_ENDIAN
 #define ACCT_BYTEORDER	0x80	/* accounting file is big endian */
include/linux/taskstats.h +1 -1
index 341dddb..9d57f68 100644
@@ -47,7 +47,7 @@ struct taskstats {
 	__u32	ac_exitcode;		/* Exit status */
 
 	/* The accounting flags of a task as defined in <linux/acct.h>
-	 * Defined values are AFORK, ASU, ACOMPAT, ACORE, and AXSIG.
+	 * Defined values are AFORK, ASU, ACOMPAT, ACORE, AXSIG, and AXOOM.
 	 */
 	__u8	ac_flag;		/* Record flags */
 	__u8	ac_nice;		/* task_nice */
kernel/acct.c +2 -0
index a6605ca..5830423 100644
@@ -632,6 +632,8 @@ void acct_collect(long exitcode, int group_dead)
 		pacct->ac_flag |= ACORE;
 	if (current->flags & PF_SIGNALED)
 		pacct->ac_flag |= AXSIG;
+	if (test_tsk_thread_flag(current, TIF_MEMDIE))
+		pacct->ac_flag |= AXOOM;
 	pacct->ac_utime = cputime_add(pacct->ac_utime, current->utime);
 	pacct->ac_stime = cputime_add(pacct->ac_stime, current->stime);
 	pacct->ac_minflt += current->min_flt;
kernel/tsacct.c +2 -0
index 00d59d0..46a816a 100644
@@ -52,6 +52,8 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
 		stats->ac_flag |= ACORE;
 	if (tsk->flags & PF_SIGNALED)
 		stats->ac_flag |= AXSIG;
+	if (test_tsk_thread_flag(current, TIF_MEMDIE))
+		stats->ac_flag |= AXOOM;
 	stats->ac_nice	 = task_nice(tsk);
 	stats->ac_sched	 = tsk->policy;
 	stats->ac_pid	 = tsk->pid;
Signature · 1 line
1.6.5.2
#1 lore raw
Quoted 4 lines · On Mon, 11 Jan 2010 14:40:34 +0800 Xiaotian Feng <[email protected]> wrote:

This patch introduces a new accounting flag which is set when a task was killed by OOM killer. taskstats can tell users when a job has been killed by the oomkiller.

Why is this useful? I'd be looking for a description of some operational scenario where this feature is valuable to an operator?

The description is incomplete. The patch also alters the contents of the BSD accounting records. That's a change to an ancient interface and needs a bit of exposure and thought. Is it good to put such a highly linux-specific and somewhat linux-version-specific field into such a venerable userspace interface?

If we _do_ decide to change the BSD accounting records in this manner then presumably a manpage will need to be updated. A cc to [email protected] would be appropriate.

But I'm not very convinced about this whole idea at present, personally.

Quoted 4 lines
 include/linux/acct.h                          |    1 +
 include/linux/taskstats.h                     |    2 +-
 kernel/acct.c                                 |    2 ++
 kernel/tsacct.c                               |    2 ++

I'm a bit surprised that getdelays.c doesn't print ac_flag.

#2 lore raw
Quoted 11 lines · Andrew Morton
Quoted 4 lines · On Mon, 11 Jan 2010 14:40:34 +0800 Xiaotian Feng<[email protected]> wrote:

This patch introduces a new accounting flag which is set when a task was killed by OOM killer. taskstats can tell users when a job has been killed by the oomkiller.

Why is this useful? I'd be looking for a description of some operational scenario where this feature is valuable to an operator?

users of taskstats need to know if a job is killed by OOM killer, then perform some automation jobs or notifications. But current taskstats logs AXSIG if a job is killed by signal, so users will be confused by SIGKILL, SIGTERM or OOM killer.

Quoted 9 lines

The description is incomplete. The patch also alters the contents of the BSD accounting records. That's a change to an ancient interface and needs a bit of exposure and thought. Is it good to put such a highly linux-specific and somewhat linux-version-specific field into such a venerable userspace interface?

If we _do_ decide to change the BSD accounting records in this manner then presumably a manpage will need to be updated. A cc to [email protected] would be appropriate.

The BSD accounting part is not necessary, I just made it same as taskstats, we can drop BSD accounting part.

Quoted 12 lines

But I'm not very convinced about this whole idea at present, personally.

Quoted 4 lines
  include/linux/acct.h                          |    1 +
  include/linux/taskstats.h                     |    2 +-
  kernel/acct.c                                 |    2 ++
  kernel/tsacct.c                               |    2 ++

I'm a bit surprised that getdelays.c doesn't print ac_flag.