swap - 交换管理接口
/usr/sbin/swap -a swapname [swaplow] [swaplen]
/usr/sbin/swap -d swapname [swaplow]
/usr/sbin/swap -l [-h | -k | --scale[=item1,item2,...]]
/usr/sbin/swap -s [-h | --scale[=item1,item2,...]]
swap 实用程序提供了一种添加、删除和监视内存管理器使用的系统交换区域的方法。
支持以下选项:
添加指定的交换区域。此选项只能由分配有 "File System Management"(文件系统管理)权限配置文件的管理员或者由 root 使用。swapname 是交换区域或常规文件的名称。在运行 ZFS 文件系统的系统上,可以指定 ZFS 卷(如 /dev/zvol/dsk/rpool/swap)作为交换区域。在 ZFS 文件系统上不支持使用常规文件作为交换区域。另外,您不能将同一 ZFS 卷同时用于交换区域和转储设备。
swaplow 是文件内以 512 字节块为单位的偏移量,交换区域应从此偏移量位置开始。swaplen 是交换区域所需的长度,以 512 字节块为单位。swaplen 的值不能小于 16。例如,如果指定了 n 个块,则 (n-1) 个块是实际的交换长度。swaplen 的长度必须至少为一个页面。可以使用 pagesize 命令确定内存页面的大小。See pagesize(1).If the swap file is not a ZFS volume or lofi device the first page of a swap file is automatically skipped, and as a swap file needs to be at least one page in length, the minimum size should be a multiple of 2 pagesize bytes.内存页面的大小取决于计算机。
swaplow + swaplen 必须小于等于交换文件的大小。如果未指定 swaplen,将添加一个始于 swaplow 并扩展到指定文件的末尾的区域。If neither swaplow nor swaplen are specified, the whole file or device will be used.For swap files that are not ZFS volume or lofi devices the first page is skipped to protect any label that might be present.
交换区域在启动系统的过程中通过 svc:/system/swap 服务自动添加。该服务会添加已在 /etc/vfstab 文件中指定的所有交换区域。有关这些规范的语法,请参见 vfstab(5) 手册页。
ZFS volumes used as a swap device will always be encrypted regardless of the value of the encryption property for the ZFS volume.See zfs_encrypt(8).
要使用 NFS 或本地文件系统 swapname,应首先使用 mkfile(8) 创建文件。现在仅通过运行 swap –a 命令即可将一个本地文件系统交换文件添加到正在运行的系统中。对于已挂载的 NFS 交换文件,服务器需要导出该文件。要进行导出,请执行以下步骤:
在 NFS 服务器上运行以下命令:
share -F nfs -o \ rw=clientname,root=clientname directory-with-swap-file
使客户机向 /etc/vfstab 中添加以下行:
server:directory-with-swap-file - local-path-to-directory nfs - yes - local-path-to-directory/swap-file - - swap - no -
在客户机上启用 NFS 客户机服务:
svcadm enable nfs/client
Reboot the client.
删除指定的交换区域。This option can only be used by an administrator who is assigned the File System Management rights profile or by root. swapname is the name of the swap file: for example, /dev/dsk/c0t0d0s1 or a regular file. swaplow is the offset in 512-byte blocks into the swap area to be deleted.如果未指定 swaplow,将从第二个页面开始删除区域。命令完成后,将无法再分配该区域中的交换块,并且该交换区域中之前正在使用的所有交换块已移动到其他交换区域。
所有大小将调整为用户可读的格式。The –h option is equivalent to using the –scale=max,1024 option.
以 1024 字节为单位写出文件大小。
列出所有交换区域的状态。The output has these columns:
交换区域的路径名。
如果设备不是块特殊设备,则此列为十进制的主/从设备号;否则为零。
区域的 swaplow 值,以 512 字节块为单位。
区域的 swaplen 值,以 512 字节块为单位。
此区域中当前没有分配的 512 字节块的数量。
Shows yes if the device is encrypted and no otherwise.
此列表不包括物理内存形式的交换空间,因为该空间不与特定的交换区域相关。
If swap –l is run while swapname is in the process of being deleted (by swap –d), the string INDEL will appear in a seventh column of the swap stats.
列显有关总交换空间的使用情况和可用性的摘要信息:
当前分配的用作后备存储的交换空间总量,以字节为单位。
当前未分配但内存映射声明将来可能使用的交换空间总量,以字节为单位。
分配的或保留的交换空间总量,以字节为单位。
当前可用于将来保留和分配的交换空间总量,以字节为单位。
These numbers include swap space from all configured swap areas as listed by the –l option, as well as swap space in the form of physical memory.
所有大小将调整为用户可读的格式。Scaling is done by repetitively dividing by 1024, unless otherwise specified.
–scale specified without arguments enables default scaled output, and is equivalent to –scale=max,1024.
–scale can be specified with the following arguments.
Scaling is done by repetitively dividing by a scale factor of 1024.The use of binary scaling is indicated by the addition of an 'i' modifier to the suffix (Ki, Mi, Gi, ...).
Values are scaled to the largest unit for which the result retains a non-zero integer part.Up to 2 decimal places of fractional output may be shown.
Values are scaled to the smallest unit capable of showing the full value within the allotted space of 5 columns, and displayed without the use of fractional output.
Values are scaled to the smallest unit capable of showing the full value within the allotted space of 8 columns, and displayed without the use of fractional output.
Scaling is done by repetitively dividing by a scale factor of 1000.
Scaling is done by repetitively dividing by a scale factor of 1024.
对于大于 2 GB 的块设备,最多可以将其 263 -1 个字节完全用作交换空间。
有关影响 swap 执行的环境变量 LC_CTYPE 和 LC_MESSAGE 的描述,请参见 environ(7)。
有关下列属性的说明,请参见 attributes(7):
|
pagesize(1), getpagesize(3C), vfstab(5), attributes(7), mkfile(8), shareall(8), zfs(8), zfs_encrypt(8)
For information about setting up a swap area with ZFS, see the book Managing ZFS File Systems in Oracle Solaris 11.4.
不会进行检查以确定要添加的交换区域是否与现有文件系统重叠。
Support for the –scale option was added to the swap command in Oracle Solaris 11.4.30.
The encrypted column was added to the output of the –l option in Oracle Solaris 11.4.24.
The –h and –k options were added to the swap command in Oracle Solaris 11.0, thanks to a contribution by Yann Poupet to the OpenSolaris project.
The swap command; with support for the –a, –d, –l, and –s options; was added to Solaris in the Solaris 2.0 release, replacing the swapon command used in SunOS 4.