Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crit: add method to retrieve shared memory size of process #146

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

behouba
Copy link
Contributor

@behouba behouba commented Aug 11, 2023

This PR aims to add a method for retrieving the size of shared memory of processes. The function iterates over the virtual memory areas (VMAs) associated with the process, summing up the sizes of VMAs with the MAP_SHARED flag.

@rst0git PTAL, is this approach accurate ?

@behouba behouba changed the title crit: add function to retrieve shared memory size of process crit: add method to retrieve shared memory size of process Aug 11, 2023
@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Patch coverage: 77.50% and project coverage change: +1.01% 🎉

Comparison is base (2210c02) 49.49% compared to head (02d11ab) 50.50%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #146      +/-   ##
==========================================
+ Coverage   49.49%   50.50%   +1.01%     
==========================================
  Files          24       24              
  Lines        2760     2865     +105     
==========================================
+ Hits         1366     1447      +81     
- Misses       1203     1220      +17     
- Partials      191      198       +7     
Files Changed Coverage Δ
crit/mempages.go 93.54% <76.92%> (-1.95%) ⬇️
test/crit/main.go 62.28% <77.57%> (+10.07%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rst0git
Copy link
Member

rst0git commented Aug 12, 2023

In Linux we have two types of shared memory: POSIX and System V shared memory.

  • With POSIX shared memory, you can use shm_open() to create a shared memory object and mmap() to map the object into the address space of a process.

    • ./zdtm.py run -t zdtm/static/maps01 -f h -k always can be used to create such image files.
  • With System V, a shared memory segment can be created with shmget() and attached to the address space of process using shmat().

    • ./zdtm.py run -t zdtm/static/shm -f ns -k always can be used to create image files for testing.

We can identify shared memory in mm-*.img by the use of MAP_SHARED in VMA flags.

sudo crit show mm-46373.img
...
                {
                    "start": "0x7fb90ef70000",
                    "end": "0x7fb90ef73000",
                    "pgoff": 0,
                    "shmid": 3,
                    "prot": "PROT_READ | PROT_WRITE",
                    "flags": "MAP_SHARED",
                    "status": "VMA_AREA_REGULAR | VMA_FILE_SHARED",
                    "fd": -1,
                    "fdflags": "0x2"
                },
sudo crit show mm-56.img
...
                {
                    "start": "0x7f6132b7c000",
                    "end": "0x7f6132b7d000",
                    "pgoff": 81920,
                    "shmid": 3,
                    "prot": "PROT_READ | PROT_WRITE",
                    "flags": "MAP_SHARED",
                    "status": "VMA_AREA_REGULAR | VMA_FILE_SHARED | 0x4000",
                    "fd": -1,
                    "fdflags": "0x2"
                },

@behouba behouba marked this pull request as ready for review August 12, 2023 21:07
crit/mempages.go Outdated Show resolved Hide resolved
crit/mempages_test.go Show resolved Hide resolved
This commit adds a method on MemoryReader to retrieve the size of process's shared
memory. The function iterates over the virtual memory areas (VMAs) associated
with the process, summing up the sizes of VMAs that have `MAP_SHARED` flag set.

Signed-off-by: Kouame Behouba Manasse <behouba@gmail.com>
test/crit/main.go Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/mmapper/mmapper.c Outdated Show resolved Hide resolved
test/crit/Makefile Outdated Show resolved Hide resolved
test/crit/Makefile Outdated Show resolved Hide resolved
test/crit/main.go Outdated Show resolved Hide resolved
test/crit/main.go Outdated Show resolved Hide resolved
test/crit/Makefile Outdated Show resolved Hide resolved
This commit introduces a new test program called `mmapper`. `mmapper` is a
simple C program that accepts three arguments: the memory size,  mmap flags
(a combinaison of `s` for `MAP_SHARED`, `p` for  `MAP_PRIVATE`, and optionally
`a` for `MAP_ANONYMOUS`). It then creates a child process with the corresponding
memory mapping of the specified size. This program is used for testing the
accuracy of the `GetShmemSize()` method of `MemoryReader`struct.

Signed-off-by: Kouame Behouba Manasse <behouba@gmail.com>
Copy link
Member

@rst0git rst0git left a comment

Choose a reason for hiding this comment

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

LGTM

@rst0git rst0git merged commit f3c069b into checkpoint-restore:master Aug 22, 2023
14 checks passed
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.

2 participants