How to modify and delete Swap virtual memory size in Centos

Source: Internet
Author: User

1. Complete the steps to modify swap:

[Root @ gamedb ~] # Free-m
[Root @ gamedb tmp] # dd if =/dev/zero of =/tmp/big_swap bs = 1024 count = 2000000
[Root @ gamedb tmp] # du-sh/tmp/big_swap
[Root @ gamedb tmp] # mkswap/tmp/big_swap
[Root @ gamedb tmp] # swapon/tmp/big_swap
[Root @ gamedb tmp] # free-m
[Root @ gamedb tmp] # vi/etc/fstab
# LABEL = SWAP-hda2 swap defaults 0 0
/Tmp/big_swap swap defaults 0 0

1. Check the memory and swap size, and find that swap is half of the memory size.

[Root @ localhost tmp] # free-m
Total used free shared buffers cached
Mem: 772 91 681 0 6 30
-/+ Buffers/cache: 53 718
Swap: 1567 0 1567

2. Determine the swap size. First, create a swap file for partitioning in the appropriate space:

[Root @ localhost tmp] # dd if =/dev/zero of =/tmp/big_swap bs = 1024 count = 2000000
Recorded 2000000 + 0 reads
Records 2000000 + 0 writes
2048000000 bytes (2.0 GB) copied, 69.5342 seconds, 29.5 MB/second
(Note: if indicates infile, of indicates outfile, bs = 1024 indicates that the size of each block to be written is 1024B = 1KB (1024B bytes = 1024 * 8bit)

3. Check whether the size of the created file meets the requirements:

[Root @ localhost tmp] # du-sh big_swap
2.0G big_swap
[Root @ localhost tmp] # ls-al big_swap

-Rw-r -- 1 root 2048000000 14:25 big_swap

4. Set the target file to a swap partition file:

[Root @ localhost tmp] # mkswap big_swap
Mkswap: big_swap: warning: don't erase bootbits sectors
On whole disk. Use-f to force.
Setting up swapspace version 1, size = 1999996 KiB
No label, UUID = 25c3eaf2-43f9-440b-87b7-f76a712f5376

5. Activate swap and enable swap partition file immediately:

[Root @ localhost tmp] # swapon big_swap
6. Check the memory and virtual memory again and find that it has been properly modified:

[Root @ localhost tmp] # free-m
Total used free shared buffers cached
Mem: 772 705 66 0 2 627
-/+ Buffers/cache: 75 697

Swap: 3521 0 3521
7. If you want to enable it at startup, modify the swap lines in the file/etc/fstab:

[Root @ gamedb tmp] # vi/etc/fstab
# LABEL = SWAP-hda2 swap defaults 0 0
/Tmp/big_swap swap defaults 0 0


II. Delete swap partitions

Sometimes you may need to delete the swap partition. How can you delete the partition correctly?
Stop swap partition first

Swapoff/swap

Delete a swap partition file

Rm-rf/swap

Delete the specified File "/etc/swap"

Sed-I "/'\/swa \/swap defaults 0 0' //"/etc/fstab

In this way, you can manually add and delete swap partitions.

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.