lkml.org 
[lkml]   [1997]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: /proc/memmap
On Wed, 17 Dec 1997, Marnix Coppens wrote:

> At 14:21 17/12/97 +0200, Craig Schlenter wrote:
> >
> >The one thing I haven't figured out is how to get from the inode to the
> >filename which would be nice ... you comment that this should be possible
> >given the dentry stuff in 2.1 but I can't see an obvious path to do this
> >looking at the 2.1 structures and code in the kernel.
>
> Have a look at how /proc/<pid>/maps does it in fs/proc/array.c
> Basically:
>
> buffer = (char *) __get_free_page(GFP_KERNEL);
> if (buffer && pdentry)
> {
> line = d_path(pdentry, buffer, PAGE_SIZE);
> free_page((unsigned long) buffer);

Is this a memory leak if pdentry is NULL? I've done it slightly
differently to avoid this.

> }
> else
> /* show dev, ino instead */
>
> d_path() is exported in fs/dcache.c. It is recommended that you pass it
[snip]

Excellent!!!

How about this then?

--- memmap.c 1997/12/15 15:23:03 1.3
+++ memmap.c 1997/12/17 15:14:01
@@ -148,10 +148,24 @@
line[len++] = 'b';
else if ((inomem = page->inode) != 0)
{
- len += sprintf(line + len, "c %08lx %3d %s %lu",
+
+ char *buffer = NULL;
+ buffer = (char *) __get_free_page(GFP_KERNEL);
+ if (buffer && inomem->i_mmap && inomem->i_mmap->vm_dentry)
+ {
+ char *dpath;
+ dpath = d_path(inomem->i_mmap->vm_dentry, buffer, PAGE_SIZE);
+ len += sprintf(line + len, "c %08lx %3d %s %s",
+ (unsigned long) inomem->i_mmap,
+ inomem->i_count,
+ kdevname(inomem->i_dev), dpath);
+ }
+ else
+ len += sprintf(line + len, "c %08lx %3d %s %lu",
(unsigned long) inomem->i_mmap,
inomem->i_count,
kdevname(inomem->i_dev), inomem->i_ino);
+ if ( buffer != NULL ) free_page((unsigned long) buffer);
}
else
line[len++] = 'u';

/proc/mempages looks quite impressive after this :)

It's been running all of 20 seconds on my machine now like this so YMMV.

Unfortunately d_path does not seem to be exported in fs/dcache.c by
default. I added a
#include <linux/config.h>
#include <linux/module.h>
and
EXPORT_SYMBOL(d_path);
to dcache.c and moved dcache.o from O_OBJS to
OX_OBJS := dcache.o
in the Makefile to get it exported in my kernel but given my ignorance
about modules that is probably not exactly the right way (TM) to do
things ...

Cheers,

--Craig


\
 
 \ /
  Last update: 2005-03-22 13:40    [W:0.040 / U:1.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site