Re: VmSiZE to physical memory mapping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

--- kernel learner <kernellearner@xxxxxxxxx> escreveu:

> Thanks for your response but i have lots of doubts regarding this:
> 
> 1. As far as i know VmRSS = (VmSize - swap space being used by the
> process)
> I know on my system there is no swap space
> so, VmSize should be equal to VmRSS but that is not the case here.
> So, what
> is that extra memory being shown in VmSize?
> 
> 2. VmRSS is physical memory being used by the system.
> Now, in case of shared libraries the space used by library will be
> added in
> VmRSS of all the processes which are loading it or only to one
> process.
> If to all process then
> parameter(A) + parameter(B) + parameter(C) + parameter(D) +
> parameter(E) = (MemTotal - MemFree)
> wont be satisfied.
> 
> 3. free gives me the below shown output:
>                        total         used         free       shared
> buffers
>   Mem:       502180       424100        78080            0         
> 340
>   Swap:            0            0            0
>   Total:       502180       424100        78080
> 
> Already a lots of processes are running on my system.  Is it buffers
> = 340
> KB memory being used by page cache etc and remaining ie 512MB(524288
> Kb) -
> 340 KB = 523948 KB should be shown as total (which is not matching
> here....???)
> 
> 4. Can you tell me any fuction in C which returns the info as shown
> in
> /proc/$PID/status file?
> Basically i need mem usage of that process.
> I tried getrusage() function. it return 0  for both  usage.ru_maxrss
> and
> usage.ru_ixrss

Humm, no idea if exists C funtion that returns info from
/proc/$PID/status.

Perhaps you need to read the /proc/$PID/status using C input/output
functions. The function below gets the number of VM and RSS pages from
/proc/$PID/statm. Probably you need to do something similar for status
entry. In this example, you have also the virtual and resident size of
memory, but in terms of page numbers. So if vm_pages=10 and rss_pages=8
you will have, respectively, VmSize=40K and VmRSS=32K, since the page
size is 4K.

#define STATM_SIZE 46
void read_statm(pid_t pid) {
	int fd;
	char filename[25];
	char statm[STATM_SIZE];
	size_t length;
	unsigned int vm_pages, rss_pages;

	snprintf(filename, sizeof(filename), "/proc/%d/statm", (int)pid);
	
	fd = open(filename, O_RDONLY);
	
	if (fd == -1) {
		fprintf(stderr,
			"error opening file %s: %s\n",
			filename, strerror(errno));
		exit(EXIT_FAILURE);
	}
	
	length = read(fd, statm, sizeof(statm));
	close(fd);
	
	statm[length] = '\0';
	
	sscanf(statm, "%u %u", &vm_pages, &rss_pages);
	
	printf("%u %u\n", vm_pages, rss_pages);
}

I hope this can help you.

BR,

Mauricio Lin.

> 
> Regards
> 
> On 4/12/06, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
> >
> > Hi...
> >
> > Allow me to share my (lousy) knowledge
> > > What parameter should i use for these five processes such that
> > >
> > > parameter(A) + parameter(A) + parameter(A) + parameter(A) +
> > > parameter(A) = (MemTotal - MemFree)
> > >
> > you mean:
> > parameter(A) + parameter(B) + parameter(C) + parameter(D) +
> > parameter(E) = (MemTotal - MemFree)
> >
> > What you need is RSS (resident set size) property of each process.
> This
> > RSS field represent the size of physical memory consumed by
> individual
> > process.
> 
>   |  But, you must realize that memory is not consumed only by
> process.
> 
> > Buffers and page cache (buffers is also a part of page cache,
> though)
> > also eat your RAM. You can use "top" or "free" to check it. So
> "free"
> > here actually means "RAM area that is still not allocated for any
> > purpose".
> >
> > Feel free to ask again if you need more information.
> 
> 
> 
> 
> regards,
> >
> > Mulyadi
> >
> >
> 



	
	
		
____________________________________________________


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux