Search Posts on Binpipe Blog

Free Up RAM in Redhat & CentOS Linux

Memory normally is occupied by 3 main objects, caches debtries and inodes. However you can free memory at times with the following commands.

1. Sync essentials to disk first by running the following command:

Code:
sync  
2. Cleanup the RAM:

Writing to this will cause the kernel to drop clean caches, dentries and
inodes from memory, causing that memory to become free.

To free pagecache:
Code:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
Code:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
Code:
echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation and dirty objects are not freeable, the user should run `sync' first.

Create graphs using SAR command and KSAR in Linux

You can use KSar tool in combination with sar command to generate and analyze server load and other parameters.



Here's how:

1. Install Sysstat rpm in your server.
2. It will provide the sar package.
3. Let sar record data for a day.
4. Run the following command:
# LC_ALL=C sar -A > /tmp/log.txt
5. Install K-Sar in a windows or Linux Box. (The package is available in sourceforge)
6. Import the log file generated in step 4 above.
7. Generate the graph.

Please note that since Ksar is a java based tool, so it can run in both Linux and Windows machines having JRE installed. Just the sar log has to be fed into it to generate the graph as described above.

Monitor with SAR command in Linux

How to Check Queue Activity (sar -q)

  1. Use the sar -q command to report the following information:

    • The Average queue length while the queue is occupied.

    • The percentage of time that the queue is occupied.


    $ sar -q  00:00:00 runq-sz %runocc swpq-sz %swpocc

    The following list describes the output from the -q option.

    runq-sz

    The number of kernel threads in memory that are waiting for a CPU to run. Typically, this value should be less than 2. Consistently higher values mean that the system might be CPU-bound.

    %runocc

    The percentage of time that the dispatch queues are occupied.

    swpq-sz

    Swap queue of processes for the sar command.

    %swpocc

    Swap queue of processes for the sar command.

    How to Check Unused Memory (sar -r)

  2. Use the sar -r command to report the number of memory pages and swap-file disk blocks that are currently unused.


    $ sar -r  00:00:00 freemem freeswap  01:00:00    2135   401922

    The following list describes the output from the -r option:

    freemem

    The average number of memory pages that are available to user processes over the intervals sampled by the command. Page size is machine-dependent.

    freeswap

    The number of 512-byte disk blocks that are available for page swapping.

    How to Check CPU Utilization (sar -u)

  3. Use the sar -u command to display CPU utilization statistics.


    $ sar -u  00:00:00    %usr    %sys    %wio   %idle  01:00:00       0       0       0     100

    The sar command without any options is equivalent to the sar -u command. At any given moment, the processor is either busy or idle. When busy, the processor is in either user mode or system mode. When idle, the processor is either waiting for I/O completion or “sitting still” with no work to do.

    The following list describes output from the -u option:

    %usr

    Lists the percentage of time that the processor is in user mode.

    %sys

    Lists the percentage of time that the processor is in system mode.

    %wio

    Lists the percentage of time that the processor is idle and waiting for I/O completion.

    %idle

    Lists the percentage of time that the processor is idle and not waiting for I/O.

    A high %wio value generally means that a disk slowdown has occurred

    How to Check System Table Status (sar -v)

  4. Use the sar -v command to report the status of the process table, inode table, file table, and shared memory record table.


    $ sar -v  00:00:00  proc-sz    ov  inod-sz    ov  file-sz    ov   lock-sz  01:00:00   43/922     0 2984/4236    0  322/322     0    0/0   

How to Check Swapping Activity (sar -w)

  1. Use the sar -w command to report swapping and switching activity.


    $ sar -w  00:00:00 swpin/s bswin/s swpot/s bswot/s pswch/s  01:00:00    0.00     0.0    0.00     0.0      22

    The following list describes target values and observations related to the sar -w command output.

    swpin/s

    The number of LWP transfers into memory per second.

    bswin/s

    The number of blocks transferred for swap-ins per second. /* (float)PGTOBLK(xx->cvmi.pgswapin) / sec_diff */.

    swpot/s

    The average number of processes that are swapped out of memory per second. If the number is greater than 1, you might need to increase memory.

    bswot/s

    The number of blocks that are transferred for swap-outs per second.

    pswch/s

    The number of kernel thread switches, per second.


    Note –

    All process swap-ins include process initialization.


How to Check Terminal Activity (sar -y)

  1. Use the sar -y command to monitor terminal device activities.


    $ sar -y  00:00:00 rawch/s canch/s outch/s rcvin/s xmtin/s mdmin/s  01:00:00       0       0       0       0       0       0

    If you have a lot of terminal I/O, you can use this report to determine if any bad lines exist. The activities recorded are defined in the following list.

    rawch/s

    Input characters (raw queue) per second.

    canch/s

    Input characters that are processed by canon (canonical queue) per second.

    outch/s

    Output characters (output queue) per second.

    rcvin/s

    Receiver hardware interrupts per second.

    xmtin/s

    Transmitter hardware interrupts per second.

    mdmin/s

    Modem interrupts per second.

    The number of modem interrupts per second (mdmin/s) should be close to zero. The receive and transmit interrupts per second (xmtin/s and rcvin/s) should be less than or equal to the number of incoming or outgoing characters, respectively. If not, check for bad lines.

    How to Check Overall System Performance (sar -A)

  2. Use the sar -A command to display statistics from all options to provide a view of overall system performance.

    This command provides a more global perspective. If data from more than a single time segment is shown, the report includes averages.

    How to Set Up Automatic Data Collection

  3. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands.

  4. Run the svcadm enable system/sar:default command.

    This version of the sadc command writes a special record that marks the time when the counters are reset to zero (boot time).

  5. Edit the /var/spool/cron/crontabs/sys crontab file.


    Note –

    Do not edit a crontab file directly. Instead, use the crontab -e command to make changes to an existing crontab file.



    # crontab -e sys  
  6. Uncomment the following lines:


    0 * * * 0-6 /usr/lib/sa/sa1  20,40 8-17 * * 1-5 /usr/lib/sa/sa1  5 18 * * 1-5 /usr/lib/sa/sa2 -s 8:00 -e 18:01 -i 1200 -A