How to increase virtual memory in Ubuntu

Source: Internet
Author: User

The following error occurred while compiling a software system today:

Virtual Memory Exhausted:cannot Allocate memory

To resolve this issue, locate the following solution.

1, open the terminal, switch to the root user, enter: free-m View memory status
[Email protected] lxt]# free-m
Total used free shared buffers Cached
mem:498 357 141 0 27 162
-/+ buffers/cache:167 331
swap:1023 0 1023
2. Enter Df-b M (or df-m) to view the current usage of each partition
[Email protected] lxt]# Df-b M
File system 1m-block already used% mount point available
/dev/mapper/vg_lxt-lv_root
12875M 4059M 8162M 34%/
/dev/sda7 194M 14M 170M 8%/boot
Tmpfs 250M 1M 249M 1%/DEV/SHM
(Fdisk-l can see the disk partition condition)
3. Select a larger partition to create the partition file:
[[email protected] lxt]# dd If=/dev/zero of=/swapadd bs=1024 count=524288
524288+0 Records in
524288+0 Records out
536870912 bytes (537 MB) copied,13.0709 sec, 41.1 mb/sec
The above command creates a new virtual memory file named Swapadd with a size of 512M in the root directory
4. Move the file to another partition with a larger space:
[Email protected] lxt]# Mkdir/mnt/swap
[Email protected]/]# MV Swapadd/mnt/swap
5. Execute the following command to enable virtual memory and restart the computer
[Email protected]/]# Mkswap/mnt/swap/swapadd
Setting up Swapspace version 1, size = 524284 KiB
No label, UUID=A5C8B651-6F64-4414-BB5F-580B742ACFCE
[Email protected]/]# Swapon/mnt/swap/swapadd
To view memory:
[Email protected]/]# free-m
Total used free shared buffers Cached
mem:498 492 6 0 15 302
-/+ buffers/cache:174 323
swap:1535 0 1535
6. If you do not need to use the new virtual memory, enter:
Swapoff-v/mnt/swap/swapadd

Extended:

If you need to keep this swap, you can change sudo-s to root
Then write it to the/etc/fstab file.

Swapadd path Swap defaults 0 0

Clear Linux cache use spot on light today to check the memory footprint of the development server, leaving only 60MB the following method can be used to clear cache frequent file access can cause the system to greatly increase the cache usage
First use Free-m to view the remaining memory [[email protected]oracle ~]# free-m
Total used free shared buffers Cached
mem:3383 3319 the0 97 2395
-/+ buffers/cache:826 2556
swap:1983 195 1788

Total memory count used the amount of memory that has been used free the total memory shared by multiple processes

Note that it is best to sync before releasing to prevent data loss.

How to use: sync
Instruction for use: The data in the Linux system to write to the hard disk is sometimes more efficient,

Will write to filesystem buffer, which is a memory space,

If the data to be written to the hard disk is stored in this buffer, and the system suddenly loses power,

Then the data will be lost, and the Sync command will force the data stored in buffer to be written to the hard disk.

[[Email protected]oracle ~]# echo 1 >/proc/sys/vm/drop_caches
[Email protected] ~]# sysctl-p


[Email protected] ~]# free-m
Total used free shared buffers Cached
mem:3383 1952 14310 1 1136
-/+ buffers/cache:814 2568
swap:1983 195 1788

Description
1>. /proc is a virtual file system that we can use to read and write as a means of communicating with kernel entities. This means that you can make adjustments to the current kernel behavior by modifying the files in the/proc. This means that we can release the memory by adjusting the/proc/sys/vm/drop_caches. 0– not release
-Free Page Cache
Release Dentries and Inodes
3– releases all cached digits 1 is used to empty the most recently asked Files page cache number 2 is used to empty the file node cache and directory entry cache number 3 is used to empty the cache of 1 and 2 of all content. 2>. The official notes on Drop_caches are as follows: Writing to this file causes the kernel to drop clean caches,dentries and inodes from memory, causing That memory to Becomefree.
To free Pagecache with use echo 1 >/proc/sys/vm/drop_caches;
to free dentriesand inodes, use echo 2 >/proc/sys/vm/drop_caches;
To free Pagecache, dentries and inodes, use Echo 3 >/proc/sys/vm/drop_caches.
Because This is a non-destructive operation and dirty objects was not freeable, the user should run sync first. 3>. LinuxThe kernel caches its most recently accessed file pages in memory for a period of time, and this file cache is called Pagecache. The inode is a data structure in the Linux/unix operating system that contains important information about each file. When you create a file system, you create a large number of inode at the same time. The General Inode table consumes 1% of the file system disk space.

Catalog Item Cache (Dcache) dentries

The meaning of each parameter:
Total: Overall physical memory
Used: Memory is used
Free: Memory that has not been used completely
Shared: Application Shared memory
Buffers: Cache, mainly used for directory aspects, inode values, etc.
Cached: Cache, for files that have been opened
-buffers/cache: The amount of memory used by the application, used minus the cached value
+buffers/cache: The amount of memory available to the application, free plus the cache value where:
Total = used + Free
-buffers/cache=used-buffers-cached, this is the memory size that the application actually uses
+buffers/cache=free+buffers+cached, this is the memory size that the server can actually use.
[Email protected] ~]$ free-m
Total used free shared buffers Cached
mem:32096 10379 21717 0 38 7942
-/+ buffers/cache:2398 29698
swap:34287 0 34287
The second line in this is the real server's free memory 2. Linux memory allocation method as we all know, Linux servers in order to improve efficiency, will be early application of memory, even if the memory is not used by specific applications, Linux will apply for these memory in advance, and then use these memory for caching, the newly opened file system into the cache, This corresponds to the server free value will be less, buffers and cached will be more and more large, so to everyone's appearance is less memory, everyone is nervous; in fact, everyone is not nervous, Linux server in the discovery of low memory, will automatically clean up the cached area, free memory , and then continue to increase cache,free continue to decrease. Therefore, the way to manually reduce memory usage, in fact, is the picture of the fast, hehe.

Echo 1 >/proc/sys/vm/drop_caches can temporarily empty cache and buffer

On Rhel5 and Ubuntu (Rhel4 not possible), you can modify the kernel file directly
#/etc/sysctl.conf
Vm.drop_caches = 1

#sysctl-P

$ sync
$ free-m
Total used free shared buffers Cached
mem:32096 30084 2011 0 590 26162
-/+ buffers/cache:3332 28764
swap:34287 0 34287
Echo 3 >/proc/sys/vm/drop_caches
Free-m

Originally thought that the Oracle cache was full, enter the ALTER system flush BUFFER_CACHE;ALTER system flush shared_pool in Sqlplus; But look at the effect is not obvious behind try Linux clear ARP cache
One Arp-n|awk '/^[1-9]/{print ' arp-d ' $ ' | Sh
Clear all ARP caches, recommended!
Second, for ((ip=2;ip<255;ip++));d o arp-d 192.168.0. $ip &>/dev/null;done
Clears all caches for the 192.168.0.0 network segment
Third, arp-d IP
This clears the ARP cache for a single IP note: The above requires root privileges, especially the last one, if it is no longer executed under root, instead: Arp-n|awk '/^[1-9]/{print ' arp-d '} ' | sudo sh

How to increase virtual memory in Ubuntu

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.