在具有 64GB mem 的系統上,當使用 dd 複製到 dev null 時,Linux 緩衝區運行滿,並且 io 停止,直到手動 drop_caches

在具有 64GB mem 的系統上,當使用 dd 複製到 dev null 時,Linux 緩衝區運行滿,並且 io 停止,直到手動 drop_caches

我正在運行一個帶有 linux 軟體 raid 10 的伺服器。與每個 CPU 相關的 2x16GB 記憶體。我想用dd來備份kvm虛擬機,遇到了嚴重的io問題。首先我認為與raid有關,但這是linux記憶體管理的問題。這是一個例子:

  1. 記憶體沒問題: https://i.stack.imgur.com/NbL60.jpg
  2. 我開始dd: https://i.stack.imgur.com/kEPN2.jpg
  3. 您也可以看到 nmon 顯示磁碟存取: https://i.stack.imgur.com/Njcf5.jpg
  4. 一段時間後,「緩衝區」很大且複製進度​​停止 https://i.stack.imgur.com/HCefI.jpg
  5. 這是記憶體資訊: https://i.stack.imgur.com/KR0CE.jpg
  6. 這是 dd 輸出: https://i.stack.imgur.com/BHjnR.jpg
  7. 我可以手動解決臨時問題並強制刪除快取:“sync; echo 3 > /proc/sys/vm/drop_caches”
  8. 呼叫需要幾秒鐘,之後 dd 速度立即達到正常水平。當然,我可以每分鐘進行一次計時任務或類似的事情,但這不是真正的解決方案。 https://i.stack.imgur.com/zIDRz.jpg https://i.stack.imgur.com/fO8NV.jpg

有人有解決方案或設定提示嗎?這也是我的 sysctl 但所有值都是 centos 預設值: https://i.stack.imgur.com/ZQBNG.jpg

編輯1

我進行了另一個測試,並將 dd 寫入磁碟而不是 /dev/null。這次也是在一個沒有 pv 的指令中。所以它只有一個過程。dd if=/dev/vg_main_vms/AppServer_System of=AppServer_System bs=4M

  1. 它從讀取開始而不是寫入(目標不在同一磁碟上) https://i.stack.imgur.com/jJg5x.jpg
  2. 過了一會兒,寫作開始,閱讀速度減慢 https://i.stack.imgur.com/lcgW6.jpg
  3. 之後就是只寫的時間了: https://i.stack.imgur.com/5FhG4.jpg
  4. 現在開始主要問題。複製過程減慢至 1mbs 以下且沒有任何反應: https://i.stack.imgur.com/YfCXc.jpg
  5. dd 進程現在需要 100% cpu 時間(1 個核心) https://i.stack.imgur.com/IZn1N.jpg
  6. 我可以再次手動解決臨時問題並強制刪除快取: sync; echo 3 > /proc/sys/vm/drop_caches。之後,同樣的遊戲又開始了…

編輯2

對於本地 dd,我可以使用參數 iflag=direct 和 oflag=direct 來解決。但這不是通用的解決方案,因為還有其他文件訪問,例如從虛擬機器將文件複製到本地 samba 共享,我無法使用此類參數。必須對系統檔案快取規則進行調整,因為如果沒有此類問題,無法複製大檔案是不正常的。

答案1

只是一個瘋狂的猜測。您的問題可能是大髒頁刷新。嘗試設定 /etc/sysctl.conf,如下所示:

# vm.dirty_background_ratio contains 10, which is a percentage of total system memory, the 
# number of pages at which the pdflush background writeback daemon will start writing out 
# dirty data. However, for fast RAID based disk system this may cause large flushes of dirty
# memory pages. If you increase this value from 10 to 20 (a large value) will result into 
# less frequent flushes:
vm.dirty_background_ratio = 1

# The value 40 is a percentage of total system memory, the number of pages at which a process
# which is generating disk writes will itself start writing out dirty data. This is nothing
# but the ratio at which dirty pages created by application disk writes will be flushed out
# to disk. A value of 40 mean that data will be written into system memory until the file 
# system cache has a size of 40% of the server's RAM. So if you've 12GB ram, data will be
# written into system memory until the file system cache has a size of 4.8G. You change the
# dirty ratio as follows:
vm.dirty_ratio = 1

然後sysctl -p重新加載,再次刪除快取(echo 3 > /proc/sys/vm/drop_caches)。

相關內容