惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
L
LINUX DO - 最新话题
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
V
Visual Studio Blog
Attack and Defense Labs
Attack and Defense Labs
O
OpenAI News
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
B
Blog RSS Feed
H
Help Net Security
量子位
小众软件
小众软件
SecWiki News
SecWiki News
N
Netflix TechBlog - Medium
TaoSecurity Blog
TaoSecurity Blog
美团技术团队
博客园 - 司徒正美
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Cloudflare Blog
N
News and Events Feed by Topic
C
Cybersecurity and Infrastructure Security Agency CISA
The Last Watchdog
The Last Watchdog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Scott Helme
Scott Helme
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Application and Cybersecurity Blog
Application and Cybersecurity Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
Schneier on Security
Schneier on Security
G
Google Developers Blog
Forbes - Security
Forbes - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Y
Y Combinator Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
A
Arctic Wolf
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Hacker News
The Hacker News
B
Blog
D
DataBreaches.Net
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - ricks

解决VS Code安装golang相关插件失败问题 努力就会成功(转自左耳朵耗子) 最全科普!你一定要了解的NB-IoT LTE - NAS 驻网流程概括 PLMN概念和应用设置 3GPP R14中的6大NB-IoT增强技术 与程序员相关的CPU缓存知识 IoT协议LwM2M MQTT与CoAP 别让自己“墙”了自己(转自耗子叔) NB-IoT的介绍最终版 !看明白了吗?(转自 top-iot) C语言函数sscanf()的用法 GPRS骨干网逻辑结构 GSM与GPRS的区别 SA vs NSA 打造高效的工作环境 – SHELL 篇 清理系统缓存 iptables禁止某个mac地址上网 使用iptables基于MAC地址进行访控 iptables的MAC地址过滤
linux下怎么清理缓存
ricks · 2019-01-30 · via 博客园 - ricks

free -m 命令可以查看内存使用情况                   

sysctl 命令可以临时改变某个系统参数  如:sysctl -w net.ipv4.ip_forward=1 是将forware参数临时改为1 当 service network restart后 失效.

我们在清理缓存前应该先

sync下

因为系统在操作的过程当中,会把你的操作到的文件资料先保存到buffer中去,因为怕你在操作的过程中因为断电等原因遗失数据,所以在你操作过程中会把文件资料先缓存。

所以我们在清理缓存先要先把buffe中的数据先写入到硬盘中,sync命令

上面的echo 3 是清理所有缓存

echo 0 是不释放缓存

echo 1 是释放页缓存

ehco 2 是释放dentries和inodes缓存

echo 3 是释放 1 和 2 中说道的的所有缓存

说明:
1>. /proc是一个虚拟文件系统,我们可以通过对它的读写操作作为与kernel实体间进行通信的一种手段。也就是说可以通过修改/proc中的文件,来对当前kernel的行为做出调整。也就是说我们可以通过调整/proc/sys/vm/drop_caches来释放内存。

0 – 不释放
1 – 释放页缓存
2 – 释放dentries和inodes
3 – 释放所有缓存

数字1是用来清空最近放问过的文件页面缓存

数字2是用来清空文件节点缓存和目录项缓存

数字3是用来清空1和2所有内容的缓存。

2>. 关于drop_caches的官方说明如下:

Writing to this file causes the kernel to drop clean caches,dentries and inodes from memory, causing that memory to becomefree.
To free pagecache, use echo 1 > /proc/sys/vm/drop_caches;
to free dentries and 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 are not freeable, the user should run sync first.

3>. Linux内核会将它最近访问过的文件页面缓存在内存中一段时间,这个文件缓存被称为pagecache。

Inode是linux/unix操作系统中的一种数据结构,包含了各文件相关的一些重要信息。在创建文件系统时,就会同时创建大量的inode。一般inode表会占用文件系统磁盘空间的1%。

目录项缓存(dcache)dentries

各参数含义:
total:总物理内存
used:已使用内存
free:完全未被使用的内存
shared:应用程序共享内存
buffers:缓存,主要用于目录方面,inode值等
cached:缓存,用于已打开的文件
-buffers/cache:应用程序使用的内存大小,used减去缓存值
+buffers/cache:所有可供应用程序使用的内存大小,free加上缓存值

其中:
total = used + free
-buffers/cache=used-buffers-cached,这个是应用程序真实使用的内存大小
+buffers/cache=free+buffers+cached,这个是服务器真实还可利用的内存大小

[oracle@cddserver1 ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:         32096      10379      21717          0         38       7942
-/+ buffers/cache:       2398      29698
Swap:        34287          0      34287
这里面的第二行才是真正服务器的空闲内存

2. Linux的内存分配方式

大家都知道,Linux服务器为了提高效率,会提前申请内存,即使这些内存没有被具体应用使用,Linux也会提前申请这些内存,然后利用这些内存做缓存用,即将刚打开的文件系统存入cache中,这样对应的服务器free值会越来越少,buffers和cached会越来越大,因此给大家表象就是内存越来越少了,大家就紧张了;其实,大家完全不用紧张,Linux服务器在发现内存不足时,会自动清理cached区域,释放内存,然后继续增大cache,free继续减少。因此,那样手动降低内存使用率的方法,其实就是图一时之快,呵呵。

echo 1 > /proc/sys/vm/drop_caches 可以暂时清空cache和buffer

在rhel5和Ubuntu上(rhel4不可以),可以直接修改内核文件
# /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

原本以为是oracle缓存占满了,

在SQLPLUS中输入

ALTER SYSTEM FLUSH BUFFER_CACHE;

alter system flush shared_pool;

 但是看了一下效果不明显

 后面试试Linux清除ARP缓存
一、 arp -n|awk '/^[1-9]/ {print "arp -d "$1}' | sh
清除所有ARP缓存,推荐!
二、for((ip=2;ip<255;ip++));do arp -d 192.168.0.$ip &>/dev/null;done
清除192.168.0.0网段的所有缓存
三、arp -d IP
这样可以清除单一IP 的ARP缓存

注意:以上均需要root权限,尤其是最后一个,如果不再root下执行,则改为:

arp -n|awk '/^[1-9]/ {print "arp -d "$1}' | sudo sh