Linux Page Table Walk?

Programming, for all ages and all languages.
Post Reply
User avatar
EQvan
Posts: 7
Joined: Wed Feb 11, 2009 4:28 pm
Location: Portland, Oregon, USA
Contact:

Linux Page Table Walk?

Post by EQvan »

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?
EQware Engineering, Inc.
-- Embedded Quality
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Linux Page Table Walk?

Post by Troy Martin »

I have no idea, but I do know this thread should be either in General Ramblings or General Programming.

post++;
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Linux Page Table Walk?

Post by JohnnyTheDon »

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.
dosfan
Member
Member
Posts: 65
Joined: Tue Oct 14, 2008 1:18 pm
Location: Scotland

Re: Linux Page Table Walk?

Post by dosfan »

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.
All your base are belong to us.
User avatar
EQvan
Posts: 7
Joined: Wed Feb 11, 2009 4:28 pm
Location: Portland, Oregon, USA
Contact:

Re: Linux Page Table Walk?

Post by EQvan »

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 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.
On a handheld product you are much less likely to find this sort of application.
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.
I have no idea, but I do know this thread should be either in General Ramblings or General Programming.
Sorry to have mis-posted... it didn't really seem that obvious to me.
EQware Engineering, Inc.
-- Embedded Quality
Post Reply