Linux memory usage all processes

Linux: find out what process is using all the RAM?

Before actually asking, just to be clear: yes, I know about disk cache, and no, it is not my case 🙂 Sorry, for this preamble 🙂 I’m using CentOS 5. Every application in the system is swapping heavily, and the system is very slow. When I do free -m , here is what I got:

 total used free shared buffers cached Mem: 3952 3929 22 0 1 18 -/+ buffers/cache: 3909 42 Swap: 16383 46 16337 

So, I actually have only 42 Mb to use! As far as I understand, -/+ buffers/cache actually doesn’t count the disk cache, so I indeed only have 42 Mb, right? I thought, I might be wrong, so I tried to switch off the disk caching and it had no effect — the picture remained the same. So, I decided to find out who is using all my RAM, and I used top for that. But, apparently, it reports that no process is using my RAM. The only process in my top is MySQL, but it is using 0.1% of RAM and 400Mb of swap. Same picture when I try to run other services or applications — all go in swap, top shows that MEM is not used (0.1% maximum for any process).

top - 15:09:00 up 2:09, 2 users, load average: 0.02, 0.16, 0.11 Tasks: 112 total, 1 running, 111 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 4046868k total, 4001368k used, 45500k free, 748k buffers Swap: 16777208k total, 68840k used, 16708368k free, 16632k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ SWAP COMMAND 3214 ntp 15 0 23412 5044 3916 S 0.0 0.1 0:00.00 17m ntpd 2319 root 5 -10 12648 4460 3184 S 0.0 0.1 0:00.00 8188 iscsid 2168 root RT 0 22120 3692 2848 S 0.0 0.1 0:00.00 17m multipathd 5113 mysql 18 0 474m 2356 856 S 0.0 0.1 0:00.11 472m mysqld 4106 root 34 19 251m 1944 1360 S 0.0 0.0 0:00.11 249m yum-updatesd 4109 root 15 0 90152 1904 1772 S 0.0 0.0 0:00.18 86m sshd 5175 root 15 0 90156 1896 1772 S 0.0 0.0 0:00.02 86m sshd 

Restart doesn’t help, and, by they way is very slow, which I wouldn’t normally expect on this machine (4 cores, 4Gb RAM, RAID1). So, with that — I’m pretty sure that this is not a disk cache, who is using the RAM, because normally it should have been reduced and let other processes to use RAM, rather then go to swap. So, finally, the question is — if someone has any ideas how to find out what process is actually using the memory so heavily?

Источник

How to Check Memory Usage in Linux, 5 Simple Commands

It is essential that your Linux system runs at an optimal level. A few simple terminal commands provide access to all relevant information and help you monitor memory statistics.

Читайте также:  Linux перенести папку home

In this tutorial, learn five powerful commands to check memory usage in Linux.

We also provide detailed explanations of what they do and more importantly, how to interpret the results. The commands will work with nearly all Linux distributions. In this instance, the commands and the results are presented using Ubuntu 18.04.

tutorial on how to check memory usage on linux

  • Access to a command line / terminal
  • User with sudo privileges
  • The apt package manager

Commands to Check Memory Use in Linux

cat Command to Show Linux Memory Information

Entering cat /proc/meminfo in your terminal opens the /proc/meminfo file.

This is a virtual file that reports the amount of available and used memory. It contains real-time information about the system’s memory usage as well as the buffers and shared memory used by the kernel. The output might differ slightly based on the architecture and operating system in question.

This is an example of what the /proc/meminfo file looks like in Ubuntu 18.04:

cat-proc-meminf-linux-memory

The terminal displays the information in kilobytes.

free Command to Display the Amount of Physical and Swap Memory

Typing free in your command terminal provides the following result:

linux-free-command

The data represents the used/available memory and the swap memory figures in kilobytes.

total Total installed memory
used Memory currently in use by running processes (used= total – free – buff/cache)
free Unused memory (free= total – used – buff/cache)
shared Memory shared by multiple processes
buffers Memory reserved by the OS to allocate as buffers when process need them
cached Recently used files stored in RAM
buff/cache Buffers + Cache
available Estimation of how much memory is available for starting new applications, without swapping.

Compared to the /proc/meminfo file, the free command provides less information. However, it is easier to understand. The key figure being the available value as it displays how much memory is still available for running new applications.

The free command has multiple options to format the output so that it better matches your requirements. The table below lists the most useful variations of the free command.

Options Result
-b output in bytes
-k output in kibibytes
-m output in mebibytes
-g output in gibibytes
-l detailed low and high memory statistics
-o old format (no -/+buffers/cache line)
-t total for RAM + swap
-s update every [delay] seconds
-c update [count] times

Note: As with most commands, entering man free displays an overview of all variations and descriptions of the results.

vmstat Command to Report Virtual Memory Statistics

The vmstat command is a useful tool that reports virtual memory statistics.

vmstat provides general information about processes, memory, paging, block IO, traps, and CPU activity.

linux-vmstat-memory-check-command

The detailed description listed below provides an explanation for each value in case you need assistance in analyzing the results.

  • Procs
    • r: number of processes waiting for run time.
    • b: number of processes in uninterruptible sleep.
    • swpd: amount of virtual memory used.
    • free: amount of idle memory.
    • buff: the amount of memory used as buffers.
    • cache: amount of memory used as cache.
    • si: memory swapped in from disk (/s).
    • so: memory swapped to disk (/s).
    • bi: Blocks received from a block device (blocks/s).
    • bo: Blocks sent to a block device (blocks/s).
    • in: number of interrupts per second, including the clock.
    • cs: number of context switches per second.
    • us: Time spent running non-kernel code. (user time, including nice time)
    • sy: Time spent running kernel code. (system time)
    • id: Time spent idle. Before Linux 2.5.41, this includes IO-wait time.
    • wa: Time spent waiting for IO. Before Linux 2.5.41, included in idle.
    • st: Time stolen from a virtual machine. Before Linux 2.6.11, unknown.

    top Command to Check Memory Use

    The top command is useful to check memory and CPU usage per process. It displays information about:

    • uptime
    • average load
    • tasks running
    • number of users logged in
    • number of CPUs/CPU utilization
    • memory/swap system processes

    The data is continuously updated, which allows you to follow the processes in real-time.

    top-command-linux-memory

    Aside from providing you with essential memory information, the top command provides a limited interactive interface. It is possible to manipulate and configure operations by using command-line options.

    The man command in Linux man top provides a comprehensive list of all available variations.

    htop Command to Find Memory Load of Each Process

    The information the htop command provides is similar to the top command. However, the real advantage to the htop command is its user-friendly environment and improved controls.

    The command uses color for its output, provides full command lines for processes, as well as the option to scroll both vertically and horizontally.

    The following output appears:

    htop-linux-command-memory

    1. The top segment provides summary information and contains graphic meters and text counters.
    2. The lower section structures the detailed data, per process. This allows you to perform actions on individual processes with ease.
    3. The shortcuts listed at the bottom of the screen will enable you to manipulate and customize the processes quickly and without the need to type specific commands.

    Note: If you run into “Command ‘htop’ not found” message when trying to run the htop command, you will need to install the htop function first:

    As an alternative, use the command below:

    Checking Memory Usage in Linux using the GUI

    Using a graphical interface for server administration is not common practice. However, certain data sets are much clearer, with a visual representation of memory usage.

    To access the System Monitor:

    1. Navigate to Show Applications.
    2. Enter System Monitor in the search bar and access the application.
    3. Select the Resources tab.
    4. A graphical overview of your memory consumption in real time, including historical information is displayed.

    gui-gnome-memory-system-monitor

    This guide provided several options to check memory usage on your Linux system. We learned that a single command provides an abundance of valuable data for future analysis. Learning to interpret the information correctly is critical.

    Now you can administer your server more efficiently.

    Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.

    This tutorial shows how to display disk usage from a command line in Linux. It is important to know how much.

    The Linux kernel is much like the central brain of the operating system. Although it is open-source, meaning.

    There are many different tools for monitoring network traffic on a Linux server. Each option has its.

    Reducing server response time to the bare minimum is one of the primary goals of website owners and SEO.

    Источник

    How to see top processes sorted by actual memory usage?

    If I understand correctly, the system has only 362 MB of available memory. My question is: How can I find out which process is consuming most of the memory? Just as background info, the system is running 64bit OpenSuse 12 .

    12 Answers 12

    use quick tip using top command in linux/unix

    and then hit Shift + m (i.e. write a capital M ).

    SORTING of task window For compatibility, this top supports most of the former top sort keys. Since this is primarily a service to former top users, these commands do not appear on any help screen. command sorted-field supported A start time (non-display) No M %MEM Yes N PID Yes P %CPU Yes T TIME+ Yes 

    Or alternatively: hit Shift + f , then choose the display to order by memory usage by hitting key n then press Enter . You will see active process ordered by memory usage

    hi codecowboy, perhaps you can look at commandlinefu.com/commands/view/3/… for more detailed memory used in my server i am using third party app like newrelic.com

    First, repeat this mantra for a little while: «unused memory is wasted memory». The Linux kernel keeps around huge amounts of file metadata and files that were requested, until something that looks more important pushes that data out. It’s why you can run:

    find /home -type f -name '*.mp3' find /home -type f -name '*.aac' 

    and have the second find instance run at ridiculous speed.

    Linux only leaves a little bit of memory ‘free’ to handle spikes in memory usage without too much effort.

    Second, you want to find the processes that are eating all your memory; in top use the M command to sort by memory use. Feel free to ignore the VIRT column, that just tells you how much virtual memory has been allocated, not how much memory the process is using. RES reports how much memory is resident, or currently in ram (as opposed to swapped to disk or never actually allocated in the first place, despite being requested).

    But, since RES will count e.g. /lib/libc.so.6 memory once for nearly every process, it isn’t exactly an awesome measure of how much memory a process is using. The SHR column reports how much memory is shared with other processes, but there is no guarantee that another process is actually sharing — it could be sharable, just no one else wants to share.

    The smem tool is designed to help users better gage just how much memory should really be blamed on each individual process. It does some clever work to figure out what is really unique, what is shared, and proportionally tallies the shared memory to the processes sharing it. smem may help you understand where your memory is going better than top will, but top is an excellent first tool.

    Источник

Оцените статью
Adblock
detector