I want to limit the use of swap space (not its size just the usage).
You can not limit swap reservations in Solaris.
Just about every byte of RAM used by a process is guaranteed by Solaris to have some sort of persistent backing store available. (There are some exceptions to that on Solaris, such as some types of shared memory, which do not need swap reservations because they can't be swapped out. Implementations like Oracle database SGAs use these features.)
Memory-maped files, such as executables and shared objects, usually use the actual file on disk as the backing store, and thus don't use swap space at all. Most other memory usages need a backing store. For example, if a process asks the kernel for a 2 GB heap but never actually uses it, that will cause a 2 GB reservation against swap space, because Solaris guarantees that if a process asks for memory, it will get it. There's no OOM killer that kills your database process on your production database server or your web server on your online web server processing customer orders...
On Solaris, if you ask for memory and the kernel says you can have it, you get it. Even if you don't actually use it until after a long, long period of time. That means if you ask for it, the kernel has to make sure there's a place to put it if it has to be swapped out in the future for any reason.
There's a cost to running under a "I said you can have this memory, and that means you WILL be able to access it no matter what" paradigm instead of a "I said you can have this memory but I lied to you and now that you've tried to use it I'm going to kill you" paradigm, and that cost is what might seem like exorbitant swap usage.
To see the swap usage of a process, you can use the pmap -S
command:
bash-4.1$ pmap -S $$
4622: /usr/bin/bash
Address Kbytes Swap Mode Mapped File
0000000000400000 1412 - r-x---- bash
0000000000571000 40 40 rw----- bash
000000000057B000 24 24 rw----- bash
0000000EC09E6000 236 236 rw----- [ heap ]
00007FF0C8590000 304 - r-x---- libcurses.so.1
00007FF0C85EC000 20 20 rw----- libcurses.so.1
00007FF0C85F1000 16 16 rw----- libcurses.so.1
00007FF0C8600000 6756 - r-x---- en_US.UTF-8.so.3
00007FF0C8CA9000 8 8 rw----- en_US.UTF-8.so.3
00007FF0C8CD0000 32 - r-x---- libgen.so.1
00007FF0C8CE8000 4 4 rw----- libgen.so.1
00007FF0C8CF0000 64 64 rwx---- [ anon ]
00007FF0C8D10000 64 64 rwx---- [ anon ]
00007FF0C8D2D000 4 - rwxs--- [ anon ]
00007FF0C8D30000 64 - r-x---- methods_unicode.so.3
00007FF0C8D40000 4 4 rw----- methods_unicode.so.3
00007FF0C8D50000 24 24 rwx---- [ anon ]
00007FF0C8D60000 1816 - r-x---- libc.so.1
00007FF0C8F36000 68 68 rw----- libc.so.1
00007FF0C8F47000 8 8 rw----- libc.so.1
00007FF0C8F50000 64 64 rw----- [ anon ]
00007FF0C8F6C000 352 - r-x---- ld.so.1
00007FF0C8FD4000 16 16 rwx---- ld.so.1
00007FF0C8FD8000 4 4 rwx---- ld.so.1
FFFF80E6271AF000 20 20 rw----- [ stack ]
---------------- ---------- ----------
total Kb 11424 684
Note this line:
0000000000400000 1412 - r-x---- bash
The Swap
column indicates that particular memory mapping requires no swap usage at all. That's the part of the bash
executable that's backed by the on-disk /usr/bin/bash
file itself.
But this line:
0000000000571000 40 40 rw----- bash
uses 40 kb of swap. It's likely a data segment mapped from /usr/bin/bash
, but since it's modifiable data (note the rw
permissions), the backing store can't be the non-modifiable /usr/bin/bash
disk file, so it gets a 40 kb swap reservation.
Note that all of the heap
, anon
, and stack
mappings are backed by swap space in their entirety.
Bottom line:
On Solaris, if you don't want to use up all your swap space to the point where you can't start new processes, don't have your processes ask for memory they don't actually use.
Or make a bigger swap partition.
swap -l
andecho "::memstat" | mdb -k
– Romeo Ninov Jan 05 '19 at 06:56prstat -Z
command tells me that my swap is 97GB Full. I add it to my question so please take a look! – Vahid F Jan 05 '19 at 11:53system.d
linux distros likecent
,fedora
, ... you have an option to specifyswappiness
of your operating system but onsystem.v
distros like solaris I cant find this os parameter. – Vahid F Jan 06 '19 at 10:29