View and modify the swap space

Source: Internet
Author: User

1. view the swap space (total ):
# The default unit of Free-M is K, and the unit of-M is M.
Total used free shared buffers cached
Mem: 377 180 197 0 19 110
-/+ Buffers/cache: 50 327
Swap: 572 0 572

 

2. view the swap space (file (s)/partition (s )):

Including file and partition details

# Swapon-S
Equivalent
# Cat/proc/SWAPs

 

3. Add swap space
Two options: Add a swap partition or add a swap file. We recommend that you add a swap partition. However, if you do not have much free space available, you can add swap files.

3.1 Add a swap Partition
The procedure is as follows:
A uses fdisk to create swap partitions (assuming/dev/sdb2 is the swap partition created)
B. Use the mkswap command to set the swap partition:
# Mkswap/dev/sdb2
C enable swap partition:
# Swapon/dev/sdb2
D write/etc/fstab to enable it during boot:
/Dev/sdb2 swap defaults 0 0

3.2 add an exchange file
A creates a m swap file:
# Dd If =/dev/Zero of =/swapfile1 BS = 1024 k count = 512
B. Use the mkswap command to set the swap file:
# Mkswap/swapfile1
C enable swap partition:
# Swapon/swapfile1
D write/etc/fstab to enable it during boot:
/Swapfile1 swap defaults 0 0

After a new swap partition is added and enabled, check the output of CAT/proc/SWAPs or the free command to ensure that the swap partition is enabled.

4. delete a swap space:
A disable swap partition:
# Swapoff/dev/sdb2
B. Delete the project from/etc/fstab;
C. Use fdisk or YaST to delete a partition.

The process for deleting a swap file is the same as that for deleting a swap file.

 

 

 

# Free-m
Total used free shared buffers cached
Mem: 377 180 197 0 19 110
-/+ Buffers/cache: 50 327
Swap: 572 0 572

 

The mem row shows the memory usage from the system perspective. Total indicates the available memory size of the system, which is equal to the physical memory of the system minus the memory reserved by the kernel.
Buffers and cached are the memory used by the system as a buffer. buffers is associated with a block device, including the metadata of the file system, and tracks block changes. The cache only contains the file itself.

-/+ The buffers/cache row displays the memory information from the user's perspective. The number of available memory is equal to the used column value of the mem row minus the size of the buffers and cached memory.

Since buffers and cached are set by the operating system to speed up system running, they can only be used as needed by users.

 

Top displays the dynamic and real-time status of processes (CPU and memory) during system running)

The top table contains three columns, virt res SHR, which indicate the memory usage of the process.
Virt identifies the total memory size that a process can use, including the memory actually used by the process, mapped files, and memory shared with other processes.
Res indicates the memory occupied by the process.
SHR identifies the memory and library size that can be shared with other processes.

Vmstat displays memory usage

These commands READ memory information from/proc/meminfo.

The meanings of each line in/proc/meminfo are described in the documentation/filesystems/proc.txt file of the kernel source code.

The actual memory size of the system can be viewed in dmesg | grep [mm] [EE] [mm ].

/Proc/Pid/status: displays the detailed status of a process.
# Cat, Proc, 5346, and status
Name: Bash
State: S (sleeping)
Sleepavg: 98%
Tgid: 5346
PID: 5346
Ppid: 5343
Tracerpid: 0
UID: 1000 1000 1000 1000
GID: 104 104 104 104
Fdsize: 256.
Groups: 6 24 29 44 104 113 1000
Vmpeak: 6528 KB
Vmsize: 6528 KB
Vmlck: 0 KB
Vmhwm: 1976 KB
Vmrss: 1976 KB
Vmdata: 752 KB
Vmstk: 84 KB
Vmexe: 644 KB
Vmlib: 1788 KB
Vmpte: 16 KB
Threads: 1
Sigq: 0/4294967295
Sigpnd: 0000000000000000
Shdpnd: 0000000000000000
Sigblk: 0000000000000000
Sigign: 0000000000384004
Sigcgt: 255.255.4b813efb
Capinh: 0000000000000000
Cappr: 0000000000000000
Capeff: 0000000000000000

Vmsize indicates the total memory size of the process, which is consistent with the virt in the top output.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.