Friday, October 07, 2005

How Solaris[TM] Operating System calculates available swap.

*Keyword(s):*swap, swapfs, swapfs_minfree, tmpfs

*Description:*

When configuring swap space on a system, it is useful to know how
Solaris[TM] Operating System calculates available swap.

*Document Body:*

Swap size is equal to all available physical memory (RAM swap) plus any physical
disk partitions dedicated for swap, plus space allocated to swap in the form of
swapfiles.

The amount of memory available for RAM swap is less than the size of physical
memory. This is because only pageable memory is available for RAM swap.
Memory that is not pageable includes most of the kernel, any memory that is
mlock()ed and intimate shared memory (ISM).

You can see the summary of memory by running "netstat -k system_pages" or
"kstat -n system_pages".

Note that the -k option to the netstat command is undocumented and its use is
deprecated. In Solaris 10 the -k option is unavailable and "kstat -n
system_pages" must be used. The output format of "kstat -n" differs from that of
"netstat -k" however all the values of interest are present in "kstat -n" output
and have the same names as they do in the output of "netstat -k" with the
exception of "pages total" which is renamed "pagestotal".

The discussion below uses "netstat -k"; similar values for "pp_kernel",
"pageslocked" and "pagestotal" would be displayed by "kstat -n system_pages".

% netstat -k system_pages
system_pages:

physmem 15153 nalloc 5931096 nfree 5868115 nalloc_calls 3092 nfree_calls
2386
kernelbase 268463432 econtig 280756224 freemem 1719 availrmem 11932
lotsfree 236 desfree 118 minfree 59 fastscan 7568 slowscan 100 nscan 0
desscan 25
pp_kernel 2773 pagesfree 1719 pageslocked 3204 pages total 15136
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^

The kernel on this 128MB machine is 2773 pages, or 21MB, and the
total size of locked memory (including the kernel) is 3204 pages, 25MB
(Note that on Solaris 10 and above, pp_kernel excludes pageslocked,
and thus they must be added). A page is 8KB (8192 bytes).

One would expect this machine to have a virtual swap size of: 128MB - 25MB =
103MB.
Note however that "pages total" is 15136 pages which corresponds to 118MB and
not the 128MB of physical memory installed.

During boot, some of the system's memory is used for statically-allocated
portions of the kernel, such as the kernel text, TSBs (translation storage
buffers), page structures, the page table, etc. Memory left after those
allocations is shown in the physmem above. In this case, there is 118MB (15153
* pagesize, or 8KB) memory for which page structures are created (Note that
on Solaris 10 and above, this memory is already accounted for in pp_kernel).

So, we have 118MB - 25MB = 93MB of pageable virtual memory, but there is one
last factor. The swap file system leaves a reserve of 1/8th of memory, or 118/8
= 14.6MB. The minimum for this is 2MB.

Summary:

Total Memory 128MB
- static kernel 10MB
- Kernel 25MB
- swapfs_minfree 15MB
--------------------- -----
Total Ram Swap 78MB

Total Swap space = Ram swap + disk swap

How to read df -k /tmp output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Filesystem kbytes used avail capacity Mounted on
swap 52280 664 51616 2% /tmp

tmpfs (when mounted on /tmp) dynamically changes its size depending upon how
much memory (or swap) is available.

The "kbytes" column in "df -k /tmp" output is the amount of swap space
available, rather than the total.

The tmpfs file system also has a minfree, so the total is slightly less than the
amount of swap available. "kbytes" column of "df -k /tmp" output actually
correspond to "swap -s" output of swap available. Normally, these two numbers
are pretty close.

The difference is due to the tmpfs_minfree value, which is 2MB by default.

% swap -s
total: 120272k bytes allocated + 26696k reserved = 146968k used, 53696k
available

If some process would de-allocate some swap, and swap -s would show more swap
available, then the df -k /tmp would also show that its total file system size
has increased.

0 Comments:

Post a Comment

<< Home