Linux内存、缓存、Swap等修改

1. Linux 修改系统内存大小:修改启动文件,增加mem=300M,如下:vi /boot/grub/grub.conf……title CentOS (2.6.18-194.3.1.el5_lustre.1.8.4)root (hd0,0)kernel /vmlinuz-2.6.18-194.3.1.el5_lustre.1.8.4 ro root=LABEL=/ mem=300M……保存重启即可。2. linux下释放cache内存/proc是一个虚拟文件系统,我们可以通过对它的读写操作做为与kernel实体间进行通信的一种手段.也就是说可以通过修改/proc中的文件,来对 当前kernel的行为做出调整.那么我们可以通过调整/proc/sys/vm/drop_caches来释放内存.操作如下:[root@server test]# cat /proc/sys/vm/drop_caches0首先,/proc/sys/vm/drop_caches的值,默认为0[root@server test]# sync手动执行sync命令,防止丢失数据(描述:sync 命令运行 sync 子例程。如果必须停止系统,则运行 sync 命令以确保文件系统的完整性。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件)[root@server test]# echo 3 > /proc/sys/vm/drop_caches[root@server test]# cat /proc/sys/vm/drop_caches3将/proc/sys/vm/drop_caches值设为3[root@server test]# cat /proc/meminfo有关/proc/sys/vm/drop_caches的用法在下面进行了说明cache释放:To free pagecache:echo 1 > /proc/sys/vm/drop_cachesTo free dentries and inodes:echo 2 > /proc/sys/vm/drop_cachesTo free pagecache, dentries and inodes:echo 3 > /proc/sys/vm/drop_caches3. 怎样添加、删除、移动Linux下的 Swap 空间You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available. 3.1 To add a swap partition (assuming /dev/hdb2 is the swap partition you want to add): 3.1.1 The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The easiest way to achieve this it to boot your system in rescue mode. Refer to Red Hat Linux Manuals Chapter 8 for instructions on booting into rescue mode. When prompted to mount the filesystem, select Skip.Alternately, if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the swapoff command.3.1.2 Create the swap partition using parted or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with parted.At a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the hard drive with free space.At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.At the (parted) prompt, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.3.1.3Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following: mkswap /dev/hdb23.1.4 To enable the swap partition immediately, type the following command: swapon /dev/hdb23.1.5To enable it at boot time, edit /etc/fstab to include:LABEL=/dev/hdb2 swap swap defaults 0 03.1.6 The next time the system boots, it will enable the new swap partition. 3.1.7After adding the new swap partition and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.3.2 To add a swap file3.2.1Determine the size of the new swap file and multiple by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.3.2.2At a shell prompt as root, type the following command with count being equal to the desired block size:dd if=/dev/zero of=/swapfile bs=1024 count=655363.2.3To enable the swap file immediately but not automatically at boot time:swapon /swapfile3.2.4The next time the system boots, it will enable the new swap file.3.2.5After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.3.3 Removing Swap SpaceTo remove a swap partition: 3.3.1.The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The easiest way to achieve this it to boot your system in rescue mode. Refer to Red Hat Linux Manuals Chapter 8 for instructions on booting into rescue mode. When prompted to mount the filesystem, select Skip.Alternately, if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the swapoff command.3.3.2.At a shell prompt as root, execute the following command to make sure the swap partition is disabled (where /dev/hdb2 is the swap partition):swapoff /dev/hdb2 3.3.3.Remove its entry from /etc/fstab.3.3.4.Remove the partition using parted or fdisk. Only parted will be discussed. To remove the partition with parted:3.4 To remove a swap file3.4.1.At a shell prompt as root, execute the following command to disable the swap file (where /swapfile is the swap file):swapoff /swapfile3.4.2.Remove its entry from /etc/fstab.3.4.3.Remove the actual file:rm /swapfile3.5 Moving Swap Space3.5.1 To move swap space from one location to another, follow the steps for removing swap space, and then follow the steps for adding swap space.3.5.2 To enable it at boot time, edit /etc/fstab to include.

1. 关闭swap空间:swapon -s

关闭swap盘,例如:

swapoff /dev/sdb3

(使用 free -m查看)

2. 删除入口:vi /etc/fstab 注释掉swap那一行

3.删除swap分区: fdisk /dev/sdb

重启

一定要记得挺身而出,即便帮不了忙,安慰也是最大的支持.

Linux内存、缓存、Swap等修改

相关文章:

你感兴趣的文章:

标签云: