Linux modifies swap virtual memory size

Source: Internet
Author: User
Tags uuid

Swap is the memory swap area; in other words, if the memory is not enough, then the system will store some infrequently used data on the hard disk, then this part of the data in the storage to be broken down, so that the memory of the remaining space to run the east, this process is called exchange, The part of the hard disk that stores the data is the swap partition. When the system is installed, the swap size may be set incorrectly but the swap size is incorrect, which affects the performance of the server. Let's talk about how to modify the size of the swap partition.

1. View System swap space usage
 free-m             total       used       free     shared    buffers     Cachedmem:           1006        753        252                    3         526-/+ Buffers/cache:        195        810Swap:                   0        -

2. Create swap file

 [[email protected] mapper]# CD/usr[[email protected] usr]#  Span style= "COLOR: #0000ff" >mkdir   swap[[email protected] usr]# CD swap[[ Email protected] swap]# ll total dosage  0  [[ Email protected] swap]#  dd  if  =/dev/zero of=/usr/swap/swapfile1 bs=1024  count= 1000000   recorded 1000000  +0   1000000  +0   Write 1024000000 bytes ( 1.0  GB) copied, 5.40277  seconds, 190  MB/s 

(Note: If means infile,of means that outfile,bs=1024 represents the size of each block written to 1024b=1kb (1024B bytes =1024*8bit bits)

3. View the size of the created file

du -sh /usr/swap/swapfile1977m    /usr/swap/swapfile1

4. Set the target file to a swap partition file

[[email protected] swap]# mkswap/usr/swap/1999996  kibno label, UUID= 7eec8e34-e5d9-48f7-aa71-028268a48e46

5. Activate swap to enable swap partition file immediately

[Email protected] swap]# Swapon/usr/swap/swapfile1

6, if you want to enable the power-on, you need to modify the swap line in the file/etc/fstab
VI /etc/fstab
## /etc/fstab# Created by Anaconda on Mon may One  +: *: -  -# # Accessible filesystems, by reference, is maintained under'/dev/disk'# SeeMansPages Fstab (5), Findfs (8),Mount(8) and/or Blkid (8) for  More Info#/DEV/MAPPER/VG_LOCALHOST-LV_ROOT/EXT4 defaults1 1UUID=cef520a0-df77-4ce1-8856-514d154c816d/boot EXT4 Defaults1 2#/dev/mapper/vg_localhost-lv_swap Swap swap Defaults0 0/usr/swap/swapfile1 Swap swap Defaults0 0Tmpfs/DEV/SHM TMPFS Defaults0 0devpts/dev/pts devpts gid=5, mode=620  0 0Sysfs/sys SYSFS Defaults0 0proc/PROC proc Defaults0 0
Restart the system to take effect.

Fstab file Details

The

Fstab contains important information about the partition, where each behavior is a partition record, each row can be divided into six parts, the following/dev/hda7/ext2 defaults 1 1 As an example of: 
1) The first item is the physical location of the storage device you want to mount, such as HDB or/DEV/HDA6.
2) The second item is where you want to add to the directory location, such as/home or/, which is actually the point at which the installation prompts for the mount.
3) The third item is the so-called local filesystem, which contains the following formats: ext, ext2, MSDOS, iso9660, NFS, swap, etc., or as ext2, see/prco/filesystems instructions.
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, async), which can be found in "mount nfs".
5) The fifth item is to provide the dump function, whether the system dump requires backup flag bit, the value is 0. This option is used by the dump command to check how fast a file system should dump and set the field to 0 if the dump is not required.
6) The six is to set the filesystem whether to do check at boot, in addition to root filesystem its necessary check is 1, the others are required to set, the default value is 0. This field is used by the fsck command to determine the order of the file systems that need to be scanned at startup, the root filesystem/pair should have a value of 1, and the other filesystem should be 2. If the file system does not need to be scanned at startup, the field is set to 0.

Fourth option parameter
RO load the file system in read-only mode
Sync does not buffer the write operation of the device, which prevents the file system from being corrupted when it is not properly shut down, but slows down the computer
User allows a normal user to load the file system
Quota forcing a disk quota limit on this file system
Noauto no longer uses the MOUNT-A command (such as when the system starts) to load the file system
Noexec (do not allow executable file executable, but do not put the root partition as NOEXEC, then can not use the system, even the mount command can not be used, then only to re-do the system!
Nodev (not allowed to mount device files)
Nosuid,nosgid (Suid and Sgid properties are not allowed)
Nouser (do not allow normal user to mount)

If you want to boot on the mount, you can add the following lines on the/etc/fstab, as well as mount in the/etc/rc.d/rc.local:
/dev/hda5/mnt/d vfat exec,dev,suid,rw,umask=0,iocharset=gb2312,codepage=936 0 0
/dev/hda6/mnt/e vfat exec,dev,suid,rw,umask=0,iocharset=gb2312,codepage=936 0 0
/dev/hda7/mnt/f vfat exec,dev,suid,rw,umask=0,iocharset=gb2312,codepage=936 0 0
/dev/hda8/mnt/g vfat exec,dev,suid,rw,umask=0,iocharset=gb2312,codepage=936 0 0

Linux modifies swap virtual memory size

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.