Strange Note in Solaris manual

Hello!

In document "Advanced System Administrationfor the Solaris� 10Operating SystemSA-
202-S10"
(Solaris 10 Advanced System Administration(SA-202-S10))

I found that:

To view the current swap space allocation, complete the following steps:

  1. List a summary of the system's virtual swap space.
 
# swap -s
total: 218096k bytes allocated + 20432k reserved = 238528k used, 4174456k available
  1. List the details of the system's physical swap areas.
 
# swap -l
swapfile dev swaplo blocks free
/dev/dsk/c0t0d0s1 136,9 16 8392544 8350448

Note - There can be a discrepancy in available and free swap space size between the
swap -s and swap -l outputs. The swap -s output does not take into account pre-allocated swap space that has not yet been used by a process.

As I understand, pre-allocated swap space is a reserved swap space. swap -l shows only swap devices itself, like swap slices and swap files. Swap -s takes into account all swapfs controlled area, i.e. physical RAM+swap slices+swap files.
What does this note means?

Perhaps with lazy allocation for speed, if you do not get a page rolled out, they do not allocate it. At exec, they do reserve the swap space, since the start is a promise that it will keep running, but it can be anywhere. If you exit with all pages in ram, they are never allocated or deallocated.

Okay, let's start from the beginning:

When I run a process, it reserves some memory and use a subset of reserved memory.
Kernel can put some pages of my process to RAM, but some pages to swap slice. But where are the pre-allocated swap spaces here?

So far, so correct. If more memory is requested than the system has then some pages are temporarily put into a part of the disk set aside - memory got "swapped out". There are are two strategies to do this, though:

When the program starts it justs requests the amount of memry it needs. It doesn't care if the kernel can meet these demands or not. If eventually the program has to be swapped out the kernel does so, but the program doesn't care. This is called "lazy" swap allocation and because swapping should happen only very rarely it has the advantag of being fast - the program doesn't bother to prepare for the rather unlikely occasion of being swapped.

Another strategy is this: when a program starts if anticipates the possibility of being swapped out. Therefore it makes the kernel allocate the space in the swap area it might need to be swapped out at start. Once it really gets swapped out it uses this space. This is called "early" swap allocation.

The advantage of this is that the swap space can hardly become overtaxed. This is why in previous times, when memory was scarce and swapping was quite usual, this was a sound strategy. But today swapping is rarely done and allocating space in swap one probably never needs anyway is just a waste of time.

For instance the AIX (IBMs UNIX) kernel used early swap allocation until version 4.3.3 (around 2001), then switched to lazy swap allocation with version 5L.

I hope this helps.

bakunin

When you run a program, everything is either:

  • mmap()'d (like libc.so). The mmap()'d pages are allocated into RAM on demand, but as they have a native disk file, they do not relate to swap.
  • put in RAM and an amount reservation in swap is made in case all the RAM needs to get swapped out. All these pages are marked dirty, as none has been swapped out. If they swap out, the first time they need to have pages allocated. Some uninitialized areas might not even have RAM pages at first, in case they are never used. In this case, when used they are allocated and marked dirty, but still no specific block of swap is allocated.
  • It is possible to have wired pages that never swap, as well, usually in the kernel. The kernel may buffer using wired pages, and active i/o wires a page.
  • Part of the process is managed in tables in the kernel. I am not sure if it is all wired or some or all can swap. May vary with OS!

Yes that is correct...

The kernel never puts any pages to swap on process initialization...and like bakunin said it simply allocates "X" amount of swap in case it were to be swapped out in the near future. That used to be the way things were done...newer systems have pseudo swap where physical memory if in abundance is reserved instead of swap...because it is faster.