Re: [patch] oom: print triggering task's cpuset and mems allowed

Andrew Morton
2008-10-28T00:41:52Z

On Fri, 24 Oct 2008 17:15:32 -0700 (PDT)
David Rientjes <rientjes@google.com> wrote:

> +#ifdef CONFIG_CPUSETS
> +#define BUFFER_LEN (256)
> +
> +static void print_task_cpuset(struct task_struct *p)
> +{
> + char buffer[BUFFER_LEN];
> +
> + if (cpuset_get_name(p, BUFFER_LEN, buffer) > 0) {
> + char nodelist[BUFFER_LEN];
> +
> + nodelist_scnprintf(nodelist, BUFFER_LEN, p->mems_allowed);
> + printk(KERN_ERR "%s cpuset=%s mems_allowed=%s\n",
> + p->comm, buffer, nodelist);
> + }
> +}
> +#else
> +static inline void print_task_cpuset(struct task_struct *p)
> +{
> +}
> +#endif
> +
> /*
> * Send SIGKILL to the selected process irrespective of CAP_SYS_RAW_IO
> * flag though it's unlikely that we select a process with CAP_SYS_RAW_IO
> @@ -391,6 +412,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
> printk(KERN_WARNING "%s invoked oom-killer: "
> "gfp_mask=0x%x, order=%d, oomkilladj=%d\n",
> current->comm, gfp_mask, order, current->oomkilladj);
> + print_task_cpuset(current);
> dump_stack();
> show_mem();
> if (sysctl_oom_dump_tasks)

We can call the oom-killer at very very deep nesting levels, and adding
another 512 bytes of stack consuption to that call path is really
risky. Perhaps use statically allocated buffers protected by a local
spinlock?

Also, 256 bytes might be overkill for storing the cpuset's name?

Also, it's Just Wrong that this code has to hardwire private knowledge
of the max possible length of a cpuset name and of the
nodelist_scnprintf() return string. These things should be controlled
by a single #define in a shared header file.