Re: [PATCH] [RFC] List per-process file descriptor consumption when hitting file-max

From: Alexander Shishkin
Date: Wed Jul 29 2009 - 12:40:33 EST


2009/6/8 <alexander.shishckin@xxxxxxxxx>:
> From: Alexander Shishkin <alexander.shishckin@xxxxxxxxx>
>
> When a file descriptor limit is hit, it might be useful to see all the
> users to be able to identify those that leak descriptors.
Is there anything dramatically wrong with this one, or could someone
please review this?

> Signed-off-by: Alexander Shishkin <alexander.shishckin@xxxxxxxxx>
> ---
> Âfs/file_table.c | Â 27 +++++++++++++++++++++++++++
> Â1 files changed, 27 insertions(+), 0 deletions(-)
>
> diff --git a/fs/file_table.c b/fs/file_table.c
> index 54018fe..9e53167 100644
> --- a/fs/file_table.c
> +++ b/fs/file_table.c
> @@ -136,8 +136,35 @@ struct file *get_empty_filp(void)
> Âover:
> Â Â Â Â/* Ran out of filps - report that */
> Â Â Â Âif (get_nr_files() > old_max) {
> + Â Â Â Â Â Â Â struct task_struct *p;
> + Â Â Â Â Â Â Â struct files_struct *files;
> + Â Â Â Â Â Â Â struct fdtable *fdt;
> + Â Â Â Â Â Â Â int i, count = 0;
> +
> Â Â Â Â Â Â Â Âprintk(KERN_INFO "VFS: file-max limit %d reached\n",
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âget_max_files());
> +
> + Â Â Â Â Â Â Â read_lock(&tasklist_lock);
> + Â Â Â Â Â Â Â for_each_process(p) {
> + Â Â Â Â Â Â Â Â Â Â Â files = get_files_struct(p);
> + Â Â Â Â Â Â Â Â Â Â Â if (!files)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
> +
> + Â Â Â Â Â Â Â Â Â Â Â spin_lock(&files->file_lock);
> + Â Â Â Â Â Â Â Â Â Â Â fdt = files_fdtable(files);
> +
> + Â Â Â Â Â Â Â Â Â Â Â /* we have to actually *count* the fds */
> + Â Â Â Â Â Â Â Â Â Â Â for (count = i = 0; i < fdt->max_fds; i++)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â count += !!fcheck_files(files, i);
> +
> + Â Â Â Â Â Â Â Â Â Â Â printk(KERN_INFO "=> %s [%d]: %d\n", p->comm,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â p->pid, count);
> +
> + Â Â Â Â Â Â Â Â Â Â Â spin_unlock(&files->file_lock);
> + Â Â Â Â Â Â Â Â Â Â Â put_files_struct(files);
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â read_unlock(&tasklist_lock);
> +
> Â Â Â Â Â Â Â Âold_max = get_nr_files();
> Â Â Â Â}
> Â Â Â Âgoto fail;
> --
> 1.6.1.3
>
>

TIA,
--
Alex
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i