linux釋放記憶體

來源:互聯網
上載者:User

標籤:linux

首先我們可能會用free 去查看記憶體的使用率,它應該是這樣的


[[email protected] ~]# free -m             total       used       free     shared    buffers     cachedMem:         32040      31707        332          0        498      27649-/+ buffers/cache:       3559      28480Swap:        16087          0      16087##實際上在一個進程結束後其記憶體是會被釋放的,但是核心沒有立刻把記憶體收集到free中,而是存放在cache或buffers當中,以提高系統的IO效率,cache和buffered的記憶體是由核心進行動態組態管理,如果系統的free大小不夠的時候,系統會自動釋放cache buffer的記憶體給程式使用!####證:如果說used佔用很多,free很少,而且cache和buffer占的比例也很小,那表明記憶體是不夠用了##

1

2

3

4

5

6

7

8

9

[root@ipython ~]# free -m

             total       used       free     shared    buffers     cached

Mem:         32040      31707        332          0        498      27649

-/+ buffers/cache:       3559      28480

Swap:        16087          0      16087

 

##實際上在一個進程結束後其記憶體是會被釋放的,但是核心沒有立刻把記憶體收集到free中,而是存放在cache或buffers當中,以提高系統的IO效率,cache和buffered的記憶體是由核心進行動態組態管理,如果系統的free大小不夠的時候,系統會自動釋放cache buffer的記憶體給程式使用!##

 

##證:如果說used佔用很多,free很少,而且cache和buffer占的比例也很小,那表明記憶體是不夠用了##

 

當然,如果你仍需要看到free比較多,你可以嘗試這樣


1、使用sync命令將所有未寫的系統緩衝區write to disk,包含已修改的i node、已延遲的塊I\O和讀寫映射[[email protected] ~]# sync2、粗暴清理[[email protected] ~]# cat /proc/sys/vm/drop_caches0##可以看到預設是0,drop_caches提供了三個選項操作##1 清空頁緩衝   2 清空inode和分類樹緩衝  3 清空所有的緩衝##清空快取頁面##[[email protected] ~]# echo "1">/proc/sys/vm/drop_caches##再來看看##[[email protected] ~]# free -m             total       used       free     shared    buffers     cachedMem:         32040       2564      29475          0          0         40-/+ buffers/cache:       2524      29515Swap:        16087          0      16087

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

1、使用sync命令將所有未寫的系統緩衝區write to disk,包含已修改的i node、已延遲的塊I\O和讀寫映射

[root@ipython ~]# sync

 

2、粗暴清理

[root@ipython ~]# cat /proc/sys/vm/drop_caches

0

##可以看到預設是0,drop_caches提供了三個選項操作##

1 清空頁緩衝   2 清空inode和分類樹緩衝  3 清空所有的緩衝

 

##清空快取頁面##

[root@ipython ~]# echo "1">/proc/sys/vm/drop_caches

 

##再來看看##

[root@ipython ~]# free -m

             total       used       free     shared    buffers     cached

Mem:         32040       2564      29475          0          0         40

-/+ buffers/cache:       2524      29515

Swap:        16087          0      16087


linux釋放記憶體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.