Linux frees CPU&GPU memory, video memory, and hard drive __linux

Source: Internet
Author: User
Tags memory usage

free-m

Free-m
              Total        used        free      shared  buff/cache   available
Mem:         128831       15666       23617         406       89547      111448
Swap:        130986        130977       9      

Total Memory
used the number of memory already in use
Free amount of memory
Total memory shared by multiple processes
Buffers buffer cache and cached Page cache disk size
-buffers/cache (used) Memory: used-buffers-cached
Number of +buffers/cache (available): Free + buffers + Cached
Available Memory=free memory+buffers+cached

Typically, Buff/cache occupies a particularly large amount of memory

sudo apt-get install sysinfo
sysinfo #查看系统信息
sudo apt-get install hardinfo hardinfo
#查看硬件信息

Why does Buffer/cache occupy so much memory?

Cache : buffer, is the cache, is located between the CPU and the main memory of the small but fast memory, because the CPU speed is much higher than the speed of the main memory, the CPU from memory to read data to wait a long time, and Cache Save the CPU just used data or recycled part of the data, then read data from the cache will be faster, reduce the CPU waiting time, improve the performance of the system.
Cache is not cached files, but the cache block (block is I/O read and write the smallest unit), the cache is generally used in I/O requests, if multiple processes to access a file, you can read this file into the cache, This next process acquires CPU control and accesses the file to read directly from the cache, improving system performance.

Buffer : buffers that transmit data between devices that are not synchronized with the device or with different priorities, and buffer can reduce the time that interprocess communication takes to wait, and when the storage speed device communicates with the slow-storage device, Storing slow data first store data into buffer, to a certain extent store fast device and then read buffer data, during which storage fast device CPU can do other things.

Buffer: Typically used to write to disk, for example: a process requires multiple fields to be read, and when all required fields are read into the fields that have been read before will be placed in the buffer.

Buffer/cache is often used more frequently when the program accesses files, and the physical memory is quickly exhausted.
When the program is finished, the memory is not released normally, but becomes the cache state.

Linux available memory enough why swap?

The size of the kernel parameter swappiness determines when Linux starts to use swap.

Swappiness=0 represents the maximum possible use of physical memory to avoid swapping into swap.
Swappiness=100 time to maximize the use of the swap partition, and the memory of the data in a timely manner to swap space inside.
The basic default setting for this value Linux is 60, and different distributions may be slightly different.

The view commands are as follows:

Cat/proc/sys/vm/swappiness
60

This means that when the memory is used to 40% (100%-60%), the system will begin to use the swap partition.
Memory speed will be much faster than disk, which will increase the system IO, at the same time to create a large number of pages in the swap, seriously affect the performance of the system, so at the operating system level, to use as much memory as possible, to adjust this parameter.

Adjust Values

Sysctl vm.swappiness=10
vm.swappiness =

10 cat/proc/sys/vm/swappiness

The reboot is still in effect and needs to be modified in/etc/sysctl.conf:

cat/etc/sysctl.conf
vm.swappiness =

sysctl-p

Swap Cleanup

Sync         #将内存缓冲区数据立刻同步到磁盘
swapoff-a   # Close all swap
swapon-a    #启用所有swap

Note: This cleanup has a prerequisite that the free memory must be larger than the swap space already in use

Cache Cleanup

1.free-m 
  cat/proc/meminfo  
2.sudo-i
3.cat/proc/sys/vm/drop_caches
4.sync  # Run sync to write the contents of the dirty back to the hard disk and synchronize the data. Writes all buffers that are in memory to disk, including files that have been modified, deferred block I/O, and read-write mapping files to ensure the integrity of the file system
-----------------------------------------
-----------------------------------------
#通过修改proc系统的drop_caches清理free的cache
#Freeing up the Page Cache # Free Page caching
5.echo 1 >/proc/sys/vm/drop_caches #free pagecache
6.sync  #运行sync将dirty的内容写回硬盘, sync data.  Writes all buffers that are in memory to disk, including files that have been modified, deferred block I/O, and read-write mapping files to ensure the integrity of the file system #Freeing up the
dentries and Inodes Release dentries and Inodes
7.echo 2 >/proc/sys/vm/drop_caches # free dentries and inodes
8.sync
------------ -----------------------------
-----------------------------------------
#Freeing up the Page Cache, Dentries and Inodes releases all caches
9.echo 3 >/proc/sys/vm/drop_caches
10.cat/proc/sys/vm/drop_caches
11. Free-m

You can transform a number at a time.

Long command

sudo su  # into the root account
sudo su-c ' free-m && sync && echo 3 >/proc/sys/vm/drop_caches && Sync && free-m '
0– does not release
the 2– release page cache release
dentries and Inodes
3– release all Caches

Memory Release Script

New freemen.sh

CD root
mkdir toolsetting
cd toolsetting
gedit freemen.sh

Add the following content

#!/bin/bash

used= ' free-m | awk ' nr==2 ' | awk ' {print $} '
free= ' free-m | awk ' nr==2 ' | awk ' {print $} '

EC Ho "===========================" >>/var/log/mem.log
date >>/var/log/mem.log
echo Memory Usage | [USE:${USED}MB] [FREE:${FREE}MB] ">>/var/log/mem.log

sync && echo 1 >/proc/sys/vm/drop_caches
Sync & & Echo 2 >/proc/sys/vm/drop_caches
sync && echo 3 >/proc/sys/vm/drop_caches
echo "OK" >> ; /var/log/mem.log
echo "not required" >>/var/log/mem.log

Add the script to the Crond task, timed to execute.

Crontab-e #添加定时任务

Add the following command, executed every 2 minutes

*/2 * * * * root/root/toolsetting/freemem.sh

Note : Crontab The first fifth field in the integer value range and significance is:
0~59-
1~23 means hours
1~31 said Day
1~12 represents the Month
0~6 said week (of which 0 said Sunday)

permissions to modify scripts

chmod 777/root/toolsetting/freemem.sh

Start Timer service

Service Crond Stop
service Crond start

View timed Tasks

Crontab-l

View Results

Tail-f/var/log/mem.log  
===========================
May 10, 2017 Wednesday 09:02:01 CST
Memory Usage | [USE:15729MB] [FREE:99379MB]
OK not
required
===========================
May 10, 2017 Wednesday 09:03:01 CST
Memory Usage | [USE:15733MB] [FREE:111141MB]
OK not
required
===========================
May 10, 2017 Wednesday 09:04:01 CST
Memory Usage | [USE:15738MB] [FREE:110174MB]
OK not
required
===========================
May 10, 2017 Wednesday 09:05:02 CST
Memory Usage | [USE:15742MB] [FREE:111135MB]
OK not
required
===========================
May 10, 2017 Wednesday 09:06:01 CST
Memory Usage | [USE:15758MB] [FREE:111117MB]
OK not
required
===========================
May 10, 2017 Wednesday 09:07:01 CST
Memory Usage | [USE:15772MB] [FREE:110138MB]
OK not
required

release the hard drive for example

After installing this series of software, perhaps want to clean up the system to release a little hard disk space, enter the following command

sudo apt-get-y autoremove 
sudo apt-get-y autoclean 
sudo apt-get-y clean

GPU

# View video card performance test

sudo apt install mesa-utils
Method One
The #lspci command is used to display all PCI bus information for the current host, and all connected PCI device information
#lspci only enumerates devices that use PCI (including the PCIe) bus;
If a device is not on the PCI bus, the command is not listed
Lspci  | Grep-i VGA  #查看显卡信息
lspci  | grep-i nvidia  #查看nvidia显卡信息
Lspci |  Egrep ' vga|3d ' # Displays all graphics information
nvidia-smi  #查看gpu使用情况
nvidia-settings #设置GPU参数, such as fan running speed
Watch-n 1 Nvidia-smi #实时显示, with watch command, let one second refresh
NVIDIA-SMI-L # List all available NVIDIA devices
sudo fuser-v/dev/nvidia* #查找占用GPU资源的PID
sudo kill-9 * * * (PID)  # Unlock memory footprint
Method Two

to cool the graphics card

ubuntu16.04 Nvidia video card fan speed and startx consequences

Reference Home

Https://linux.cn/article-5573-3.html
http://blog.csdn.net/kongxx/article/details/51678487

Buff/cache Content Release

Linux available memory enough why swap

Crontab implementation executes a shell script at timed intervals (for example, once every 10 minutes)

Related Article

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.