I have a customer who wants me to analyze his use of physical memory on a Linux-based handheld product. I've looked at all the obvious Linux tools for getting memory info, but what I'd really like to be able to do is take a "snapshot" of physical memory, and relate it to running processes. I could, for example, get the information I wanted by dumping /proc/pid/maps for each process, if I could somehow get the physical addresses of all the pages making up each of the virtual memory ranges.
One approach that seems reasonable is to "walk" the page table structure and dump it to a file for post processing. I'm a fairly experienced kernel and driver hacker, but I've never actually done anything with the paging and memory management code. After doing a little reading, I concluded that this would be a fairly straight-forward task -- so straight-forward that I was certain I wouldn't have to do it, there would be some tool out there already that did what I need.
To my surprise, after much searching, I haven't located such a tool. This suggests to me that either (a) I'm not searching for the right thing, or (b) this is a much more challenging task in general that I think.
Can anyone confirm one or both of these notions? In particular, can anyone point me at a tool like what I'm looking for, or alternatively, can anyone explain why this is a really hard thing to do?
Linux Page Table Walk?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Linux Page Table Walk?
I have no idea, but I do know this thread should be either in General Ramblings or General Programming.
post++;
post++;
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: Linux Page Table Walk?
On a handheld product you are much less likely to find this sort of application.
How hard it is to do this yourself depends on a the handheld's processor. It also depends how the linux kernel uses the MMU (ie. x86 processors support segmentation, but linux doesn't use this feature).
I don't have much experience with embedded devices, but I would imagine that it wouldn't page anything out to disk, which removes one important level of complexity.
One option might be doing a core dump with an emulator (if you can find one for your processor) and attempting to find information from there.
How hard it is to do this yourself depends on a the handheld's processor. It also depends how the linux kernel uses the MMU (ie. x86 processors support segmentation, but linux doesn't use this feature).
I don't have much experience with embedded devices, but I would imagine that it wouldn't page anything out to disk, which removes one important level of complexity.
One option might be doing a core dump with an emulator (if you can find one for your processor) and attempting to find information from there.
Re: Linux Page Table Walk?
Hi
I'm not that familiar with the Linux kernel internals anymore so take what you like from this..
A tasks 'mm_struct' has a field 'pgd' which points to the page global directory. I believe this is architecture-independent-ish (3-level thing, PGD/PMD/PTE and page struct to the physical page) This is the data you want to be walking.
You could probably publish this via procfs and or use /dev/mem?
Edit: Sorry, I totally missed the OP's question. One possible reason is the whole VM system is designed to let you forget about physical memory. Such a tool probably isn't that useful outside the embedded market and created bespoke? It doesn't sound terribly difficult though.
I'm not that familiar with the Linux kernel internals anymore so take what you like from this..
A tasks 'mm_struct' has a field 'pgd' which points to the page global directory. I believe this is architecture-independent-ish (3-level thing, PGD/PMD/PTE and page struct to the physical page) This is the data you want to be walking.
You could probably publish this via procfs and or use /dev/mem?
Edit: Sorry, I totally missed the OP's question. One possible reason is the whole VM system is designed to let you forget about physical memory. Such a tool probably isn't that useful outside the embedded market and created bespoke? It doesn't sound terribly difficult though.
All your base are belong to us.
Re: Linux Page Table Walk?
I agree -- it doesn't sound difficult, which is why I expected to find something like it already out there. True, it may not be generally useful, but being able to characterize physical RAM usage is such a frequent desire (especially in embedded products) that if it were easy, I'd expect to find it.One possible reason is the whole VM system is designed to let you forget about physical memory. Such a tool probably isn't that useful outside the embedded market and created bespoke? It doesn't sound terribly difficult though.
Again, I agree... many of the more common Linux tools aren't available on the product I'm working on. I port them as needed, if the difficulty isn't too great.On a handheld product you are much less likely to find this sort of application.
Sorry to have mis-posted... it didn't really seem that obvious to me.I have no idea, but I do know this thread should be either in General Ramblings or General Programming.