solaris calculate available swap

Upload: apletonprince

Post on 08-Aug-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/22/2019 Solaris Calculate Available Swap

    1/5

    6/27/13 Document Display

    https://support.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_adf.ctr l-state=13z7b6ooqz_1003

    How does Solaris Operating System calculate available swap? [ID 1010585.1]

    Modified: Mar 18, 2013 Type: HOWTO Migrated ID: 214564 Status: PUBLISHED Priority: 3

    Applies to:

    Solaris SPARC Operating System - Version 8.0 and later

    All Platforms

    Goal

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

    swap.

    Fix

    Processes use virtual memory. A process' virtual address space consists of a number of memory segments: text, data

    stack, heap, cow segments. When a process accesses the virtual address space, it might result in page fault. A page

    fault brings the data from swap into physical memory. The faulted virtual address is then mapped to physical memory

    All pages reside in the memory segment, which has a disk-based backing store where the pages within the segment

    can be migrated during memory shortages. Text/data segments are different; these segments are backed by

    executable file on the file system. Stack, heap, COW (copy-on-write) and shared memory pages are anonymous(Anon) pages; they are backed up by virtual swap.

    When a process begins accessing pages, anonymous memory is allocated; there is no physical disk swap allocated. In

    Solaris, swap allocation only happens when there is little available memory and pages need to be migrated to the swa

    device to keep up with workload memory demand. This is why "swap -l" reports physical disk swap allocation but

    shows the same value in "block" and "free" columns during normal conditions.

    Solaris can run without physical disk swap and due to the swapfs abstraction, which mimicks a physical swap space

    backing up the page. Solaris works with virtual swap composed of physical memory and physical disk-backed swap.

    When there is no physical disk-based swap configured, swap reservation is allocated from physical memory. Swap

    reservation from physical memory is limited by the fact the system cannot perform a malloc() larger than the physica

    memory. Systems configured without physical disk-based swap prevent malicious programs from executing huge

    malloc() operations and thus impacting system performance due to memory shortages.

    When a process calls the malloc()/sbrk() commands, only virtual swap is allocated. The operating system allocates th

    memory from physical disk-based swap first. If disk-based swap is exhausted or unconfigured, the reservation is

    allocated from physical memory. If both resources are exhausted then the malloc() call fails. To ensure malloc() won

    fail due to lack of virtual swap, configure large physical disk-based swap in the form of a device or swapfile. You can

    monitor swap reservation via "swap -s" and "vmstat:swap", as described above.

    On a system with sufficient memory, "swap -l" reports the same value for "block" and "free" column. The "swap -l"

    command reporting a large value in "free" does not mean plenty of virtual swap exists or guarantee a malloc() will

    succeed, because "swap -l" does not provide information about virtual swap usage. It only provides information about

    physical disk swap allocation. The "swap -s" and "vmstat:swap" commands report information about virtual swap

    available for reservation.

    Follow the guidelines below to calculate amount of virtual swap usage:

    Virtual swap = Physical Memory + Fixed Disk swap

    Considering physical memory usage changes over time, we can only calculate how much physical

    memory can be reserved as swap at certain time by keeping track of availrmem.

  • 8/22/2019 Solaris Calculate Available Swap

    2/5

    6/27/13 Document Display

    https://support.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_adf.ctr l-state=13z7b6ooqz_1003

    availrmemreports how much memory can be make available if the demand is there. It counts

    all the unmapped pages that can be freed. Some time it is not possible to free all unmapped

    pages. For e.g: Dirty pages tied up in the page cache. freememreports how much memory is

    immediately available for use. freemem pages can be used with no more overhead than removing

    them from the freelist or cachelist.

    vmstat and swap-s report virtual memory usage:

    # vmstat 5

    kthr memory page disk faults cpu r b w swap free re mf pi po fr de sr s0 s1 s2 s3 in sy cs

    us sy id

    ...

    0 0 0 3296516 38201892 4321 49454 0 0 0 0 0 0 0 6 0 11521 164084 69372 11 31 59

    0 0 0 3361076 38193196 3034 34037 0 0 0 0 0 0 0 47 0 9639 107575 37481 8 24 68

    0 0 0 3501776 38286380 3325 36763 0 0 0 0 0 0 0 5 0 12679 113673 42466 8 25 67

    0 0 0 3545612 38326200 4935 57916 0 0 0 0 0 0 0 63 0 13688 111744 35804 12 31 56

  • 8/22/2019 Solaris Calculate Available Swap

    3/5

    6/27/13 Document Display

    https://support.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_adf.ctr l-state=13z7b6ooqz_1003

    unix:0:system_pages:pagestotal 32626994 [4k pages = 124G]

    unix:0:system_pages:physmem 33552184 [4k pages = 127G] < Total physical memory

    unix:0:system_pages:pp_kernel 8520375 [4k pages = 32G] < Amount of memory used by kernel

    drivers and subsystems

    The operating system earmarks swapfs_minfree ( 1/8 x physmem memory) amount of memory as unavailable for

    reservation as virtual swap by applications.

    mdb can be used to dump swapfs_minfree setting in the kernel. Value is reported in pages [8k

    (sparc), 4k(Intel)]

    # echo "swapfs_minfree::print -t "|mdb -l

    swapfs_minfree = 1/8 x physmem = 1/8 x 127G = ~ 16G < This value is substracted from

    availrmem to find how much physical memory can used for swap reservation for non-root user

    RAM back swap available for reservation: availrmem - swapfs_minfree = 19 -16 = 3G

    An ISM segment reserves only physical memory backed swap, and considers all ISM pages as both locked in memoryby the kernel and unavailable for swapping. A DISM allocation requires both disk and memory backed swap

    reservation, and allows memory to be locked and unlocked by the process.

    As discussed, When measuring virtual swap available for reservation, consider monitoring

    vmstat (swap column) or swap-s (available column). Free memory as reported by vmstat (free

    column) or swap usage as reported by swap-s (free column) is unrelated with virtual swap

    available for reservation. When allocating swap reservation from memory, there is no memory

    deducted and vmstat continues to show same amount of "free" memory. Similarly, when a swap

    reservation is from a physical disk-based swap, swap-l continue to show the same amount of

    "free" swap. Free memory is only deducted due to page fault and free swap is deducted during

    a memory shortage, when data needs to be migrated from the physical memory to physical disk

    swap to maintain a sufficient supply of free memory available.

    ISM pages are locked by the kernel upon return from the shmat() system call. Swap

    reservation of ISM memory is allocated from physical memory, not physical disk-based swap.

    This results in a virtual swap deduction when ISM memory is allocated, but deduction happens

    only against physical memory, considering ISM pages are locked in memory and thus, no

    physical disk swap reservation is necessary.

    When a process calls shmget(), it results in a reservation against physical disk-based swap.

    However, when a process calls shmat() next, swap deduction against physical disk is reversed

    and deduction is then performed against physical memory as demonstrated below:

    k_anon_info structure in kernel keeps track of system wide anonymous memory usage . Before

    starting the program, system wide swap usage:

    > k_anoninfo::print -d

    {

    ani_max = 0t512074

    ani_free = 0t469096

    ani_phys_resv = 0t48810 [virtual swap reservation against physical disk: 8k pages: 381M]

    ani_mem_resv = 0 [virtual swap reservation against physical memory: 0 M]

    ani_locked_swap = 0 [ swap locked in memory: 0 M]

    }

    Start a program that calls shmget() with a size of 400MB. There is no process attached

    (ISMATTACH is 0):

  • 8/22/2019 Solaris Calculate Available Swap

    4/5

    6/27/13 Document Display

    https://support.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_adf.ctr l-state=13z7b6ooqz_1003

    Shared Memory:

    T ID KEY MODE OWNER GROUP CREATOR CGROUP NATTCH SEGSZ CPID LPID ATIME DTIME CTIME ISMATTCH

    PROJECT

    m 7 0x1a --rw-rw---- root root root root 0 419430400 16480 0 no-entry no-entry 18:47:21 0

    user.root

    As you can see, swap reservation increased 400MB against physical disk, but still 0 against

    physical memory

    > k_anoninfo::print -d

    {

    ani_max = 0t512074

    ani_free = 0t469083

    ani_phys_resv = 0t100023 [virtual swap reservation against physical disk: 8k pages: 781 M

    ani_mem_resv = 0

    ani_locked_swap = 0

    }

    Next, program calls shmat() ( ISMATTACH is 1). This results in a swap reservation switched

    from physical disk-based swap to physical memory swap as shown below:

    T ID KEY MODE OWNER GROUP CREATOR CGROUP NATTCH SEGSZ CPID LPID ATIME DTIME CTIME ISMATTCH

    PROJECT

    Shared Memory:

    m 8 0x1a --rw-rw---- root root root root 1 419430400 16487 16487 18:48:27 no-entry 18:48:25

    1 user.root

    > k_anoninfo::print -d

    {

    ani_max = 0t512074

    ani_free = 0t469083

    ani_phys_resv = 0t48823 [ virtual swap reservation against physical disk: 8k pages: 381M]

  • 8/22/2019 Solaris Calculate Available Swap

    5/5

    6/27/13 Document Display

    https://support.oracle.com/epmos/faces/ui/km/SearchDocDisplay.jspx?_adf.ctr l-state=13z7b6ooqz_1003

    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.

    # df -kl -Z /tmp

    Filesystem kbytes used avail capacity Mounted on

    swap 3449940 116 3449824 1% /tmp

    When a process releases memory then df -k /tmp would also show that its total file system

    size has increased.

    Product

    Solaris 8 Operating System

    Solaris 9 Operating System

    Solaris 10 Operating System

    References