Skip to contentSkip to conversation

add /proc/*/pmap files

PATCH In review Albert Cahalan 6 participants 11 messages Jan 22, 2006

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

PATCH 1/1 add /proc/*/pmap files

This adds a few things needed by the pmap command. They show up in /proc/*/pmap files.

---

This applies to -git4, grabbed Saturday night.

History is being made I think, with the first /proc file to have a solidly documented syntax for future expansion and proper parsers.

If the patch doesn't make it to the list intact, somebody please give me a hand. Non-mangling email systems are getting to be kind of exotic these days. :-(

diff -Naurd old/Documentation/filesystems/proc/pmap new/Documentation/filesystems/proc/pmap
--- old/Documentation/filesystems/proc/pmap 1969-12-31
19:00:00.000000000 -0500
+++ new/Documentation/filesystems/proc/pmap 2006-01-22
03:42:59.000000000 -0500
@@ -0,0 +1,50 @@
+general grammar of a /proc/*/pmap file
+======================================
+
+The file consists of one line of text for every memory mapping. +Each line consists of several parts, delimited internally and +from each other by the ' ' (SPACE) character except as described +otherwise. From left to right the parts of a line are:
+
+1. general fields, supplied for every mapping
+2. a type indicator field
+3. type-specific fields
+4. a filename
+
+No general field will exceed 20 characters. No general field +will contain '_', '\\', '/', or whitespace. When future +requirements dictate additional general fields, they will be +added to the end (between the last existing general field and +the type indicator field).
+
+The type indicator field will start with the '_' character.
+The remainer will be composed of letters and numbers, but
+will not start with a number. The length will not exceed 8, +including the leading '_'.
+
+Type-specific fields will not contain whitespace, '/', or '\\'. +Unlike general fields, they may contain '_'. No type-specific +field will exceed 20 characters. Type-specific fields will
+vary in both meaning and number according to the type indicator. +There may be zero type-specific fields.
+
+The filename is encoded with '\\' (BACKSLASH) and '\n' (NEWLINE) +escaped as in the C language notation used here.
+
+The very first field of the line is itself extendable by adding +characters to the end. This is not allowed to violate the length +or character limits for a general field. Each position must have +a unique character associated with it, and must display as that +character or as the '-' (HYPHEN) character. This allows parsers +to rely on either position or character value.
+
+It is expected that parsers may:
+
+a. read general fields into an unprotected 20-byte buffer
+b. scan from the beginning for the '_' to determine type
+c. scan from the beginning for the '/' to find the filename
+d. scan from the beginning for the '\n' to find the end
+e. scan from the beginning using strchr() or similar
+f. scan field by field, skipping unknown fields
+g. parse the first field by character position
+h. parse the first field by characters seen
diff -Naurd old/Documentation/filesystems/proc.txt new/Documentation/filesystems/proc.txt
--- old/Documentation/filesystems/proc.txt 2006-01-21
14:42:13.000000000 -0500
+++ new/Documentation/filesystems/proc.txt 2006-01-22
03:27:05.000000000 -0500
@@ -134,6 +134,7 @@
status Process status in human readable form
wchan If CONFIG_KALLSYMS is set, a pre-decoded wchan
smaps Extension based on maps, presenting the rss size for each mapped file
+ pmap for pmap command; see Documentation/filesystems/proc/pmap
..............................................................................

For example, to get the status information of a process, all you have to do is

fs/proc/base.c 2006-01-21 19:45:32.000000000 -0500 renamed from fs/proc/base.c 2006-01-21 14:42:25.000000000 -0500 +31 -0
diff -Naurd old/fs/proc/base.c new/fs/proc/base.c
@@ -106,6 +106,7 @@
        PROC_TGID_MOUNTS,
        PROC_TGID_WCHAN,
 #ifdef CONFIG_MMU
+       PROC_TGID_PMAP,
        PROC_TGID_SMAPS,
 #endif
 #ifdef CONFIG_SCHEDSTATS
@@ -146,6 +147,7 @@
        PROC_TID_MOUNTS,
        PROC_TID_WCHAN,
 #ifdef CONFIG_MMU
+       PROC_TID_PMAP,
        PROC_TID_SMAPS,
 #endif
 #ifdef CONFIG_SCHEDSTATS
@@ -202,6 +204,7 @@
        E(PROC_TGID_EXE,       "exe",     S_IFLNK|S_IRWXUGO),
        E(PROC_TGID_MOUNTS,    "mounts",  S_IFREG|S_IRUGO),
 #ifdef CONFIG_MMU
+       E(PROC_TGID_PMAP,      "pmap",   S_IFREG|S_IRUGO),
        E(PROC_TGID_SMAPS,     "smaps",   S_IFREG|S_IRUGO),
 #endif
 #ifdef CONFIG_SECURITY
@@ -244,6 +247,7 @@
        E(PROC_TID_EXE,        "exe",     S_IFLNK|S_IRWXUGO),
        E(PROC_TID_MOUNTS,     "mounts",  S_IFREG|S_IRUGO),
 #ifdef CONFIG_MMU
+       E(PROC_TID_PMAP,       "pmap",    S_IFREG|S_IRUGO),
        E(PROC_TID_SMAPS,      "smaps",   S_IFREG|S_IRUGO),
 #endif
 #ifdef CONFIG_SECURITY
@@ -661,6 +665,27 @@
 };
 #endif
 
+#ifdef CONFIG_MMU
+extern struct seq_operations proc_pid_pmap_op;
+static int pmap_open(struct inode *inode, struct file *file)
+{
+       struct task_struct *task = proc_task(inode);
+       int ret = seq_open(file, &proc_pid_pmap_op);
+       if (!ret) {
+               struct seq_file *m = file->private_data;
+               m->private = task;
+       }
+       return ret;
+}
+
+static struct file_operations proc_pmap_operations = {
+       .open           = pmap_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release,
+};
+#endif
+
 extern struct seq_operations mounts_op;
 struct proc_mounts {
        struct seq_file m;
@@ -1730,6 +1755,12 @@
                        inode->i_fop = &proc_smaps_operations;
                        break;
 #endif
+#ifdef CONFIG_MMU
+               case PROC_TID_PMAP:
+               case PROC_TGID_PMAP:
+                       inode->i_fop = &proc_pmap_operations;
+                       break;
+#endif
 #ifdef CONFIG_SECURITY
                case PROC_TID_ATTR:
                        inode->i_nlink = 2;
fs/proc/task_mmu.c 2006-01-22 03:16:51.000000000 -0500 renamed from fs/proc/task_mmu.c 2006-01-21 14:42:25.000000000 -0500 +64 -0

67 lines not on this page · raw message

vma->vm_end >= mm->brk) {
+ seq_puts(m, "_heap");
+ } else {
+ if (vma->vm_start <= mm->start_stack
&& vma->vm_end >= mm->start_stack) {
+ seq_puts(m, "_stack");
+ } else {
+ seq_puts(m, "_other");
+ }
+ }
+ } else {
+ seq_puts(m, "_vdso");
+ }
+ }
+
+ seq_putc(m, '\n');
+
+ if (m->count < m->size) /* vma is copied successfully */
+ m->version = (vma != get_gate_vma(task))? vma->vm_start: 0;
+ return 0;
+}
+
static void *m_start(struct seq_file *m, loff_t *pos)

 {
        struct task_struct *task = m->private;

@@ -389,6 +473,13 @@
.show = show_smap
};

+struct seq_operations proc_pid_pmap_op = {

+       .start  = m_start,
+       .next   = m_next,
+       .stop   = m_stop,
+       .show   = show_pmap

+};
+
#ifdef CONFIG_NUMA
extern int show_numa_map(struct seq_file *m, void *v);

#1 lore raw
Quoted 3 lines

This applies to -git4, grabbed Saturday night.

with this much wrapping... no it doesn't ;-)

#2 lore raw
Quoted 3 lines · Arjan van de Ven
Quoted 1 line

This applies to -git4, grabbed Saturday night.

with this much wrapping... no it doesn't ;-)

Err, the patch looks fine to me. I just checked and I can't find any wrapped lines. Mail client confusion of some sort?

Cheers,
Kyle Moffett

--
Q: Why do programmers confuse Halloween and Christmas?
A: Because OCT 31 == DEC 25.

#3 lore raw
In reply to Albert Cahalan

Hi Albert,

On Sun, Jan 22, 2006 at 04:50:17AM -0500, Albert Cahalan wrote:
(...)

Quoted 3 lines

If the patch doesn't make it to the list intact, somebody please give me a hand. Non-mangling email systems are getting to be kind of exotic these days. :-(

It failed :

Quoted 6 lines

diff -Naurd old/Documentation/filesystems/proc/pmap new/Documentation/filesystems/proc/pmap
--- old/Documentation/filesystems/proc/pmap 1969-12-31
19:00:00.000000000 -0500
+++ new/Documentation/filesystems/proc/pmap 2006-01-22
03:42:59.000000000 -0500

You seem to have used a web interface, you might try to tune its options to accept very large lines (more than one hundred of chars). Also, you might try to attach it as text only, with some mailers, the file remains intact and does not need any decoding on the receiver side.

Regards,
Willy

#4 lore raw
In reply to Albert Cahalan
Quoted 3 lines

This adds a few things needed by the pmap command. They show up in /proc/*/pmap files.

But my pmap command works without the /proc/$$/pmap file?

Quoted 3 lines

If the patch doesn't make it to the list intact, somebody please give me a hand. Non-mangling email systems are getting to be kind of exotic these days. :-(

Send it as MIME attachment then :o)

Jan Engelhardt

#5 lore raw
Quoted 5 lines · Jan Engelhardt
Quoted 3 lines

This adds a few things needed by the pmap command. They show up in /proc/*/pmap files.

But my pmap command works without the /proc/$$/pmap file?

The -x option doesn't show locked memory, etc.

I'll still be missing a few things, but perhaps they just don't make sense for Linux today. Solaris has them.

For example, Solaris can report how much swap space each mapping has reserved and how much it has used. I don't think we remember per-mapping reservations yet AFAIK, Linux can't tell which mapping to blame if we run out of memory.

If mlock() might work on only part of a mapping, then a mere flag won't do. Adding this later is now easy, though the flag would need to remain.

Quoted 5 lines
Quoted 3 lines

If the patch doesn't make it to the list intact, somebody please give me a hand. Non-mangling email systems are getting to be kind of exotic these days. :-(

Send it as MIME attachment then :o)

Doesn't the mailing list trash posts with MIME? I still remember how to use uuencode though:

begin 644 diff.gz M'XL("/%&TT,"V1I9F8K5GY5^-&$O[9_BLZDY?!Q@>VN0(L9!S&^QP/0P[ MF;>3YR=++5L/75%+9LCN_._[5;5.8P))EAELJ5557?75V<)R;%MT+HTDLD3@ M6AOOS/QI!\;L1/X&[;C2O6H8NFIC3`*S(W0,T+ARX?7T-4[G<YK9=;Z>SM[ MG?Z@L]D7_;W]7@__N[WL1W1ZV[U>O=5JO7;OVJ#7V^GT^IW!0/0V][<&^]M[ M3^2]>X>+=D^T^NWMGGCWKMZ:25]&ABMFD>%Y1B0"6QA"2UW7MM-N]=;AJW[J MK7KK=BZ91YB!KQP5*Y(9^%*X#CYP'<NOL;"#2,B%C!Z%)[V`OHPP=/Q9M]X:
M&>9<$Y<E***&HJ$1Q:HM+.DZGA-+2SA^+"/?<-U'8?A6O65'@2<DR0CBN8S$ M]%'@6ZSA7V-\/3P>-84Y-R+#!)N07TT9QL)0$*C,R)E*2&"^!T?)KOAPEQI MQR(.1.3,YC$+8R4T5JRH$<E]LKW?%1F@MB-="XJJ)Q=!WJ6+-:FUEN#+@3$ MCZ&$$99C&C%(F*_>VNSR@XX*I>G8CIG*J[>VB(?P]0U/TIZ7075/\>"X+AN& M30>]PEC5%<NT]183^?8<'RQ-EEKB[4O7^ASQ]0YV$.D%5HF#CTUSZPD[B M),+&D?PM<2))40GP'!.Q"1PLRZ$0I8!:P@&P/6K5IN&(;0#IH2F]"W1F,KX M04(^+;B&BF$!7^8EJQC'Q/1*MR:W2P"5SW5VZL8SL-E/-=Q,5DK(.IJ9I@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GX\P?N(9DY?&&++E?XQ&+`*I'@``
`
end

#6 lore raw
In reply to Albert Cahalan
Quoted 2 lines · Albert Cahalan

This adds a few things needed by the pmap command. They show up in /proc/*/pmap files.

also since this shows filenames and such, could you make the permissions of the pmap file be 0400 ? (yes I know some others in the same dir aren't 0400 yet, but I hope that that can be changed in the future, adding more of these should be avoided for information-leak/exposure reasons)

#7 lore raw
Quoted 10 lines · Arjan van de Ven
Quoted 2 lines · Albert Cahalan

This adds a few things needed by the pmap command. They show up in /proc/*/pmap files.

also since this shows filenames and such, could you make the permissions of the pmap file be 0400 ? (yes I know some others in the same dir aren't 0400 yet, but I hope that that can be changed in the future, adding more of these should be avoided for information-leak/exposure reasons)

I thought it was the addresses you'd object to.

I was thinking I'd follow up with a patch to make things a bit more logical as far as info exposure goes. It makes no sense to have the /proc/*/exe link fail a readlink() when one can reliably guess that data from elsewhere.

I notice that Fedora Core 4 shipped with /proc/*/smaps files that were readable, but /proc/*/maps files that were not readable. (at least, a recent kernel update did)

As of now, I'm keeping mainstream kernel policy as is.

#8 lore raw
Quoted 6 lines · Albert Cahalan
Quoted 5 lines · Arjan van de Ven
Quoted 2 lines · Albert Cahalan

This adds a few things needed by the pmap command. They show up in /proc/*/pmap files.

Quoted 7 lines
Quoted 5 lines

also since this shows filenames and such, could you make the permissions of the pmap file be 0400 ? (yes I know some others in the same dir aren't 0400 yet, but I hope that that can be changed in the future, adding more of these should be avoided for information-leak/exposure reasons)

I thought it was the addresses you'd object to.

well both ;)

knowing that you're listening to Mrs Stefani's music rather than watching her music clips is something you might not want to spread to other users of your system. Or in other words, open files already disclose "private" stuff.

Quoted 3 lines

I notice that Fedora Core 4 shipped with /proc/*/smaps files that were readable, but /proc/*/maps files that were not readable. (at least, a recent kernel update did)

that'd be a mistake

Quoted 1 line

As of now, I'm keeping mainstream kernel policy as is.

you're making a NEW file, so there is no "mainstream policy" yet. Please do it right the first time so that it doesn't have to change later...

#9 lore raw
Quoted 2 lines · Arjan van de Ven

you're making a NEW file

One which, afaict, contains the same thing as /proc/pid/smaps only in a different format. If there's a point to this patch, we weren't told what it is.

#10 lore raw
Quoted 7 lines · Andrew Morton
Quoted 2 lines · Arjan van de Ven

you're making a NEW file

One which, afaict, contains the same thing as /proc/pid/smaps only in a different format. If there's a point to this patch, we weren't told what it is.

First of all, it isn't just the same. I need to know if memory is locked or not. I need to know the page size.

Second of all, smaps is surely a parody of bad file format design. When I first heard of the patch, I was certain that it would be rejected for that reason. At the time I was to sick and busy to even comment on the matter. It was with shock and horror that I later found the patch in the kernel.

I can't just fix smaps now, because that would break a rotten ABI. Patching it out should work OK though, because it is recent enough that apps will still support kernels without it. I would have done so with this patch, but you supposedly don't care for big patches.