Difference between revisions of "User pages accounting"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
(No difference)

Revision as of 12:42, 4 September 2006

User Beancounters
Definition
/proc/user_beancounters
/proc/bc/
General information
Units of measurement
VSwap
Parameters description
Primary parameters
numproc, numtcpsock, numothersock, vmguarpages
Secondary parameters
kmemsize, tcpsndbuf, tcprcvbuf, othersockbuf, dgramrcvbuf, oomguarpages, privvmpages
Auxiliary parameters
lockedpages, shmpages, physpages, numfile, numflock, numpty, numsiginfo, dcachesize, numiptent, swappages
Internals
User pages accounting
RSS fractions accounting
On-demand accounting
UBC consistency
Consistency formulae
System-wide configuration
vzubc(8)
Configuration examples
Basic
Derived
Intermediate configurations
Tables
List of parameters
Parameter properties
Consistency
Config examples

This article describes internals of user-space pages accounting.

Introduction

User pages is the second importaint resource (after kmemsize) which must be accounted. Despite kernel memory, which is either used or not, the set of user pages may have different classifications. Pages may be backed by file, locked, unused, i.e. requesed with mmap/brk but not yet touched and so on. Thus user pages accounting is trickier that kernel pages' one.

Ways of accounting

There are tree ways of user pages' accouting.

Account all the mappings on mmap/brk and reject as soon as the sum of VMA-s lenghts reaches the barrier.
This type is very bad as applications always map more than they really use and very oftem MUCH more.
Account only the really used memory and reject as soon as RSS [1] reaches the limit.
This type is not good either as the only place where pages appear in user space is page fault handler and the only way to reject is killing the task. Comparing to previous scenarion this is much worse as application won't even be able to close correctly.
Account a part of memory on mmap/brk and reject there, and account the rest of the memory in page fault handlers without any rejects.
This type of accounting it used in UBC.

UBC user pages accounting

Terms

The following terms are used by UBC

  1. shmem mapping - this is the mapping of file, that belong to tmpfs. UBC accounts these pages separately and the description below doesn't take them into account;
  2. private mapping - this includes the following types of mappings:
    1. writable anonymous mappings
    2. writable private file mappings
    Both types are not backed by disk file and thus may not be just freed. These mappings are charged with possible reject right when they are made - in sys_mmap()/sys_brk().
  3. unused pages - this is the number of pages which belong to private mapping, but are not yet touched.

Math model

The following notations are used:

  1. is the total number of privvmpages accounted on UB. I.e. the value seen in /proc/user_beancounters in privvmpages.held;
  2. is the total number of unused pages. This parameter is shown in /proc/user_beancounters_debug file;
  3. is some value that represents the part of the page charged to beancounter in case, when page is mapped;
  4. is the amount of physical memory used by processes.

Page fraction () normally should be , where is the number of UBs the pages is shared between, but this is bad as adding a new UB to page shared set would require recalculating of the whole current set. In UB , where is some parameter which is calculated so that

.

The notation means "there exists an mm_struct, where the page is mapped to and this mm_struct belongs to beancounter". This type of calculation allowed to make an O(1) algorithm of fractions accounting.

Privvmpages accounts the sum of unused pages and the "normalized" number of rss pages:

If you summ the privvmpages of all beancounters in the system you'll get an upper estimation of current physical memory usage by processes.

To get real physical memory usage physpages resource is used [2].

Thus


  1. Resident Set Size
  2. Actually physpages also include tmpfs resident pages