使用記憶體檔案系統後系統記憶體統計方法

來源:互聯網
上載者:User

使用記憶體檔案系統後系統記憶體統計方法 【問題描述】   在Linux系統中,記憶體可以分出一部分空間作為磁碟來使用,稱為Ramdisk。這部分記憶體空間具有高速讀寫  www.2cto.com  特性,可以儲存那些對磁碟IO要求較高的資料,顯著的提升系統的服務效能。   Ramdisk分為兩種,一種是固定空間大小的空間,跟硬碟分區完全一樣,可以格式化並掛載使用;一種是以記憶體檔案系統tmpfs的形式出現,可以根據需要擴充和縮小。這兩種使用方式在kernel 2.4之後都得到了支援。   在使用tmpfs時,因為不是一次分配,且對記憶體配置的形式比較模糊,使得怎樣計算系統整體記憶體使用量情況成為一個問題。 【觀察和解決】   在使用ubuntu系統時,對使用Ramdisk的形式做了簡單測試,發現在使用和不使用Ramdisk的時候有奇怪的問題發生。具體如下:   記憶體分區無資料時的情況如下,   root@peter:~# free -m                total       used       free     shared    buffers     cached   Mem:          3851       2222       1629          0         63        847   -/+ buffers/cache:       1310       2540   Swap:         1925          0       1925   root@peter:~# df -h   Filesystem      Size  Used Avail Use% Mounted on   /dev/sda3       125G  4.9G  114G   5% /   udev            1.9G  4.0K  1.9G   1% /dev   tmpfs           771M  888K  770M   1% /run   none            5.0M     0  5.0M   0% /run/lock   none            1.9G  7.4M  1.9G   1% /run/shm   向記憶體分區寫入1G資料時的情況如下,   root@peter:/run/shm# dd if=/dev/zero ibs=1M count=1024 of=./test.img   1024+0 records in   2097152+0 records out   1073741824 bytes (1.1 GB) copied, 2.22898 s, 482 MB/s   root@peter:/run/shm# df -h   Filesystem      Size  Used Avail Use% Mounted on   /dev/sda3       125G  4.9G  114G   5% /   udev            1.9G  4.0K  1.9G   1% /dev   tmpfs           771M  888K  770M   1% /run   none            5.0M     0  5.0M   0% /run/lock   none            1.9G  1.1G  895M  54% /run/shm   root@peter:/run/shm# free -m                total       used       free     shared    buffers     cached   Mem:          3851       3245        605          0         64       1871   -/+ buffers/cache:       1309       2541   Swap:         1925          0       1925   前後資料對比發現主要增加的是cached資料的統計量,而實際使用的記憶體1309幾乎和之前沒有變化。可以大概認為向記憶體分區中寫入的資料實際是增大了cached的統計量。為了進一步說明這個情況,可以釋放掉系統的cached資料    root@peter:/run/shm# sync; echo "3" > /proc/sys/vm/drop_caches    root@peter:/run/shm# free -m                  total       used       free     shared    buffers     cached    Mem:          3851       2694       1156          0          0       1401    -/+ buffers/cache:       1292       2558    Swap:         1925          0       1925    由於/run/shm分區中實際儲存了1.1G的資料,cached並沒有被完全使用,可以說明存放到記憶體分區的資料實際是在cached的統計資料中。    最後釋放掉記憶體分區的資料並清理系統緩衝後的情況如下    root@peter:/run/shm# rm -fr test.img    root@peter:/run/shm# free -m                  total       used       free     shared    buffers     cached    Mem:          3851       1676       2174          0          7        370    -/+ buffers/cache:       1297       2553    Swap:         1925          0       1925    root@peter:/run/shm# df -h    Filesystem      Size  Used Avail Use% Mounted on    /dev/sda3       125G  4.9G  114G   5% /    udev            1.9G  4.0K  1.9G   1% /dev    tmpfs           771M  888K  770M   1% /run    none            5.0M     0  5.0M   0% /run/lock    none            1.9G  7.4M  1.9G   1% /run/shm     至此,可以發現,在使用記憶體分區的系統中,實際使用的記憶體資料,應該是free -m獲得使用記憶體情況加上記憶體區中的資料量,這才是系統真正使用的記憶體量。 【總結】    在使用記憶體檔案系統儲存資料的系統中,分析記憶體時要充分的考慮記憶體檔案系統的資料用量,進而準確的給出系統所使用記憶體的情況,整體把握系統的資源情況,為進一步的系統分析做準備。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.