內存壓測神器:memtester深度指南

1.前言

本文接上篇燒腦神器cpuburn,繼續介紹監控告警的資源場景構造。php

如何構造內存使用率過多的場景?html

有兩個方法:ubuntu

1. 本身寫代碼弄個小工具,不斷地去allocate_memory。ide

2. 用現成的工具:好比立刻要介紹這款內存測試工具:memtester。工具

2.簡介

簡介:A userspace utility for testing the memory subsystem for faults. It's portable and should compile and work on any 32- or 64-bit Unix-like system. (Yes, even weird, proprietary Unices, and even Mac OS X.) For hardware developers, memtester can be told to test memory starting at a particular physical address as of memtester version 4.1.0.oop

翻譯:一款在用戶空間下,用於測試內存正確性的實用工具,適用於大多數平臺。能夠在32位或64位的類Unix操做系統編譯和運行(固然也包括MacOs)。這款工具主要面向硬件開發人員,從4.1.0版本開始,memtester能夠指定起始物理內存地址進行測試。測試

經過這段介紹,能夠看出這是一款測試內存正確性的工具,雖然說的是面向於硬件工程師,可是咱們也能夠拿過來構造內存佔用的場景。spa

項目地址http://pyropus.ca/software/memtester/操作系統

3.安裝方式

3.1 源碼編譯(推薦)

#.下載源碼,當前最新版本4.3.0
wget http:#. 解壓縮
tar xzvf memtester-..tar.gz

#3. 進入目錄
cd memtester-4.3.0

#4. 編譯 
sudo make 

#5. 安裝 
sudo make install

3.2 預編譯好的二進制

memtester能夠再各Linux系統的軟件安裝包列表裏面找到,能夠使用對應軟件管理命令查找並安裝memtester,以下是相關Linux系統的memtester的package信息:.net

 Debian

 Ubuntu

 DAG packages for Fedora

 NetBSD ports

 MacPorts

 NetBSD

 Solaris/SunOS (sunfreeware.com)

好比,Ubuntu下安裝memtester

sudo apt install -y memtester

4. 幫助

Usage: memtester [-p physaddrbase [-d device]] <mem>[B|K|M|G] [loops]

參數解釋

   -p PHYSADDR: 用於指定起始物理內存地址開始測試(16進制的地址格式),通常是硬件工程師用來測試內存映射的設備IO等場景。指定內存地址會覆蓋對應地址的內存數據(這部份內存多是系統或者其餘應用在用的),從而致使crash。

   -d 默認使用/dev/mem,咱們不用指定

   mem: 默認使用M(MB),能夠指定B, K, M, or G(分別表明 bytes, kilobytes, megabytes, or gigabytes)

   loops:測試次數,默認無限次數執行下去

5. 例子

1)首先查看本機內存

free -g,能夠看到有16G

 

2)分配10g內存用於memtest,循環十次

memtester 10g 10

文中打印了不少測試信息,能夠看出來memtester對內存的邏輯操做進行了正確性驗證。

 

3) 查看實際內存使用狀況

輸入: top ,而後按下m字母鍵。

10/16≈62.5%,系統總體的內存使用率達到了70%,memtester使用了約64%左右。

 

6.其餘

退出碼

 0:正常退出

 x01:內存分配或者鎖定失敗

 x02:stuck Address測試失敗

 x04:其餘測試失敗

最佳實踐

  •  在32位系統上運行memtester的話,memtester最多隻能申請使用4GB內存。

  •  不要指定memtester測試內存大於系統的可用內存,若是超額申請過多內存,會明顯影響其餘進程,最終可能會被系統殺掉(OOM killer)(其實這麼作根本沒法啓動memtester)

  •  儘可能在root權限下執行memtester,以便讓memtester能申請到指定的內存大小。

 

博主:測試生財

座右銘:專一測試與自動化,致力提升研發效能;經過測試精進完成原始積累,經過讀書理財奔向財務自由。

csdn:https://blog.csdn.net/ccgshigao 

博客園:https://www.cnblogs.com/qa-freeroad/ 

51cto:https://blog.51cto.com/14900374

相關文章
相關標籤/搜索