RAM and Virtual Memory: sar

The System Activity Report (sar) is one of the most versatile Linux performance tools. sar sometimes does not provide as much detail as some more specialized tools, but provides a good overview. sar reports data that has already been gathered by two commands, sa1 and sa2, which are part of /etc/cron.d/systat. They are run as cron jobs. If these cron jobs are not running, sar will not have any historical data to report. The output from these jobs are stored in /var/log/sa. The following setting in /etc/sysconfig/sysstat indicates that output should be saved for 28 days:
HISTORY=28

The sar command without arguments will show statistics related to CPU usage from the system in real time.
RAM Overview
Technical articles
Memory Shortages and sar
UNIX memory shortages impact performance once virtual memory is impacted. Therefore, when we are investigating possible memory shortages, we are investigating virtual memory as well. vmstat is an essential tool for diagnosing these issues.

sar
The System Activity Report (sar) reports data that has already been gathered by two commands, sa1 and sa2, which are part of /etc/cron.d/systat. They are run as cron jobs. The output from these jobs are stored in /var/log/sa. The following setting in /etc/sysconfig/sysstat indicates that output should be saved for 28 days:
HISTORY=28

If the cron jobs are not running, sar will not have any data to report.

The following reports are used for diagnosing memory issues.
  • sar -r
  • sar -W
  • sar -B
  • sar -R

sar -r
The sar -r report provides these columns (values in K):
  • kbmemfree: free memory statistics
  • kbmemused: used memory statistics,
  • %memused: percentage of memory used
  • kbbuffers: how much memory is allocated to buffers
  • kbcached: how much memory is allocated to the system-wide data cache

sar -W
Shows swap activity. Specifically, pages being brought in from swap (pswpin/s) and pages going out to swap (pswpout/s). Can be used to identify spikes in swapping.

sar -B
more swapping info
Reports paging statistics.

The following values are displayed:
  • pgpgin/s: Total number of kilobytes the system paged in from disk per second.
  • pgpgout/s: Total number of kilobytes the system paged out to disk per second.
  • fault/s: Number of page faults (major + minor) made by the system per second. This is not a count of page faults that generate I/O, because minor page faults are resolved without I/O (see majflt/s).
  • majflt/s: Number of major faults the system has made per second, those which have required loading a memory page from disk.
  • pgfree/s: Number of pages placed on the free list by the system per second.
  • pgscank/s: Number of pages scanned by the kswapd daemon per second.
  • pgscand/s: Number of pages scanned directly per second.
  • pgsteal/s: Number of pages the system has reclaimed from cache (pagecache and swapcache) per second to satisfy its memory demands.
  • %vmeff: Calculated as pgsteal / pgscan, this is a metric of the efficiency of page reclaim. If it is near 100% then almost every page coming off the tail of the inactive list is being reaped. If it gets too low (e.g. less than 30%) then the virtual memory is having some difficulty. This field is displayed as zero if no pages have been scanned during the interval of time.

sar -R
These fields are displayed (pages are 4K or 8K in size):
  • frmpg/s: pages per second being freed from list of free pages. Negative number indicates pages being allocated to the system.
  • campg/s: pages per second being added to the page cache. Negative number means fewer pages.
  • bufpg/s: pages per second being added to the list of pages being used as buffers. Negative number means fewer pages used as buffers.
  • shmpg/s: pages per second being added to the list of pages being used as shared memory

page sizes
The page sizes can be determined by one of these commands:
  • getconf PAGESIZE
  • getconf PAGE_SIZE


Suggestions for Future Learning
This information will be in the second edition of UNIX For Application Support Staff . The ETA for the second edition is December 1, 2016.



RAM Overview
Technical articles