Skip to content

Display memory mapped files for processes#7

Merged
propertone merged 6 commits intodeshaw:mainfrom
herbierand:memory-maps
Oct 14, 2025
Merged

Display memory mapped files for processes#7
propertone merged 6 commits intodeshaw:mainfrom
herbierand:memory-maps

Conversation

@herbierand
Copy link
Copy Markdown
Contributor

Resolves #4.

Copy link
Copy Markdown
Member

@propertone propertone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you compare the output of procfd and lsof for memory maps, procfd includes an extra entry for the executable. Is there a way to make them match? Also, I don't think it's correct to include mmaps for --type=path, it should be a separate filter.

@herbierand
Copy link
Copy Markdown
Contributor Author

Example of inspecting a bash process with procfd:

$ ./target/debug/procfd -p 252759
 PID    | User | Name | Type | FD  | Target
--------+------+------+------+-----+-----------------------------------------------------
 252759 | rand | bash | path | 0   | /dev/pts/1
 252759 | rand | bash | path | 1   | /dev/pts/1
 252759 | rand | bash | path | 2   | /dev/pts/1
 252759 | rand | bash | path | 255 | /dev/pts/1
 252759 | rand | bash | exe  |     | /usr/bin/bash
 252759 | rand | bash | cwd  |     | /home/rand/oss/procfd
 252759 | rand | bash | root |     | /
 252759 | rand | bash | mmap |     | /usr/lib/locale/locale-archive
 252759 | rand | bash | mmap |     | /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
 252759 | rand | bash | mmap |     | /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
 252759 | rand | bash | mmap |     | /usr/lib/x86_64-linux-gnu/libc.so.6
 252759 | rand | bash | mmap |     | /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4

Inspecting the same process with lsof:

$ lsof -p 252759
COMMAND    PID USER  FD   TYPE DEVICE SIZE/OFF     NODE NAME
bash    252759 rand cwd    DIR  259,7     4096  2930887 /home/rand/oss/procfd
bash    252759 rand rtd    DIR  259,7     4096        2 /
bash    252759 rand txt    REG  259,7  1380656 11666857 /usr/bin/bash
bash    252759 rand mem    REG  259,7  3063024 11670577 /usr/lib/locale/locale-archive
bash    252759 rand mem    REG  259,7  2003408 11678163 /usr/lib/x86_64-linux-gnu/libc.so.6
bash    252759 rand mem    REG  259,7   204088 11668749 /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4
bash    252759 rand mem    REG  259,7    27028 11678152 /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
bash    252759 rand mem    REG  259,7   225600 11678160 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
bash    252759 rand   0u   CHR  136,1      0t0        4 /dev/pts/1
bash    252759 rand   1u   CHR  136,1      0t0        4 /dev/pts/1
bash    252759 rand   2u   CHR  136,1      0t0        4 /dev/pts/1
bash    252759 rand 255u   CHR  136,1      0t0        4 /dev/pts/1

Filtering with --type mmap:

$ ./target/debug/procfd -p 252759 --type mmap
 PID    | User | Name | Type | FD | Target
--------+------+------+------+----+-----------------------------------------------------
 252759 | rand | bash | mmap |    | /usr/lib/locale/locale-archive
 252759 | rand | bash | mmap |    | /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
 252759 | rand | bash | mmap |    | /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
 252759 | rand | bash | mmap |    | /usr/lib/x86_64-linux-gnu/libc.so.6
 252759 | rand | bash | mmap |    | /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4

Grepping for mem with lsof:

$ lsof -p 252759 | grep mem
bash    252759 rand mem    REG  259,7  3063024 11670577 /usr/lib/locale/locale-archive
bash    252759 rand mem    REG  259,7  2003408 11678163 /usr/lib/x86_64-linux-gnu/libc.so.6
bash    252759 rand mem    REG  259,7   204088 11668749 /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4
bash    252759 rand mem    REG  259,7    27028 11678152 /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
bash    252759 rand mem    REG  259,7   225600 11678160 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for displaying memory-mapped files for processes by implementing a new "mmap" file descriptor type. This enhancement allows users to view which files are memory-mapped by each process, providing additional insight into process resource usage.

  • Adds MMap variant to FDType and FDTarget enums
  • Implements memory map querying and filtering functionality
  • Excludes process executables from memory map results to avoid duplication

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@propertone propertone merged commit 7393434 into deshaw:main Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show memory maps

3 participants