EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Accounting for memory use in a running embedded Linux process

Started by Les Cargill August 23, 2012
I have a Linux process that uses, say 16 MBytes of memory according
to "top".

When I dump the executable using objdump, I can account for only, say, 7 
MBytes of that. It's not doing much if any dynamic allocation ( a quick 
grep fest showed nothing at all, but I wouldn't trust that as
truthful for the moment ).

What tools do I need to account for the difference? And why couldn't I
Google something on the subject?

Thanks in advance.

--
Les Cargill
On 23.8.12 8:59 , Les Cargill wrote:
> I have a Linux process that uses, say 16 MBytes of memory according > to "top". > > When I dump the executable using objdump, I can account for only, say, 7 > MBytes of that. It's not doing much if any dynamic allocation ( a quick > grep fest showed nothing at all, but I wouldn't trust that as > truthful for the moment ). > > What tools do I need to account for the difference? And why couldn't I > Google something on the subject? > > Thanks in advance. > > -- > Les Cargill
Have a look at /proc/process_id/maps. Substitute 'process_id' with the number of your process. It lists all memory areas mapped to your process. The memory consumed by a process in a demand-paged virtual-memory system is pretty complicated, and there is no unique description what memory reservations must be accounted to the process. Remember that physical memory is not consumed before an access is attempted to the page. Also, what is the proper way of accounting for the memory areas consumed by shared libraries linked to several processes? -- Tauno Voipio
In article <k14hb3$99o$1@dont-email.me>,
Tauno Voipio  <tauno.voipio@notused.fi.invalid> wrote:
>On 23.8.12 8:59 , Les Cargill wrote: >> I have a Linux process that uses, say 16 MBytes of memory according >> to "top". >> >> When I dump the executable using objdump, I can account for only, say, 7 >> MBytes of that. It's not doing much if any dynamic allocation ( a quick >> grep fest showed nothing at all, but I wouldn't trust that as >> truthful for the moment ). >> >> What tools do I need to account for the difference? And why couldn't I >> Google something on the subject? > >Have a look at /proc/process_id/maps. Substitute 'process_id' with >the number of your process. > >It lists all memory areas mapped to your process.
Also, /proc/$PID/status will give a short summary of the totals of various types of allocation for the process.
>The memory consumed by a process in a demand-paged virtual-memory >system is pretty complicated, and there is no unique description >what memory reservations must be accounted to the process. > >Remember that physical memory is not consumed before an access >is attempted to the page. > >Also, what is the proper way of accounting for the memory areas >consumed by shared libraries linked to several processes?
You can only really take a system wide view of the total. If you try to account by process, you might say that a process uses X Mb of which Y is shareable, but how much of Y will actually be shared with other processes depends on what libraries they have in common. In practice libc will probably be shared of course, at the very least. /proc/$PID/smaps will give a full breakdown of .../maps including which segments are shared or private, which bits of libraries are not fully resident as not all pages in it have been faulted into core, which bits are paged out to swap (though you probably don't have that on an embedded system of course) and much more that will only be of interest to serious memory tweakers. Nick -- "The Internet, a sort of ersatz counterfeit of real life" -- Janet Street-Porter, BBC2, 19th March 1996

The 2024 Embedded Online Conference