Monitoring Page Swapping?

This is a discussion on Monitoring Page Swapping? within the Linux Programming forums, part of the Platform Specific Boards category; Hey guys, I need to monitor a program's memory use and to see if any page swapping occurs. Monitoring memory ...

  1. #1
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72

    Monitoring Page Swapping?

    Hey guys,

    I need to monitor a program's memory use and to see if any page swapping occurs. Monitoring memory use is easy, but I'm not quite sure how to monitor to see if any swapping occurs.

    Is there a way to do this without using auxiliary software?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There is /proc/meminfo or some such, which I believe has paging info.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    That's great! So I looked in there and found (I cut each down a bit for readability):

    Buffers:
    Cached:
    SwapCached:
    Active:
    Inactive:
    SwapTotal:
    SwapFree:
    Dirty:
    Writeback:
    AnonPages:
    Mapped:
    Slab:
    PageTables:
    VmallocTotal:
    VmallocUsed:
    VmallocChunk:
    I also used vmstat and got:


    free memory
    buffer memory
    96780 swap cache
    524280 total swap
    1664 used swap
    522616 free swap
    825797 pages paged in
    813650 pages paged out
    135091 pages swapped in
    41812 pages swapped out
    interrupts
    CPU context switches
    forks
    Now, from vmstat, I assume the 'pages swapped in' and 'pages swapped out' sections are where I'd start looking. I have a few questions:

    1. Is there a way to start these tools to measure from the beginning of a program's execution? It seems like these tools have been measuring and gathering statistics from when they are booted capturing data from all activity on the processor.
    2. Are the 'pages in' and 'pages out' parameters measured in single pages?
    3. Both tools have a parameter to measure 'swap'. I Googled swap and I get the gist of it - but how is it different than a page? For example, is 'used swap' the amount of memory used in a single page? And is 'free swap' the amount of page memory left in the page before it needs to be swapped?


    Thanks again!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm pretty sure "used swap" and "free swap" is the amount of space used/free on the swap partition. vmstat man-page or some other such documentation should give you a clue as to what the unit is, either kilobytes or pages.

    pages out and pages in would tell you how many pages has been swapped out and in respectively (if it's not modified, the same page may be swapped in several times without being swapped out - since there is no reason to swap out a page that isn't modified - and pages may of course be swapped out and never be swapped back in ever again, if the code is doing the "right" things).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    Are the "si" and "so" fields which "vmstat -n 1" generates not sufficient?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Gotcha. Now, is there a way to start these statistics from 0 when I start my program?

  7. #7
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Quote Originally Posted by brewbuck View Post
    Are the "si" and "so" fields which "vmstat -n 1" generates not sufficient?
    Well, there are probably many things that are sufficient. However, I'm new to this so I may not know them.

    The "si" and "so" fields do look to be exactly what I want.

    I was using "vmstat -s" to format it so its easier to view.

    It looks like "vmstat -n 1" starts all values from 0 and continues to update forever? If so, that is exactly what I'm looking for.

    Thanks!

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    I don't think vmstat is cumulative. It just displays the number of events per update cycle. You could do some light post-processing on it to turn it into a cumulative report.

    EDIT: I didn't mean to be harsh in my previous post, just genuinely curious whether vmstat could do what you want, since it's a lot easier.
    Last edited by brewbuck; 03-19-2009 at 11:45 AM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Quote Originally Posted by brewbuck View Post
    I don't think vmstat is cumulative. It just displays the number of events per update cycle. You could do some light post-processing on it to turn it into a cumulative report.

    EDIT: I didn't mean to be harsh in my previous post, just genuinely curious whether vmstat could do what you want, since it's a lot easier.
    No offense taken at all. Vmstat is exactly what I was looking for.

    Thanks!

  10. #10
    Registered User
    Join Date
    Jun 2010
    Posts
    1
    really it's nice information about page swapping.Thanks for sharing

  11. #11
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Depending on your needs mate, check out Htop which I like a lot more than Top....
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault!?!?!?
    By Viper187 in forum Windows Programming
    Replies: 57
    Last Post: 10-02-2008, 09:40 PM
  2. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 02:17 AM
  3. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  4. virtual memory
    By sweets in forum C Programming
    Replies: 6
    Last Post: 11-06-2004, 05:55 AM
  5. C Graphics - Page Flipping
    By z0diac in forum C Programming
    Replies: 1
    Last Post: 10-29-2002, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21