Linux Memory virt res shr data swap meaning

Source: Internet
Author: User

 

Virt Res SHR Data These are easy to confuse.

First explain the following meanings:

Virt: Virtual memory consumed by the program

Man:the Total amount of virtual memory used by the task. It includes all code, data and shared

Libraries plus pages that has been swapped out and pages that has been mapped but not used.

Res: Memory usage resident memory, which is what the program really occupies

Man:the non-swapped Physical Memory a task has used

SHR: Shared memory, shared library What's

Mans: The amount of shared memory used by a task. It simply reflects memory that could be potentially

shared with other processes

Data: The memory occupied by the database, in addition to the executable file memory.

Mans: The amount of virtual memory devoted to other than executable code, also known as the ' data resi‐

Dent set ' size or DRS.

 

Swap: Swap out the space that has been applied but not used

Man:memory that was not resident but was present in a task. This was memory that had been swapped out

But could include additional non-resident memory. This column was calculated by subtracting phys‐
ical memory from virtual memory

.

Here are some examples to illustrate:

#include <stdio.h>#include<stdlib.h>intMain () {Chararr[1024x768*1024x768*1]; void* p = malloc (1024x768*1024x768* + ); if(NULL = = p) {printf ("malloc mem fail.");return; } Sleep ( $);}

GCC Malloc.c-o malloc

Operation Result:

From above you can see the data: the sum of heaps and stacks.

Can you tell from man's manual that virt = 4+513m + 228?

 

Continue the experiment:

intMain () {Chararr[1024x768*1024x768*1]; void* p = malloc (1024x768*1024x768* + ); if(NULL = = p) {printf ("malloc mem fail.");return; } Memset (P,0,1024x768*1024x768* +) ; memset (arr,0,1024x768*1024x768*1) ; Sleep ( $);}

Operation Result:

As can be seen from the results

The memory space that the RES process is using, after requesting memory and using

 

Continue below:

   

#include <stdio.h>#include<stdlib.h>#include<string.h>#include<sys/ipc.h>#include<sys/shm.h>intMain () {Chararr[1024x768*1024x768*1]; void* p = malloc (1024x768*1024x768* + ); if(NULL = = p) {printf ("malloc mem fail.");return; } intFD = Shmget (Ipc_private,1024x768*1024x768* -,0666|ipc_creat); if( -1= = FD) {return; } void* Pshm = Shmat (FD, NULL,0); Memset (P,0,1024x768*1024x768* +) ; memset (arr,0,1024x768*1024x768*1) ; memset (PSHM,2,1024x768*1024x768* -/2); Sleep ( $);}

Operation Result:

 

As can be seen from the above

SHR: The space used for shared memory.

Swap: Memory stack shared memory that has been applied but not used

To summarize:

Virt: Virtual memory, containing code snippets, stacks.

Res: The memory the process really uses

Swap: The memory that has been applied but not used

Data: Heap + stack

SHR: The space used for shared memory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.