By Alan Hargreaves-Oracle on Aug 23, 2016
I got passed a call today where the customer was concerned that they were using 65% of their available swap. Given that the machine had 128gb of memory and about 16gb free they were concerned at what may be using swap.
The output that lead to the concern was:
$ swap -s total: 6515808k bytes allocated + 3248840k reserved = 9764648k used, 102445552k available
From this output it would be easy to assume that we are using 6.2 gb of swap and the customer knew that they only had an 8gb swap volume.
The part that is often overlooked is the available amount. If we add available and used we end up with 107gb. That's substantially larger than the swap volume size.
What is going on here?
First some definitions from "Solaris Internals"
- Virtual swap space is reserved for an entire segment. Reservation occurs when a segment is created with private/read/write access. The reservation represents the virtual size of the area being created.
- Virtual swap space is allocated when the first physical page is assigned to it. At that point, a swapfs vnode and offset are assigned against the anon slot.
- Swapped out (used swap)
- When a memory shortage occurs, a page may be swapped out by the page scanner. Swap-out happens when the page scanner calls swapfs_putpage for the page in question. The page is migrated to physical (disk or file) swap.
and a few from swap(1M)
- The total amount of swap space in bytes currently allocated for use as backing store.
- The total amount of swap space in bytes not currently allocated, but claimed by memory mappings for possible future use.
- Used(Often referred as “reserved”)
- The total amount of swap space in bytes that is either allocated or reserved.
- The total swap space in bytes that is currently available for future reservation and allocation.
Solaris uses all available pageable memory as virtual swap space in addition to the disk-based swap space.
The amount of virtual swap space available is the amount of available pageable physical memory plus the amount of disk-based swap space available.
Solaris reserves the virtual swap space from the disk- based swap first. Only if disk-based swap is exhausted or unconfigured, the reservation is done from physical memory.
swap -s" reports on "virtual swap". To look at the actual amount of disk
based swap in use we need to look at "
In this case we see
$ swap -l swapfile dev swaplo blocks free /dev/zvol/dsk/rpool/swap 256,1 16 16777200 16777200
The crucial take away in this output is that
blocks == free. This means that we are not using any disk based swap.