Top command RES, DATA

Monitoring the memory usage of the process at any time is very important for the stability and peace of the service. For example, the size of the process memory for each php-fpm in the nginx+php-fpm technology stack will affect the number of processes open. .

So how do you see the amount of memory used by running processes? Linux provides the top command, which can view the memory usage of each process in real time. There are two main parameters to note, RES and DATA parameters.

Top -p pid Then use f and then click the DATA corresponding identifier to see the DATA column.

       

RES is actually used by the process. VIRT is the sum of virtual and physical. For example, the php-fpm process has a memory limit. This can only limit the RES.

CODE is obtained by the compiler, VIRT and DATA are obtained by malloc and free mmap, etc., and RES is allocated by the operating system.


You can use the following practical example to explain:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

int main(){

        int *data, size, count, i;

        printf( "fyi: your ints are %d bytes large\n", sizeof(int) );

        printf( "Enter number of ints to malloc: " );
        scanf( "%d", &size );
        data = malloc( sizeof(int) * size );
        if( !data ){
                perror( "failed to malloc" );
                exit( EXIT_FAILURE );
        }

        printf( "Enter number of ints to initialize: " );
        scanf( "%d", &count );
        for( i = 0; i < count; i++ ){
                data[i] = 1337;
        }

        printf( "I'm going to hang out here until you hit <enter>" );
        while( getchar() != '\n' );
        while( getchar() != '\n' );

        exit( EXIT_SUCCESS );
}Copy code

This example shows how much memory is allocated, how much memory is initialized, 1250,000 bytes are allocated at runtime, and 500000 bytes are initialized:

$ ./a.out
fyi: your ints are 4 bytes large
Enter number of ints to malloc: 1250000
Enter number of ints to initialize: 500000

TOp view results displayCopy code
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP CODE DATA COMMAND
<program start>
11129 xxxxxxx   16   0  3628  408  336 S    0  0.0   0:00.00 3220    4  124 a.out
<allocate 1250000 ints>
11129 xxxxxxx   16   0  8512  476  392 S    0  0.0   0:00.00 8036    4 5008 a.out
<initialize 500000 ints>
11129 xxxxxxx   15   0  8512 2432  396 S    0  0.0   0:00.00 6080    4 5008 a.outCopy code

After malloc had 1250,000, VIRT and DATA increased, but RES did not change. VIRT and DATA did not change after initialization, but RES increased.

VIRT is all the virtual memory of the process, including shared, into the dynamic link library, etc. DATA is the size of the virtual stack and heap. RES is not virtual, it is the memory that is actually used in memory at a specified time.


Intelligent Recommendation

CentOS explains the meaning of each data in the top command

I recently installed gitlab in docker (the host is a centos virtual machine), and found that as time goes on, the memory of the virtual machine continues to rise. After a few hours of operation, the m...

Once Java memory top res, high inspection record

Foreword To share a recent problem, TOP watch the Java process RES continues to rise, and it can rise 3 G a day. After using the JMAP DUMP memory snapshot, the DUMP files are only more than 300 m, and...

http-res returns different data according to url

Then learned the res response data So how to implement different URLs to respond to different data? Get url Make a judgment on url What if you want to return an array or data JSON.stringify() method C...

android read data in res/values/arrays

Sometimes we need to store some constants in arrays.xml example When you need to read in the activity can be put in a list Can also be placed in an array...

Layui Data Analytics Parsedata: Function (RES)

Layui data resolution, the backend wants to write? Do you want to write a front end? official website https://www.layui.com/doc/modules/table.html#options In the cloud, you will see the official websi...

More Recommendation

Res. Data outputs value, but printing no value

From the figure we can see the output RES has a value of a promise type, and after assigning the Victorray array, it is Undefined, which is asynchronous. My understanding: The program statement is not...

Top command

The top command is commonly used to monitor the CPU load and check the CPU usage of each process. Execute the top command on centos7 The indicators in the first line of the column are obvious, not muc...

The decoder netty LengthFieldBasedFrameDecoder

Official api:http://netty.io/4.1/api/io/netty/handler/codec/LengthFieldBasedFrameDecoder.html MessageDecoder: Wherein the packet length is 6: 17-22 Reference reference: reference:...

lstm

First, combine the previous hidden layer with the current input to form a combined vector. The combined vector enters the forgetting gate, through a sigmoid function, 0 forgetting, 1 memory. Then the ...

ELK installation

ELK installation 1. First prepare the environment of two centos7 192.168.27.136 install jdk elasticsearch kibana 192.168.27.137 install jdk logstash 2. Turn off the firewall, setenforce 3. Synchronize...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top