Memory-Debuging: How to get locked pages information in user space/kernel space in linux
For each page in memory the is flag assigned to it, Virtual memory page is locked using mlock
, mlockall()
etc API, it assigned the VM_LOCKED
flag to page.
Two options to know the locked pages detail:
Use cat
/sys/kernel/debug/page_owner >> page_owner.txt
To enable debug:kernel menuconfig PAGE_OWNER=y
add"page_owner=on"
to boot cmdline.
cat /sys/kernel/debug/page_owner >> page_owner.txt
In linux source code type:
/tool/vm/page-types.c
, then
compile it and iterate through all pid entries in/proc/
and use the following option for application:
./test -p $PID -L >> test_output.txt
.
It will give you all page details with flags, then you can find locked pages in memory.
`mlockall` to another process
I write a new system call in order to fill the gap.
I attached the patch to the kernel-mm mailing list, you can find it here
Why would we need to lock a process's address space in RAM?
It ensures the memory is always in RAM and never moved to the swap disk. This makes accessing those memory locations much faster as disks are extremely slow compared to RAM.
In a realtime system (linux is NOT a RTS btw!) you need extremely low latencies so a memory access resulting in a disk access is usually not acceptable inside time-critical code.
How do segments from a single memory page behave when mlock'd?
If it locks or unlocks, it does so for the entire page. There's no smaller granularity in the CPU (disregarding x86 segmentation, which is effectively disabled). The OS does not check each and every memory access either (would be prohibitively slow like going to computers of the 80's).
Does the kernel implement a mechanism where the page remains locked as long as the number of mlocks exceeds the number of unlocks?
No:
Memory locks do not stack, that is, pages which have been locked several times by calls to mlock() or mlockall() will be unlocked by a single call to munlock() for the corresponding range or by munlockall().
Related Topics
How to You Configure The Command Prompt in Linux to Show Current Directory
How to Run a Windows Docker Container on Linux Host
Intercepting File System System Calls
What Is The Linux Equivalent to Msvc++'s Option /D1Reportsingleclasslayout
Angular Cli App Not Running When Deploying to Linux App Service
Amazon Ec2 Lost Private Key, How to Get Access to The Server
Bash - How to Print Multi Line Strings (With '\N') Using Printf
Apache Httpd VS. Tomcat 7: Port 80 VS. Port 8080
How to Find Out What Program's on The Other End of a Local Socket
In Linux, How to Find Find Directory with The Most Subdirectories or Files
How to Let Users Run a Script with Root Permissions
What Ncurses Frameworks Are Available for Bash
Move Lines Matching a Pattern from One File to Another
How to Simulate Two Consecutive Enter Key Presses for a Command in a Bash Script