Linux Set swap (virtual memory area) __linux

Source: Internet
Author: User

[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

===========================================================================================

First, look at the memory and swap sizes and find that swap is half the size of memory

[Root@gamedb ~]# Free-m

Total used free shared buffers Cached

MEM:1001 338 662 0 8 307

-/+ buffers/cache:22 978

swap:509 0 509

===========================================================================================

Second, decide to modify the swap size, first create a swap file for the partition at the appropriate place in space:

[Root@gamedb tmp]# dd If=/dev/zero of=/tmp/big_swap bs=1024 count=2000000

Read the 2000000+0 block.

Output 2000000+0 block.

(Note: If the infile,of represents a outfile,bs=1024 representation of the size of each block written is 1024b=1kb (1024B byte =1024*8bit bit)

===========================================================================================

Third, to see whether the file size is created to meet the requirements:

[Root@gamedb tmp]# Du-sh Big_swap

2.0G Big_swap

[Root@gamedb tmp]# Ls-al Big_swap

-rw-r--r--1 root root 2048000000 June 11:55 big_swap

===========================================================================================

Set the destination file as a swap file:

[Root@gamedb tmp]# Mkswap Big_swap

Setting up Swapspace version 1, size = 2047995 KB

===========================================================================================

Activate swap to enable swap partition files immediately:

[Root@gamedb tmp]# Swapon Big_swap

===========================================================================================

Vi. view memory and virtual memory again, and found that it has been modified normally:

[Root@gamedb tmp]# Free-m

Total used free shared buffers Cached

mem:1001 984 16 0 2 931

-/+ buffers/cache:50 950

swap:2462 0 2462

===========================================================================================

If you want to enable it when you turn on, you need to modify the swap line 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

===========================================================================================

Attached: Fstab documents detailed:

The fstab contains important information about the partition, each of which is a partition record, each row can be divided into six parts, and the following is an example of/DEV/HDA7/EXT2 defaults 1 1:

1. The first item is the physical location of the storage unit you want to mount, such as HDB or/DEV/HDA6.

2. The second item is where you want to add it to the directory location, such as/home or/, which is actually the mount point that is prompted at installation time.

3. The third item is the so-called local filesystem, which includes the following formats: ext, ext2, MSDOS, iso9660, NFS, swap, or, for example, Ext2, can refer to the/prco/filesystems description.

4. The fourth item is the state you want to set when you mount, such as RO (read-only) or defaults (including other parameters such as RW, suid, exec, auto, Nouser, <

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.