i’ve googled a lot about what is “page share factor per proc” responsible for and found nothing. It’s just interesting for me, i have no current problem with it for now, just curious (wnat to know more). In sysctl it is:
vm.pmap.shpgperproc
Thanks in advance
The first thing to note is that
shpgperprocis a loader tunable, so it can only be set at boot time with an appropriate directive inloader.conf, and it’s read-only after that.The second thing to note is that it’s defined in
<arch>/<arch>/pmap.c, which handles the architecture-dependent portions of the vm subsystem. In particular, it’s actually not present in the amd64pmap.c– it was removed fairly recently, and I’ll discuss this a bit below. However, it’s present for the other architectures (i386, arm, …), and it’s used identically on each architecture; namely, it appears as follows:and it’s not used anywhere else.
pmap_init()is called only once: at boot time as part of the vm subsystem initialization.maxproc, is just the maximum number of processes that can exist (i.e.kern.maxproc), andcnt.v_page_countis just the number of physical pages of memory available (i.e.vm.stats.v_page_count).A
pv_entryis basically just a virtual mapping of a physical page (or more precisely astruct vm_page, so if two processes share a page and both have them mapped, there will be a separatepv_entrystructure for each mapping. Thus given a page (struct vm_page) that needs to be dirtied or paged out or something requiring a hw page table update, the list of corresponding mapped virtual pages can be easily found by looking at the corresponding list ofpv_entrys (as an example, take a look ati386/i386/pmap.c:pmap_remove_all()).The use of
pv_entrys makes certain VM operations more efficient, but the current implementation (for i386 at least) seems to allocate a static amount of space (seepv_maxchunks, which is set based onpv_entry_max) forpv_chunks, which are used to managepv_entrys. If the kernel can’t allocate apv_entryafter deallocating inactive ones, it panics.Thus we want to set
pv_entry_maxbased on how manypv_entrys we want space for; clearly we’ll want at least as many as there are pages of RAM (which is wherecnt.v_page_countcomes from). Then we’ll want to allow for the fact that many pages will be multiply-virtually-mapped by different processes, since apv_entrywill need to be allocated for each such mapping. Thusshpgperproc– which has a default value of 200 on all arches – is just a way to scale this. On a system where many pages will be shared among processes (say on a heavily-loaded web server running apache), it’s apparently possible to run out ofpv_entrys, so one will want to bump it up.