Solaris 操作系统虚拟交换使用问题

案例分析

来龙去脉

2023 年 02 月 01 日 11 时 47分,集中监控显示生产运行小型机agent无法访问 (1.5min恢复),之后报oracle实例无法访问,(约20秒后恢复)

原因分析:

The cause of this message is the inability of the system to find swap space to allow a thread stack to grow into another page, ie there is not even a single available page of free swap.

经核查判断,该自主重启主要由于 swap 分区不足导致没有交换空间以允许线程堆栈扩展引起,相关原厂文档参考

Document 1008068.1 (oracle.com)

该行为导致生产运营系统节点1上的实例重启,因为系统架构是rac,前端应用未受影响。

后续加强了对solaris的swap监控,部署了新的监控指标,针对swap空间不足的问题,作为隐患制定了修正计划,并于近期对swap进行扩容。

Solaris 操作系统swap空间

swap在solaris下的计算方式

​ 进程使用虚拟内存。一个进程的virtual address space由许多内存段组成:文本、数据、堆栈、堆、cow段。当进程访问virtual address space时,可能会导致[page fault](##_什么是page fault?)。page fault将数据从交换区带入物理内存。然后将faulted virtual address映射到物理内存。所有页都驻留在内存段中,该内存段有一个基于磁盘的备份存储,在内存不足时可以迁移段内的页。文本/数据段是不同的;这些段由文件系统上的可执行文件支持。堆栈、堆、COW(写时复制)和共享内存页是匿名(Anon)页;它们由virtual swap支持。

​ 当进程开始访问页面时,将分配匿名内存;没有分配物理磁盘交换。在Solaris中,只有当可用内存很少并且需要将页面迁移到swap device以满足工作负载内存需求时,才会进行交换分配。这就是为什么“swap -l”报告物理磁盘交换分配,但在正常情况下,“block”和“free”列显示相同的值。

​ Solaris可以在没有物理磁盘交换的情况下运行,这是因为swapfs抽象模拟了备份页面的物理交换空间。Solaris使用由物理内存和physical disk-backed swap组成的虚拟交换。如果没有配置基于物理磁盘的交换空间,则从物理内存分配交换空间预留。物理内存的交换预留受到限制,因为系统不能执行大于物理内存的malloc()(动态内存分配,而且是分配匿名内存)。没有物理磁盘交换的系统可以防止恶意程序执行巨大的malloc()操作,从而由于内存不足而影响系统性能。

​ 当进程调用malloc()/sbrk()命令时,只分配虚拟交换。操作系统首先从物理磁盘交换分配内存。如果基于磁盘的交换耗尽或未配置,则从物理内存分配预留。如果两个资源都耗尽,则malloc()调用失败。为了确保malloc()不会因为缺少虚拟交换而失败,可以以设备或交换文件的形式配置一个基于物理磁盘的大型交换工具。如前所述,可以通过“swap -s”和“vmstat:swap”监视交换空间预留。

​ 在内存充足的系统中,"swap -l"为"block"和"free"列报告相同的值。“swap -l”命令报告“free”中的大值并不意味着存在大量的虚拟交换,也不意味着malloc()会成功,因为“swap -l”不提供关于虚拟交换使用的信息。它只提供有关物理磁盘交换分配的信息。“swap -s”和“vmstat:swap”命令用于报告可用的虚拟交换空间预留信息。

​ 按照下面的指导原则计算虚拟交换的使用量:

Virtual swap = Physical Memory + Fixed Disk swap

虚拟内存交换=物理内存+固定磁盘交换

​ 考虑到物理内存使用随时间的变化,我们只能通过跟踪availrmem来计算在特定时间可以作为swap预留多少物理内存。Availrmem报告如果有需求,可以提供多少内存。它计算所有可以释放的未映射页面。可能无法释放所有未映射的页面。例如:脏页绑定在页缓存中。Freemem报告有多少内存可以立即使用。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:

root@naoms-db-1:~# vmstat 2 5
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr am s0 s1 s2 in sy cs us sy id
0 0 0 39880984 27647456 1405 3025 0 9 9 0 0 0 10 40 3 18516 37458 25073 1 0 99
0 0 0 46084352 32841504 721 1836 0 0 0 0 0 0 4 11 3 25137 32554 19890 1 0 98
0 0 0 46113840 32826824 570 2506 0 0 0 0 0 0 20 140 3 24093 71648 40266 1 1 98
0 0 0 46116880 32843240 600 2197 0 0 0 0 0 0 8 14 3 17846 18199 15802 1 0 99
0 0 0 46084552 32840024 560 1629 0 0 0 0 0 0 6 17 3 19559 37522 30153 1 0 98

Available virtual swap: 46084552 KB =~ 44G


root@naoms-db-1:~#
root@naoms-db-1:~#
root@naoms-db-1:~# swap -s
total: 17083336k bytes allocated + 4056656k reserved = 21139992k used, 46096672k available

Available virtual swap: 3472532 KB = 44G
Used virtual swap: 116501456 KB = 20G

Physical disk swap configured:

root@naoms-db-1:~# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 305,1 16 33554416 33554416

33554416*512/1024/1024/1024 ~= 16G

上例的 17083336k bytes allocated ~= 16G

即物理磁盘上划分的固定交换区

首先从磁盘支持的交换空间分配内存。如上所示,总虚拟交换预留为20G。这表明系统已经耗尽了磁盘支持的交换空间,现在正在从物理内存中分配:

对物理内存做了多少交换预留?

20G (total virtual swap) - 16G (disk-based swap) = 4G (swap allocated from physical memory)

即4056656k reserved

Total virtual swap = RAM backed swap + Disk-backed swap

kstat报告availrmem值和应用程序锁定的内核和页面的内存使用情况:

root@naoms-db-1:~# kstat -n system_pages
module: unix                            instance: 0
name:   system_pages                    class:    pages
............
......
availrmem                       5949921 * 8 /1024/1024   ~= 45G
freemem                         4106126 * 8 /1024/1024 ~= 31G
physmem                         16259731 * 8 /1024/1024 ~= 124G

# 这里我们要确认一下系统内存的pages
root@naoms-db-1:~#   getconf PAGE_SIZE
8192
# 8k

遵循一个原则:

The operating system earmarks swapfs_minfree ( 1/8 x physmem memory) amount of memory as unavailable for reservation as virtual swap by applications.

swapfs_minfree = 1/8 x physmem = 1/8 x 124G = ~ 16G 这个值从availrmem中减去,得到可以为非根用户预留多少物理内存

RAM back swap available for reservation: availrmem - swapfs_minfree = 45 -16 = 29G

​ ISM段只保留物理内存交换支持,并认为所有ISM页面都被内核锁定在内存中,不可用于交换。DISM分配需要磁盘和内存支持的交换预留,并允许进程锁定和解锁内存。(深入研究可阅读Oracle Solaris性能衰减预警 - 墨天轮 (modb.pro)

​ 如前所述,在测量预留可用的虚拟交换时,可以考虑监视vmstat(“swap”列)或swap -s(“可用”值)。vmstat报告的空闲内存(“Free”列)或swap -l报告的交换空间使用量(“Free”列)与可用的虚拟交换空间预留无关。当从内存分配交换预留时,不会从内存中减掉这部分空间,vmstat 仍旧显示相同数量的“空闲”内存。类似地,当从基于物理磁盘的交换进行交换预留时,swap -l 将继续显示相同数量的“空闲”交换。当数据需要从物理内存迁移到物理磁盘交换以保持足够的空闲内存供应时,空闲内存在page fault时被扣除,空闲交换在内存不足时被扣除。

什么是page fault?(帮助理解)

​ Linux 内核给每个进程都提供了一个独立的虚拟地址空间,并且这个地址空间是连续的。这样,进程就可以很方便地访问内存,更确切地说是访问虚拟内存。虚拟地址空间的内部又被分为内核空间和用户空间两部分。并不是所有的虚拟内存都会分配物理内存,只有那些实际使用的虚拟内存才分配物理内存,并且分配后的物理内存,是通过内存映射来管理的。

内存映射,其实就是将虚拟内存地址映射到物理内存地址。为了完成内存映射,内核为每个进程都维护了一张页表,记录虚拟地址与物理地址的映射关系。页表实际上存储在 CPU 的内存管理单元 MMU 中。

​ 当进程访问它的虚拟地址空间中的PAGE时,如果这个PAGE目前还不在物理内存中,此时CPU是不能干活的,Linux会产生一个hard page fault中断。系统需要从慢速设备(如磁盘)将对应的数据PAGE读入物理内存,并建立物理内存地址与虚拟地址空间PAGE的映射关系。然后进程才能访问这部分虚拟地址空间的内存。

page fault 又分为几种,major page fault、 minor page fault、 invalid(segment fault)。

  • major page fault 也称为 hard page fault, 指需要访问的内存不在虚拟地址空间,也不在物理内存中,需要从慢速设备载入。从swap 回到物理内存也是 hard page fault。

  • minor page fault 也称为 soft page fault, 指需要访问的内存不在虚拟地址空间,但是在物理内存中,只需要MMU建立物理内存和虚拟地址空间的映射关系即可。

当一个进程在调用 malloc 获取虚拟空间地址后,首次访问该地址会发生一次soft page fault。
通常是多个进程访问同一个共享内存中的数据,可能某些进程还没有建立起映射关系,所以访问时会出现soft page fault
invalid fault 也称为 segment fault,指进程需要访问的内存地址不在它的虚拟地址空间范围内,属于越界访问,内核会报 segment fault错误。

什么是匿名内存

​ 匿名内存是指那些在文件系统里没有相对应的”储备文件“的那些内存,堆和栈空间的内存都属于匿名内存。匿名内存来源于交换分区.

​ Swap空间的作用可简单描述为:当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用。那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被释放的空间被临时保存到Swap空间中,等到那些程序要运行时,再从Swap中恢复保存的数据到内存中。这样,系统总是在物理内存不够时,才进行Swap交换。

​ 需要说明一点,并不是所有从物理内存中交换出来的数据都会被放到Swap中(如果这样的话,Swap就会不堪重负),有相当一部分数据被直接交换到文件系统。例如,有的程序会打开一些文件,对文件进行读写(其实每个程序都至少要打开一个文件,那就是运行程序本身),当需要将这些程序的内存空间交换出去时,就没有必要将文件部分的数据放到Swap空间中了,而可以直接将其放到文件里去。如果是读文件操作,那么内存数据被直接释放,不需要交换出来,因为下次需要时,可直接从文件系统恢复;如果是写文件,只需要将变化的数据保存到文件中,以便恢复。但是那些用malloc和new函数生成的对象的数据则不同,它们需要Swap空间,因为它们在文件系统中没有相应的“储备”文件,因此被称作“匿名”(Anonymous)内存数据。这类数据还包括堆栈中的一些状态和变量数据等。所以说,Swap空间是“匿名”数据的交换空间.

什么是ISM & DISM?

Oracle Solaris性能衰减预警 - 墨天轮 (modb.pro)

一、预警内容

Solaris平台下,ISM或DISM配置错误可能会严重降低Oracle数据库性能:

The use of DISM on Solaris systems (SPARC and x86-64) outside of the ASM instance can lead to several different issues ranging from excessive swap usage even when memory is available to kernel panics to performance problems. It has been determined by engineering that the ASM instance is typically such a small memory footprint that it should not cause an issue.

二、问题现象

1、数据库级别体现为:

● Overall Poor Performance including login problems

● Processing Delays Resulting in IPC errors

●Instance Evictions

● Node Evictions

2、操作系统级别体现为:

● High System Time (often exceeding 50%)

● GUDs will show numerous threads in the ipc_get system call

● Excessive swap usage

● Kernel Panics

3、预警级别: 高级

Oracle广泛使用共享内存,错误配置共享内存可能会导致严重的性能问题。Solaris 支持四种类型的共享内存:

●Pageable Shared Memory: This is the same as any other anonymous memory (heap, stack, copy-on-write). Shared memory segment is allocated via shmget(2). Attaching to the shared memory segment via shmat() system call without passing SHM_SHARED_MMU or SHM_PAGEABLE flags results in pageable mapping to the shared memory segment. Page fault into the shared memory segment results in virtual to physical memory mapping. All pages residing in the shared memory segment have a backing store, to which the pages within the segment can be migrated during memory shortages. Similar to stack, heap, COW (copy-on-write), shared memory pages are anonymous (Anon) pages and thus they are backed up by virtual swap. These pages can be swapped out during memory shortages which can have a negative effect on application performance. Also, the kernel needs to acquire locks on pages when syncing data cached in shared memory segment. This can induce high lock contention on large SMP systems.

●Intimate Shared Memory (ISM): ISM is an optimized shared memory that deals with the shortcoming of pageable shared memory. Shared memory segment is allocated via shmget(2). Attaching to the shared memory via shmat() system call with SHM_SHARE_MMU flags results in a ISM segment. Unlike non-ISM memory, ISM memory is automatically locked by the kernel and does not require disk swap reservation. This ensures that ISM pages are not paged out during memory shortages. Also, IO performed on pages in ISM segment uses a fast locking mechanism that reduces kernel lock contention and in turn CPU kernel overhead. ISM offers several additional features such as: Large Page support (page sizes of 4M-2G are supported depending on the platform, see pagesize(1)) to improve TLB reach and cache hits; Low memory footprints due to shared virtual-to-physical translation tables (or mapping structures) for sharing memory pages amongst multiple processes; and a reduction in the number of memory pointers needed by applications due to the larger pages. This reduction in complexity translates into noticeable performance improvements, especially on systems with large amounts of memory. [It is important to note that shmget(2) requires swap reservation when it allocates shared memroy segment. It is only after shmat() is called with SHM_SHARED_MMU that the swap reservation against disk is released and switched to swap reservation against memory when pages are locked in memory]

● Dynamic Intimate Shared Memory (DISM): DISM is similar to ISM, but it can be dynamically resized depending on the application demand. Shared memory segment is allocated via shmget(2). Attaching to the shared memory via shmat() system call with SHM_PAGEABLE flags results in a DISM segment. With ISM, it is not possible to change the size of the segment once it has been created. For example, Oracle Database needs to be restarted if the buffer cache size needs to be increased. DISM was introduced as a RAS feature that allows Oracle Database to deal with dynamic reconfiguration events such as adding or removing memory from the system. With this feature, a large DISM segment can be created when the database is started (see doc: Dynamic SGA). The database can selectively lock and unlock sections of this segment as memory requirements change. Unlike ISM, where the kernel locks the shared memory segment, responsibility for locking and unlocking (mlock(3C)) is placed on the database or application. This provides flexibility to adjust memory requirements dynamically. Once DISM is locked properly by the database, it behaves in the same way as ISM, both in functionality and performance. That means availability benefits of DISM can be realized without compromising performance.

●Optimized Shared Memory (OSM): OSM provides similar benefits as DISM but without some of the requirements of DISM see doc: Oracle Database 12c takes Advantage of Optimized Shared Memory on Solaris for additional details.

四、解决方法:

为了主动避免/防止与DISM相关的问题,Oralce最佳实践强烈建议通过以下任一方式禁用在SGA大于4GB的所有实例上使用DISM:

  1. Unset the SGA_MAX_SIZE MEMORY_MAX_TARGET / MEMORY_TARGET parameters

  2. Ensure SGA_MAX_SIZE is set to the same value as SGA_TARGET parameter or equal to the sum of all SGA components in the instance

References:

RAC and Oracle Clusterware Best Practices and Starter Kit (Solaris) (Doc ID 811280.1)

ISM or DISM Misconfiguration can Slow Down Oracle Database Performance (Doc ID 1472108.1)

Running Oracle Database in Solaris 10 Containers - Best Practices (Doc ID 317257.1)

交换空间与虚拟内存

Oracle Solaris OS 软件和应用程序软件可以将一些磁盘空间用于临时存储而不是用于文件系统。磁盘的保留区称为交换空间。当系统没有足够的物理内存来处理当前进程时,将交换空间用作虚拟内存存储区域。在 ZFS 根文件系统中,为交换所保留的磁盘空间为 ZFS 卷。

虚拟内存系统将磁盘上文件的物理副本映射到内存中的虚拟地址。文件系统中的常规文件或交换空间可以备份包含这些映射的数据的物理内存页面。如果交换空间对内存进行了备份,则该内存称为匿名内存,因为没有为备份内存的磁盘空间指定标识。

Oracle Solaris OS 使用的虚拟交换空间概念是指,匿名内存页面和实际备份这些页面的物理存储(或磁盘备份交换空间)之间的层。系统的虚拟交换空间等于其所有物理(磁盘备份)交换空间与当前部分可用物理内存的和。

虚拟交换空间具有以下优点:

  • 由于虚拟交换空间不必对应于物理(磁盘)存储,因此减少了对大量物理交换空间的需求。
  • 称为 SWAPFS 的伪文件系统可为匿名内存页面提供地址。由于 SWAPFS 可以控制内存页面的分配,因此它在确定要对页面执行的操作方面具有更大的灵活性。例如,SWAPFS 可更改页面对磁盘备份交换存储的要求。

交换空间与 TMPFS 文件系统

在 Oracle Solaris 环境中,TMPFS 文件系统由 /etc/vfstab 文件中的项自动激活。TMPFS 文件系统将文件及其关联信息存储在内存中(存储在 /tmp 目录中)而不磁盘上,从而加快了访问这些文件的速度。对于大量使用 /tmp 的应用程序(例如编译器和 DBMS 产品),此功能可显著增强这些应用程序的性能。

TMPFS 文件系统从系统的交换资源分配 /tmp 目录中的空间。此功能意味着,用尽 /tmp 目录中的空间时,也就用尽了交换空间。因此,如果应用程序大量使用 /tmp 目录,而且您未监视交换空间使用情况,则系统可能会用尽交换空间。

如果要使用 TMPFS,但交换资源有限,请采用以下措施:

  • 使用尺寸选项 (-o size) 挂载 TMPFS 文件系统,以便控制 TMPFS 可以使用的交换资源量。

  • 使用编译器的 TMPDIR 环境变量指向另一个较大的目录。

    使用编译器的 TMPDIR 变量仅可以控制编译器是否使用 /tmp 目录。此变量对其他程序是否使用 /tmp 目录没有影响。

总结

下面我将从数值上阐明我的理解(个人理解,可能不准确,可探讨)

=======node-1============
root@naoms-db-1:~# swap  -s
total: 17860552k bytes allocated + 3930736k reserved = 21791288k used, 45369528k available
root@naoms-db-1:~# kstat -n system_pages
availrmem                       5949921 * 8 /1024/1024   ~= 45G
freemem                         4106126 * 8 /1024/1024 ~= 31G
physmem                         16259731 * 8 /1024/1024 ~= 124G
--------------
bytes allocated ~= 17G
reserved ~= 4G
used ~= 21G
available ~= 43G
availrmem ~= 45G 
physmem ~= 124G  
swapfs_minfree ~= 15.5G (1/8 x physmem memory)
availrmem - swapfs_minfree = 可预留内存 = 29.5G
------------------
used = 16G(swap -l) + 5G(RAM backed swap)     // 使用的交换总量,包括已分配的和预留的
available = 16G(swap -l) + (RAM backed swap) ~= 43G
-------------------------------
可预留内存 + 16G(swap -l) = 29.5G + 16G = 45.5G  ~= available

=======node-2============
root@naoms-db-2:~# swap  -s
total: 40025200k bytes allocated + 5630992k reserved = 45656192k used, 19958984k available
root@naoms-db-2:~#   kstat -n system_pages
availrmem                       2671049   20G
freemem                         1177158   9G
physmem                         16259731  124G 
--------------------------------
bytes allocated ~= 38G
reserved ~= 5G
used ~= 43G
available ~= 19G
availrmem ~= 20G 
physmem ~= 124G  
swapfs_minfree ~= 15.5G (1/8 x physmem memory)
availrmem - swapfs_minfree = 可预留内存 = 4.5G
---------------------------------
可预留内存 + 16G(swap -l) =  4.5G + 16G = 20.5  ~= available

如上,比较乱,其实我想验证的就是最后一个等式

可预留内存 + disk-based swap ~= available

solaris 下进程请求内存时,内核从虚拟交换空间中分配空间,这个虚拟交换是指可以向进程提供的内存总量,不是指物理内存,也不是指交换空间。这种特殊的分配机制导致了solaris下内存请求和使用两个阶段:

  1. 内存请求

The first step is the memory request, resulting in the kernel telling a process it has been assigned some memory. For this step, the kernel simply updates the process and reserves the swap by subtracting the allocation provided to the process from the total available swap.

  1. 内存使用

进程使用已分配的虚拟内存空间,完成任务,In the second stage, the process actually tries to use the memory that it has been given. When this happens, the kernel gets notified and verifies the promised swap is available. Assuming no problems occur, the kernel proceeds to locate some physical memory and update the address mappings so that the process's attempt to access memory will succeed.

查看

查看物理内存
prtconf|grep Memory  、 top  、kstat
查看系统swap
# swap -l
查看的是物理交换分区
#swap -s
查看的是虚拟交换空间
虚拟交换空间=物理交换分区+部分物理内存  
-------------
值得注意的是:
swap -l 查出来的block单位是以512字节为单位的。
root@naoms-db-1:~# swap  -l
swapfile                 dev            swaplo      blocks        free
/dev/zvol/dsk/rpool/swap 305,1              16    33554416    33554416
查看分配的空间=33554416*512/1024/1024/1024 =~ 16G

blocks
    The swaplen value for the area in 512-byte blocks.
free
    The number of 512-byte blocks in this area that  are  not  cur-
    rently allocated.
                        
swap -s 显示是按照千字节显示的。        
root@naoms-db-1:~# swap  -s
total: 16745416k bytes allocated + 4263072k reserved = 21008488k used, 46282880k available
查看分配的空间:~=16G + ~=4G ~=20G used , ~=44G available

bytes allocated: 当前为用作后备存储区而分配的交换空间总量(以字节为单位)。
reserved: 交换空间的总量(以字节为单位),当前未分配,但由内存映射请求以供将来使用。
used: 已分配或保留的交换空间总量(以字节为单位)。
available: 当前可用于将来预留和分配的总交换空间(以字节为单位)。这些数字包括-l选项列出的所有已配置交换区域的交换空间,以及物理内存形式的交换空间。

kstat报告availrmem值和应用程序锁定的内核和页面的内存使用情况:
kstat -n system_pages
swap = 物理内存(availrmem - swapfs minfree) + 固定磁盘交换 (16G)
solaris 操作系统上交换空间与虚拟内存管理方式:“TMPFS 文件系统从系统的交换资源分配 /tmp 目录中的空间。
sloaris 操作系统进程分配内存时使用的是swap两个节点总磁盘支持交换 16G

root@naoms-db-1:~# df  -h
Filesystem             Size   Used  Available Capacity  Mounted on
rpool/ROOT/solaris     547G    82G       372G    19%    /
/devices                 0K     0K         0K     0%    /devices
/dev                     0K     0K         0K     0%    /dev
ctfs                     0K     0K         0K     0%    /system/contract
proc                     0K     0K         0K     0%    /proc
mnttab                   0K     0K         0K     0%    /etc/mnttab
swap                    43G   920K        43G     1%    /system/volatile
objfs                    0K     0K         0K     0%    /system/object
sharefs                  0K     0K         0K     0%    /etc/dfs/sharetab
rpool/ROOT/solaris/var
                       547G   3.2G       372G     1%    /var
fd                       0K     0K         0K     0%    /dev/fd
swap                    43G    18M        43G     1%    /tmp
rpool/VARSHARE         547G   272M       372G     1%    /var/share
rpool/VARSHARE/zones   547G    31K       372G     1%    /system/zones
rpool/IPS              547G   9.4G       372G     3%    /IPS
rpool/IPS/full         547G    31K       372G     1%    /IPS/full
oraclepool/backup      547G   125G       308G    29%    /backup
rpool/export           547G    32K       372G     1%    /export
rpool/export/home      547G    33K       372G     1%    /export/home
rpool/export/home/grid
                       547G    31M       372G     1%    /export/home/grid
rpool/export/home/oracle
                       547G    15M       372G     1%    /export/home/oracle
oraclepool             547G    31K       308G     1%    /oraclepool
rpool                  547G    73K       372G     1%    /rpool
oraclepool/u01         547G   113G       308G    27%    /u01/app
rpool/VARSHARE/pkg     547G    33K       372G     1%    /var/share/pkg
rpool/VARSHARE/pkg/repositories
                       547G    31K       372G     1%    /var/share/pkg/repositories
/dev/asm/ogg-127       400G    28G       372G     7%    /ogg



swap扩容方案

How to Add Swap Space in an Oracle Solaris ZFS Root Environment

  1. Become an administrator.

    For more information, see How to Use Your Assigned Administrative Rights in Oracle Solaris 11.1 Administration: Security Services.

  2. Identify the current swap volume.

    A swap volume cannot be removed if it is in use. You can tell if the current swap volume is in use by comparing the blocks identified in the blocks column and blocks identified in the free column. If the blocks in the two columns are equal, the swap area is not busy. For example:

    # swap -l
    swapfile                 dev  swaplo   blocks   free
    /dev/zvol/dsk/rpool/swap 256,1      16 1058800 1058800
    
  3. Select one of the following to resize the swap volume.

    1. If the current swap area is not in use, you can resize the size of the current swap volume, but you must reboot the system to see the increased swap space.

      For example:

      # zfs get volsize rpool/swap
      NAME        PROPERTY  VALUE    SOURCE
      rpool/swap  volsize   517M     -
      # zfs set volsize=2g rpool/swap
      # zfs get volsize rpool/swap
      NAME        PROPERTY  VALUE    SOURCE
      rpool/swap  volsize   2G       -
      # init 6
      
    2. If the system cannot be rebooted, add another swap volume to increase your total swap space.

      For example:

      # zfs create -V 2G rpool/swap2
      

      Then, activate the second swap volume.

      # swap -a /dev/zvol/dsk/rpool/swap2
      # swap -l
      swapfile                  dev  swaplo   blocks   free
      /dev/zvol/dsk/rpool/swap  256,1      16 1058800 1058800
      /dev/zvol/dsk/rpool/swap2 256,3      16 4194288 4194288
      
  4. If necessary, add an entry for the second swap volume in the /etc/vfstab file.

    For example:

    /dev/zvol/dsk/rpool/swap2    -        -       swap    -       no      -
    
附件- 测试记录
1. If the system cannot be rebooted, add another swap volume to increase your total swap space.
For example:

扩容前:
root@solaris:~# swap  -s 
total: 361936k bytes allocated + 132104k reserved = 494040k used, 6585504k available
root@solaris:~# swap -l 
swapfile                 dev            swaplo      blocks        free
/dev/zvol/dsk/rpool/swap 254,1               8     8388600     8388600

root@solaris:~# more /etc/vfstab 
#device         device          mount           FS      fsck    mount   mount
#to mount       to fsck         point           type    pass    at boot options
#
# START Informational entries for filesystems mounted by the kernel
#/devices       -               /devices        devfs   -       no      -
#/proc          -               /proc           proc    -       no      -
#ctfs           -               /system/contract ctfs   -       no      -
#objfs          -               /system/object  objfs   -       no      -
#sharefs        -               /etc/dfs/sharetab       sharefs -       no      -
#fd             -               /dev/fd         fd      -       no      -
#swap           -               /tmp            tmpfs   -       yes     -
# END Informational entries for filesystems mounted by the kernel

/dev/zvol/dsk/rpool/swap        -  

zfs get volsize rpool/swap  
NAME        PROPERTY  VALUE  SOURCE
rpool/swap  volsize   4G     local

zfs create -V 2G rpool/swap2

Then, activate the second swap volume.
# swap -a /dev/zvol/dsk/rpool/swap2
# swap -l

If necessary, add an entry for the second swap volume in the /etc/vfstab file
For example:
/dev/zvol/dsk/rpool/swap2    -        -       swap    -       no      -

扩容后: 
root@solaris:~# swap -s 
total: 364576k bytes allocated + 132776k reserved = 497352k used, 8659444k available
---
root@solaris:~# swap  -l 
swapfile                  dev            swaplo      blocks        free
/dev/zvol/dsk/rpool/swap  254,1               8     8388600     8388600
/dev/zvol/dsk/rpool/swap2 254,6               8     4194296     4194296


2. If the current swap area is not in use, you can resize the size of the current swap volume, but you must reboot the system to see the increased swap space.
For example:

zfs get volsize rpool/swap2
zfs set volsize=4g rpool/swap2

root@solaris:~# swap  -l 
swapfile                  dev            swaplo      blocks        free
/dev/zvol/dsk/rpool/swap  254,1               8     8388600     8388600
/dev/zvol/dsk/rpool/swap2 254,2               8     4194296     4194296
/dev/zvol/dsk/rpool/swap2 254,2         4194312     4194296     4194296

root@solaris:~# swap  -s  
total: 363520k bytes allocated + 134144k reserved = 497664k used, 10783184k available
root@solaris:~# 
root@solaris:~# swap  -l 
swapfile                  dev            swaplo      blocks        free
/dev/zvol/dsk/rpool/swap  254,1               8     8388600     8388600
/dev/zvol/dsk/rpool/swap2 254,5               8     8388600     8388600
root@solaris:~# 
root@solaris:~# 
root@solaris:~# 
root@solaris:~# swap  -s 
total: 362464k bytes allocated + 133304k reserved = 495768k used, 10795712k available
root@solaris:~# 

参考文档:

Solaris 操作系统如何计算可用交换?(文档 ID 1010585.1)

Oracle Solaris 11 Information Library (简体中文) 11/11 Release

solaris系统上11.2.0.4 db出现ora-04030排查引出的/tmp与swap管理方式差异

测试环境搭建可以用这个v-box的虚拟机模板

posted @ 2023-02-18 16:26  运维小九九  阅读(395)  评论(0编辑  收藏  举报