2020年4月28日 星期二

修正Mac當機後不要直接重開機

Adjust Whether a Mac Restarts Automatically on System Freeze

sudo systemsetup -getrestartfreeze

You’ll either see one of two reports, indicating the status of the feature:

Restart After Freeze: On

or:

Restart After Freeze: Off

Again, the default Mac setting now is to be “On” – it is highly recommended to leave that setting enabled as is and not adjust it.

Adjusting the Automatic Mac Restart Upon Freeze Feature
If you’re advanced user and you wish to toggle the auto-restart on freeze feature, the following command syntax will do so. Adjust the ‘on’ or ‘off’ component of the command to achieve the desired effect:

Turn automatic restarting upon freeze on:

sudo systemsetup -setrestartfreeze on

Turn automatic restarting upon freeze off:

sudo systemsetup -setrestartfreeze off

Keep in mind if you turn this feature off, an unattended frozen Mac will stay frozen at whatever is on screen for however long it takes a user to come an force the computer to reboot, if not for some other power event taking place. This is one of many reasons why the average user should leave the setting turned on.

Even with the automatic restart on freeze feature left enabled, sometimes, a frozen Mac can be so stuck that it requires forcibly rebooting to get the computer to behave again.

Note this setting was actually contained in the System Preferences for a while in earlier versions of OS X, but newer versions of Mac OS X removed the option and instead simply default to having the feature on.

systemsetup Help Information
-------------------------------------
Usage: systemsetup -getdate
        Display current date.

Usage: systemsetup -setdate <mm:dd:yy>
        Set current date to <mm:dd:yy>.

Usage: systemsetup -gettime
        Display current time.

Usage: systemsetup -settime <hh:mm:ss>
        Set current time to <hh:mm:ss>.

Usage: systemsetup -gettimezone
        Display current time zone.

Usage: systemsetup -settimezone <timezone>
        Set current time zone to <timezone>. Use "-listtimezones" to list time zones.

Usage: systemsetup -listtimezones
        List time zones supported by this machine.

Usage: systemsetup -getusingnetworktime
        Display whether network time is on or off.

Usage: systemsetup -setusingnetworktime <on off>
        Set using network time to either <on> or <off>.

Usage: systemsetup -getnetworktimeserver
        Display network time server.

Usage: systemsetup -setnetworktimeserver <timeserver>
        Set network time server to <timeserver>.

Usage: systemsetup -getsleep
        Display amount of idle time until computer, display and hard disk sleep.

Usage: systemsetup -setsleep <minutes>
        Set amount of idle time until computer, display and hard disk sleep to <minutes>.
        Specify "Never" or "Off" for never.

Usage: systemsetup -getcomputersleep
        Display amount of idle time until computer sleeps.

Usage: systemsetup -setcomputersleep <minutes>
        Set amount of idle time until compputer sleeps to <minutes>.
        Specify "Never" or "Off" for never.

Usage: systemsetup -getdisplaysleep
        Display amount of idle time until display sleeps.

Usage: systemsetup -setdisplaysleep <minutes>
        Set amount of idle time until display sleeps to <minutes>.
        Specify "Never" or "Off" for never.

Usage: systemsetup -getharddisksleep
        Display amount of idle time until hard disk sleeps.

Usage: systemsetup -setharddisksleep <minutes>
        Set amount of idle time until hard disk sleeps to <minutes>.
        Specify "Never" or "Off" for never.

Usage: systemsetup -getwakeonmodem
        Display whether wake on modem is on or off.

Usage: systemsetup -setwakeonmodem <on off>
        Set wake on modem to either <on> or <off>.

Usage: systemsetup -getwakeonnetworkaccess
        Display whether wake on network access is on or off.

Usage: systemsetup -setwakeonnetworkaccess <on off>
        Set wake on network access to either <on> or <off>.

Usage: systemsetup -getrestartpowerfailure
        Display whether restart on power failure is on or off.

Usage: systemsetup -setrestartpowerfailure <on off>
        Set restart on power failure to either <on> or <off>.

Usage: systemsetup -getrestartfreeze
        Display whether restart on freeze is on or off.

Usage: systemsetup -setrestartfreeze <on off>
        Set restart on freeze to either <on> or <off>.

Usage: systemsetup -getallowpowerbuttontosleepcomputer
        Display whether the power button is able to sleep the computer.

Usage: systemsetup -setallowpowerbuttontosleepcomputer <on off>
        Enable or disable whether the power button can sleep the computer.

Usage: systemsetup -getremotelogin
        Display whether remote login is on or off.

Usage: systemsetup -setremotelogin <on off>
        Set remote login to either <on> or <off>. Use "systemsetup -f -setremotelogin off" to suppress prompting when turning remote login off. Requires Full Disk Access privileges.

Usage: systemsetup -getremoteappleevents
        Display whether remote apple events are on or off.

Usage: systemsetup -setremoteappleevents <on off>
        Set remote apple events to either <on> or <off>. Requires Full Disk Access privileges.

Usage: systemsetup -getcomputername
        Display computer name.

Usage: systemsetup -setcomputername <computername>
        Set computer name to <computername>.

Usage: systemsetup -getlocalsubnetname
        Display local subnet name.

Usage: systemsetup -setlocalsubnetname <name>
        Set local subnet name to <name>.

Usage: systemsetup -getstartupdisk
        Display current startup disk.

Usage: systemsetup -setstartupdisk <disk>
        Set current startup disk to <disk>.

Usage: systemsetup -liststartupdisks
        List startup disks on this machine.

Usage: systemsetup -getwaitforstartupafterpowerfailure
        Get the number of seconds after which the computer will start up after a power failure.

Usage: systemsetup -setwaitforstartupafterpowerfailure <seconds>
        Set the number of seconds after which the computer will start up after a power failure. The <seconds> value must be a multiple of 30 seconds.

Usage: systemsetup -getdisablekeyboardwhenenclosurelockisengaged
        Get whether or not the keyboard should be disabled when the X Serve enclosure lock is engaged.

Usage: systemsetup -setdisablekeyboardwhenenclosurelockisengaged <yes no>
        Set whether or not the keyboard should be disabled when the X Serve enclosure lock is engaged.

Usage: systemsetup -version
        Display version of systemsetup tool.

Usage: systemsetup -help
        Display help.

Usage: systemsetup -printCommands
        Display commands.

Mac 的启动组合键

Mac 的啟動組合鍵

了解可通過在啟動時按住一個或多個按鍵來訪問的Mac 功能和工具。 
要使用這些組合鍵中的任何一個,請在按下電源按鈕以開啟Mac  後或在Mac開始重新啟動後,立即按住相應按鍵。請一直按住,直至電腦出現對應的行為。


你可以在Mac開機時,按住如下的組合鍵,去進入其功能設定:
  1. 按住〈C〉,從CD 或DVD 光碟機啟動,如:Mac OS X 安裝光碟。
  2. 按住〈D〉,如果插入安裝DVD 1,則啟動為Apple Hardware Test (AHT)。
  3. 按住〈Option〉+〈Command〉+〈P〉+〈R〉,直到聽到兩聲BB聲-->Reset NVRAM。
  4. 按住〈Option〉 ,開機後進入Startup Manager,你可以在這些選項中,選擇從一個你想的Mac OS X 項目去開機。注意:按住〈N〉 鍵,可顯示出第一個可啟動的網絡選項。你也可以選擇從UEFI磁碟作開機,去做一些內部設定。
  5. 按住〈Eject〉or〈F12〉 ,或者按住鼠標鍵(/觸控板),退出所有可移動的媒體,如光碟,USB。
  6. 按住〈N〉,試著從相容的網絡伺服器(NetBoot)去作開機的動作。
  7. 按住〈T〉,開機後成為FireWire 目標(Taget)的磁碟模式。
  8. 按住〈Shift〉,開機後成為安全模式,並且暫時關閉登錄選項。
  9. 按住〈Command〉+〈V〉,開機後成為Verbose 模式。
  10. 按住〈Command〉+〈S〉,開機後成為單一使用者模式。
  11. 按住〈Option〉+〈N〉,使用系統預設執的開機鏡像,從NetBoot伺服器開機。
若要從「macOS 復原」啟動,請將 Mac 開機,然後立即在鍵盤上按住下列其中一套組合鍵。在您看到 Apple 標誌、旋轉的地球或其他啟動畫面時,放開按鍵。

Command(⌘)-R

重新安裝 Mac 上所安裝的最新版 macOS(建議做法)。

Option-⌘-R

升級到與 Mac 相容的最新版 macOS。

Shift-Option-⌘-R

重新安裝 Mac 隨附的 macOS,或仍提供使用的最接近版本。

Mac 開機啟動 詳細 message

我們知道任何作業系統都會有發生故障的時候,macOS也不例外,而通過作業系統產生的日誌,有助於判斷故障產生的原因並解決故障。
通過蘋果官方網站的幫助信息^,在Mac啟動時按住Command + V可以進入詳細模式(經常玩黑蘋果的同學會稱之為囉嗦模式),按住Command + S可以進入單用戶模式,按住Shift可以進入安全模式。
除了在Mac啟動時按住鍵盤的快捷鍵,你還可以通過終端的「nvram」命令來為Mac設置啟動參數,這樣就不需要每次在Mac啟動時按住這些快捷鍵了。
通過終端為Mac設置啟動參數
1、打開Finder,點選菜單欄的「前往「,然後選擇」應用程式「,找到」實用工具「文件夾並打開,找到並打開」終端「應用程式;



2、在終端窗口中,輸入以下命令並按回車執行:
sudo nvram boot-args="-v"
3、執行後會出現Password提示,這時候輸入你當前帳戶的密碼,Unix系統在輸入密碼時不會有任何提示,輸入完成後按回車繼續;
4、此時啟動參數已經被添加到了nvram里,當啟動macOS時系統會以-v參數啟動,進入詳細模式;
5、如果需要檢查參數是否已經添加了,執行以下命令:
nvram -p | grep boot-args



看到如圖紅線處所示,boot-args -v,則表示添加參數成功。
這個方法適用於運行所有基於Intel處理器的Mac和部分PowerPC架構的Mac
最終效果



通過這個方法除了可以添加詳細模式外還可以添加其他模式的參數:
sudo nvram boot-args="-x"
讓系統在啟動時進入安全模式
sudo nvram boot-args="-s"
讓系統在啟動時進入單用戶模式
sudo nvram boot-args="-x -v"
讓系統以詳細模式啟動安全模式
如果希望清除啟動參數,執行以下命令即可:
sudo nvram boot-args=""
完!
能力有限,如有錯誤還請指出,謝謝!
^:蘋果官方幫助信息連結https://support.apple.com/zh-cn/HT201255

啟動Mac系統時,您可以選擇在啟動時提供鍵盤命令以將系統引導至備用環境。例如,常用選項是按住Shift鍵以啟動到安全模式,但您也可以將Command-V保持為詳細模式(加載時項目的文本輸出)或Command-S for Single User模式,將您作為“root”用戶轉到命令行,以便執行故障排除任務。

除了啟動時的鍵盤命令,您還可以使用“nvram”terminal命令設置許多不同的啟動選項,這在對Mac進行故障排除時可能很有用。Apple的機器有許多可以使用的隱藏啟動選項,但請記住,其中大多數都是用於故障排除目的,並且只對程序員有用。

sudo nvram boot-args =“iog = 0x0”
這反轉了蘋果筆記本電腦系統的“翻蓋”模式,當你關閉顯示器但將系統連接到外部顯示器和鍵盤時,系統將保持清醒狀態。運行此命令後,連接外部顯示器時,內部顯示器將被禁用,這在某些情況下是有益的,例如您鏡像桌面但希望以比筆記本電腦可以運行的更高分辨率運行外部顯示器的情況。

sudo nvram boot-args =“debug = 0x144”
這是內核調試功能的組合,它將向您顯示有關內核進程的額外信息,如果系統遇到內核恐慌,這可能非常有用。另一種選擇是使用debug = 0x14e,它將顯示更多的日誌記錄選項。這樣做的主要用途是它能夠在屏幕上顯示滾動文本的舊式內核恐慌,說明系統恐慌的原因,而不是顯示灰色背景和僅重新啟動系統的消息。替代調試選項如下,但這些可能僅對內核程序員有用:

0x01 – 在引導時停止並等待調試器附加
0x02 – 將內核調試輸出發送到控制台
0x04 – 在不可屏蔽的中斷上進入調試器
0x08 – 將內核調試信息發送到串行端口
0x10 – 使ddb成為默認調試器
0x20 – 將診斷信息輸出到系統日誌
0x40 – 允許調試器進行ARP和路由
0x80 – 在較新的系統上支持舊版本的gdb
0x100 – 禁用圖形應急對話框屏幕

sudo nvram boot-args =“arch = x86_64”
在Snow Leopard系統上,即使64位內核可用,系統默認也會引導至32位內核。此命令將更改此值,以便系統始終引導至64位內核。要將系統更改為始終引導至32位內核,請將命令的“x86_64”部分替換為“i386”。在某些情況下,第三方內核擴展可能只是32位或64位,這需要引導到相應的內核類型才能加載。

sudo nvram boot-args =“maxmem = 32”
將可尋址內存限制為指定的數量,在本例中為32GB。這是另一個可能只對程序員有用的東西。如果沒有它,系統會將內存限制設置為硬件可以解決的最大值或安裝量。

sudo nvram boot-args =“cpus = 1”
將系統中活動處理器的數量限制為設置級別。Apple的開發人員工具可以選擇啟用或禁用系統上的某些CPU,但您可以通過運行此命令並指定要使用的CPU核心數來手動執行此操作。在某些情況下,例如筆記本電腦系統,這可能有助於保持功率,但除非您正在測試和編程,否則可能對其他許多功能沒用。
使用這些選項,您可以通過一次運行上述命令來單獨設置它們,也可以根據需要組合它們。例如,要將系統設置為啟動到安全模式並在啟動期間詳細顯示項目,您可以運行上面列出的兩個命令來執行此操作,也可以將它們組合到以下命令中:
sudo nvram boot-args =“ – x -v”

要禁用這些功能並讓系統正常啟動而不需要任何額外選項,您可以通過重置它或者更具體地說,通過在終端中運行以下任一命令來從nvram中刪除它們(這些將重置引導參數而不是重置所有nvram變量):

如果希望清除啟動參數,執行以下命令即可:
sudo nvram boot-args=""

Mac 重置系統管理控制器(SMC)

作者:知乎用户
链接:https://www.zhihu.com/question/20401972/answer/48146602
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

SHIFT+CTRL+OPTION+POWER十秒鐘:重置系統管理控制器(SMC)
  • 關閉電腦。
  • 將MagSafe 電源適配器連接到電源和Mac(如果尚未連接的話)。
  • 在內建鍵盤上,同時按下(左側)Shift-Control-Option 鍵和電源按鈕。
  • 同時鬆開所有鍵和電源按鈕。
  • 按電源按鈕打開電腦。
:重置SMC時,MagSafe電源適配器上的LED指示燈可能會更改狀態或暫時關閉。
在風扇、電源指示燈、系統性能、視頻出現某些異常時候,可以通過上述方法進行重置來解決。具體的症狀判斷和說明可以參考" 基於Intel的Mac:重置系統管理控制器(SMC) "。
OPTION+CMD+R+P+POWER:重置NVRAM 或PRAM
Mac 會將某些設置儲存在特殊內存區域中,而且即使關機這些設置也不會丟失(除非存在電池問題)。在基於Intel 的Mac 上,存儲位置是稱為NVRAM 的內存;而在基於PowerPC 的Mac 上,存儲位置則是稱為PRAM 的內存。操作步驟為:
  • 關閉電腦。
  • 在鍵盤上找到以下按鍵:Command、Option、P 和R。您需要在步驟4 中同時按下這些鍵。
  • 啟動電腦。
  • 按住Command-Option-PR 鍵。必須在出現灰屏前按下此組合鍵。
  • 按住上述鍵,直到電腦重新啟動,您會再次聽到啟動聲。
  • 鬆開這些鍵。

2020年4月13日 星期一

Ubuntu 18.04 setting null_blk, test fio


先確認/lib/modules/4.15.0-96-generic/kernel/drivers/block/ 是否有null_blk.ko 
若沒有,請先自行build出此driver. 或是使用apt-get install 安裝

** apt-get install extra driver

# uname -a
Linux sam 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# apt-cache search linux-modules-extra-4.15.0.96
linux-modules-extra-4.15.0-96-generic - Linux kernel extra modules for version 4.15.0 on 64 bit x86 SMP

apt-get install linux-modules-extra-4.15.0-96-generic


** 自動掛載 null_blk driver

vi /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
null_blk

** 設定 null_blk 參數,只能以 module 形式,在開機讀取設定.
# vi /etc/modprobe.d/null_blk.conf 

寫入下行資料, nr_devices=1 建立 nullb0, queue_mode=0 初步測試沒queue能測出較高IOPS.
options null_blk nr_devices=1 queue_mode=0

reboot

如何確認queue_mode=0, queue 被關閉,請確認 mq 不存在,即表示queue_mode=0 設定成功.

#  ls /sys/class/block/nullb0
alignment_offset  bdi  capability  dev  discard_alignment  ext_range  hidden  holders  inflight  integrity  mq  power  queue  range  removable  ro  size  slaves  stat  subsystem  trace  uevent

# ls /sys/class/block/nullb0

alignment_offset  bdi  capability  dev  discard_alignment  ext_range  hidden  holders  inflight  integrity  power  queue  range  removable  ro  size  slaves  stat  subsystem  trace  uevent


Null block device driver
https://www.kernel.org/doc/Documentation/block/null_blk.txt

Null block device driver
================================================================================

I. Overview

The null block device (/dev/nullb*) is used for benchmarking the various
block-layer implementations. It emulates a block device of X gigabytes in size.
The following instances are possible:

  Single-queue block-layer
    - Request-based.
    - Single submission queue per device.
    - Implements IO scheduling algorithms (CFQ, Deadline, noop).
  Multi-queue block-layer
    - Request-based.
    - Configurable submission queues per device.
  No block-layer (Known as bio-based)
    - Bio-based. IO requests are submitted directly to the device driver.
    - Directly accepts bio data structure and returns them.

All of them have a completion queue for each core in the system.

II. Module parameters applicable for all instances:

queue_mode=[0-2]: Default: 2-Multi-queue
  Selects which block-layer the module should instantiate with.

  0: Bio-based.
  1: Single-queue.
  2: Multi-queue.

home_node=[0--nr_nodes]: Default: NUMA_NO_NODE
  Selects what CPU node the data structures are allocated from.

gb=[Size in GB]: Default: 250GB
  The size of the device reported to the system.

bs=[Block size (in bytes)]: Default: 512 bytes
  The block size reported to the system.

nr_devices=[Number of devices]: Default: 1
  Number of block devices instantiated. They are instantiated as /dev/nullb0,
  etc.

irqmode=[0-2]: Default: 1-Soft-irq
  The completion mode used for completing IOs to the block-layer.

  0: None.
  1: Soft-irq. Uses IPI to complete IOs across CPU nodes. Simulates the overhead
     when IOs are issued from another CPU node than the home the device is
     connected to.
  2: Timer: Waits a specific period (completion_nsec) for each IO before
     completion.

completion_nsec=[ns]: Default: 10,000ns
  Combined with irqmode=2 (timer). The time each completion event must wait.

submit_queues=[1..nr_cpus]:
  The number of submission queues attached to the device driver. If unset, it
  defaults to 1. For multi-queue, it is ignored when use_per_node_hctx module
  parameter is 1.

hw_queue_depth=[0..qdepth]: Default: 64
  The hardware queue depth of the device.

III: Multi-queue specific parameters

use_per_node_hctx=[0/1]: Default: 0
  0: The number of submit queues are set to the value of the submit_queues
     parameter.
  1: The multi-queue block layer is instantiated with a hardware dispatch
     queue for each CPU node in the system.

no_sched=[0/1]: Default: 0
  0: nullb* use default blk-mq io scheduler.
  1: nullb* doesn't use io scheduler.

blocking=[0/1]: Default: 0
  0: Register as a non-blocking blk-mq driver device.
  1: Register as a blocking blk-mq driver device, null_blk will set
     the BLK_MQ_F_BLOCKING flag, indicating that it sometimes/always
     needs to block in its ->queue_rq() function.

shared_tags=[0/1]: Default: 0
  0: Tag set is not shared.
  1: Tag set shared between devices for blk-mq. Only makes sense with
     nr_devices > 1, otherwise there's no tag set to share.

zoned=[0/1]: Default: 0
  0: Block device is exposed as a random-access block device.
  1: Block device is exposed as a host-managed zoned block device. Requires
     CONFIG_BLK_DEV_ZONED.

zone_size=[MB]: Default: 256
  Per zone size when exposed as a zoned block device. Must be a power of two.

zone_nr_conv=[nr_conv]: Default: 0
  The number of conventional zones to create when block device is zoned.  If
  zone_nr_conv >= nr_zones, it will be reduced to nr_zones - 1.

2020年4月12日 星期日

Fio 輸出內容的解釋 與 設定檔案 範例


翻譯原文來源

fio,又稱為Flexible IO Tester,是Jens Axboe編寫的應用程序。Jens是Linux Kernel中block IO subsystem的維護者。fio從多個方面來看類似於更古老的ffsb工具,但他們之間似乎沒有任何關係。作為一個強大的工具,fio可以產生足夠多的任意類型的負載(arbitrary load)。作為權衡,fio不容易學習,這就是這篇文章的目的。

  • 配置
  • 原始輸出
配置
以下是一個50/50讀寫的垃圾處理IO (Trashing IO)負載,對於多個盤進行的讀寫。
5分鐘,磁盤垃圾處理測試,50/50讀寫在每個盤上產生相同數量的隨機讀和寫IO,為每個盤產生測試數據。
# a 5 minute disk thrashing benchmark
# generates equal amounts of random read and write IO on every drive
# will generate metrics for each drive
[global]
ioengine=libaio
direct=1
unified_rw_reporting=1
rw=randrw
time_based=1
runtime=300s

<strong># Seagate 7200RPM SAS 512G ST9500430SS (sdb)</strong>
[/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c5000d7f96d9-lun-0]
write_lat_log=7200RPMSAS-0x5000c5000d7f96d9

<strong># Seagate 7200RPM Enterprise SATA 1TB ST31000340NS (sdg)</strong>
[/dev/disk/by-id/wwn-0x5000c500151229dd]
write_lat_log=7200RPMEnterpriseSATA-0x5000c500151229dd

<strong># Samsung 840 Pro 128GB (on a 3G SATA port) (sdd)</strong>
[/dev/disk/by-id/ata-Samsung_SSD_840_PRO_Series_S1ANNSADB05219A]
write_lat_log=SSDSATA-S1ANNSADB05219A

# 2x SAS drives with GPT partition & MDRAID0 (sdi1 + sdc1)
<strong># Seagate 7200RPM SAS 512G ST9500430SS</strong>
[/dev/disk/by-id/md-uuid-6bb71ed6:e4410fc9:b27af0b7:0afe758d]
write_lat_log=7200RPMSAS-MDRAID0

原始輸出
以上鍊接可打開上述fio配置的原始輸出。

接下來按照每個部分分析輸出內容。這裡顯示的數據是Samsung 840 Pro SSD,其他盤的數據稍後再深入研究。
對於每一個部分的描述在輸出文字下面。

read : io=10240MB, bw=63317KB/s, iops=15829, runt=165607msec
第一行很容易讀懂。fio做了10GB的IO,速率63.317MB/s,總IOPS 15829 (默認4k block size),運行了2分鐘45秒。

你看到的第一個延遲(Latency)數據是slat,或稱為submission latency。這個值和他的名字很相像,代表“盤需要多久將IO提交到kernel做處理?”。
slat (usec): min=3, max=335, avg= 9.73, stdev= 5.76
我起初認為submission latency對於性能調試沒有用,但是下面的數據讓我改變了觀點。269usec或1/4 ms看起來是噪音(noise),需要關註一下。我還沒有做任何調試,所以我猜測改變scheduler以告訴kernel這不是機械硬盤會有效果。
以下是從其他盤上得到的更多例子。
 slat (usec): min=3, max=335, avg= 9.73, stdev= 5.76 (SATA SSD)
 slat (usec): min=5, max=68,  avg=26.21, stdev= 5.97 (SAS 7200)
 slat (usec): min=5, max=63,  avg=25.86, stdev= 6.12 (SATA 7200)
 slat (usec): min=3, max=269, avg= 9.78, stdev= 2.85 (SATA SSD)
 slat (usec): min=6, max=66,  avg=27.74, stdev= 6.12 (MDRAID0/SAS)

 clat (usec): min=1, max=18600, avg=51.29, stdev=16.79
接下來是completion latency。這是命令提交到kernel到IO做完之間的時間,不包括submission latency。在老版本的fio中,這是估計應用級延遲的最好指標。

緯度(USEC):最小值= 44,最大值= 18627,平均= 61.33,標準差= 7.91
在我看來,'lat'是一個新的指標,在man或者文檔中都沒有描述。分析C代碼,似乎這個值是從IO結構體創建時刻開始,直到緊接著clat完成,這個算法最好地表現出了應用程序的行為。

  1. clat percentiles (usec):
  2. | 1.00th=[ 42], 5.00th=[ 45], 10.00th=[ 45], 20.00th=[ 46],
  3. | 30.00th=[ 47], 40.00th=[ 47], 50.00th=[ 49], 60.00th=[ 51],
  4. | 70.00th=[ 53], 80.00th=[ 56], 90.00th=[ 60], 95.00th=[ 67],
  5. | 99.00th=[ 78], 99.50th=[ 81], 99.90th=[ 94], 99.95th=[ 101],
  6. | 99.99th=[ 112]
Completion latency百分數的解釋一目了然,可能是輸出信息中最有用的部分。我看了代碼,這不是slat+clat,而是用了單獨的結構體記錄。
這個列表可以在config文件中配置。在精簡輸出模式下有20個這樣的格式,%f=%d; %f=%d;... 解析這樣的輸出格式會很有趣。

作為比較,這裡列出一個7200RPM SAS硬盤運行完全相同的負載的統一部分數據。
希捷7200RPM SAS 512G ST9500430SS
clat percentiles (usec):
     |  1.00th=[ 3952],  5.00th=[ 5792], 10.00th=[ 7200], 20.00th=[ 8896],
     | 30.00th=[10304], 40.00th=[11456], 50.00th=[12608], 60.00th=[13760],
     | 70.00th=[15168], 80.00th=[16768], 90.00th=[18816], 95.00th=[20608],
     | 99.00th=[23424], 99.50th=[24192], 99.90th=[26752], 99.95th=[28032],
     | 99.99th=[30080]

    bw (KB  /s): min=52536, max=75504, per=67.14%, avg=63316.81, stdev=4057.09
帶寬(bandwidth)的意思顯而易見,而per=part就不是很好理解。文檔上說這個值是指在單個盤上跑多個負載,可以用來看每個進程消耗了多少IO。對於我這樣把fio跑在多個盤的情況,這個值意義不大。但由於SSD和機械硬盤混合使用,這個值挺有趣。
下面是另一個SAS硬盤,佔測試的所有4個盤總IO的0.36%。
    bw (KB  /s): min=   71, max=  251, per=0.36%, avg=154.84, stdev=18.29

    lat (usec) :   2= 0.01%,   4=0.01%,  10=0.01%,   20=0.01%, 50=51.41%
    lat (usec) : 100=48.53%, 250=0.06%, 500=0.01%, 1000=0.01%
    lat (msec) :   2= 0.01%,   4=0.01%,  10=0.01%,   20=0.01%

latency分佈部分我看了幾遍才理解。這是一組數據。與三行使用一樣的單位不同,第三行使用了毫秒(ms),使得文本寬度可控。把第三行讀成2000, 4000, 10000, 20000微秒(us)就更清晰了。
這組數據表示latency的分佈,說明了51.41%的request延遲小於50微秒,48.53%的延遲小於100微秒(但是大於50微秒),以此類推。

lat (msec) : 4=1.07%, 10=27.04%, 20=65.43%, 50=6.46%, 100=0.01%
如果想用快速腳本解析這些繁瑣的數據,你可能需要知道,最後一部分會省略那些沒有數據的項。例如,我使用的SAS盤沒有IO可以在1毫秒中完成,所以只有一行。

cpu          : usr=5.32%, sys=21.95%, ctx=2829095, majf=0, minf=21
這是用戶/系統CPU佔用率,進程上下文切換(context switch)次數,主要和次要(major and minor)頁面錯誤數量(page faults)。由於測試是配置成使用直接IO,page faults數量應該極少。

IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
Fio有一個iodepth設置,用來控制同一時刻發送給OS多少個IO。這完全是純應用層面的行為,和盤的IO queue不是一回事。這裡iodepth設成1,所以IO depth在全部時間都是1。

     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
submit和complete代表同一時間段內fio發送上去和已完成的IO數量。對於產生這個輸出的垃圾回收測試用例來說,iodepth是默認值1,所以100%的IO在同一時刻發送1次,放在1-4欄位裡。通常來說,只有iodepth大於1才需要關注這一部分數據。
我會找時間測試多種調度策略,這些數據會變得更有趣。

issued    : total=r=2621440/w=0/d=0, short=r=0/w=0/d=0
發送的IO數量。這裡出現了奇怪的現象,因為這是50/50的讀寫負載,照道理應該有相同數量的write。我猜測把unified_rw_reporting打開是的fio把所有的IO都認為是read。
如果你在直接IO測試是看到了IO值很低,那麼可能是出問題了。我在Linux kernel中找到參考說這種現象發生在文件末尾EOL或可能是設備的尾端。

latency   : target=0, window=0, percentile=100.00%, depth=1
Fio可以配置一個延遲目標值,這個值可以調節吞吐量直到達到預設的延遲目標。我還沒有太多深入了解這部分。在基於時間或和容量的測試中,這行通常看起來一樣。四個值分別代表預設的latency_target, latency_window, latency_percentile和iodepth。

Run status group 0 (all jobs):
Fio支持把不同的測試聚合。例如,我可以用一個配置文件混合包含SSD和HDD,但是設置分組(group)把IO單獨匯總。我現在還沒涉及這個功能,但未來會用到。

MIXED: io=12497MB, aggrb=42653KB/s, minb=277KB/s, maxb=41711KB/s, mint=300000msec, maxt=300012msec

最後,匯總輸出吞吐量和時間。io=表示總共完成的IO數量。在基於時間的測試中這是一個變量,在基於容量的測試中,這個值能匹配size參數。aggrb是所有進程/設備的匯總帶寬。minb/maxb表示測量到的最小/最大帶寬。mint/maxt表示測試的最短和最長耗時。和io=參數類似,時間值對於基於時間的測試應該能匹配runtime參數,對於基於容量的測試是一個變量。



LINUX FIO 測試IO工具 設定檔


[global]

filename=/dev/nullb0

ioengine=libaio
#ioengine=sync

#direct=bool
#If value is true, use non-buffered I/O. This is usually O_DIRECT.
#Note that OpenBSD and ZFS on Solaris don’t support direct I/O.
#On Windows the synchronous ioengines don’t support direct I/O. Default: false.
direct=1

time_based
ramp_time=5
refill_buffers
group_reporting
wait_for_previous

#size=200G
runtime=1m

#This option also allows a range of CPUs to be specified
#say you wanted a binding to CPUs 0, 5, and 8 to 15, you would set cpus_allowed=0,5,8-15.
#cpus_allowed=0,1

[JOB1]
bs=1M
rw=read
numjobs=4
iodepth=1

[JOB2]
bs=1M
rw=write
numjobs=8
iodepth=1

#[JOB3]
#bs=4k
#rw=write

#[JOB4]
#bs=32k
#rw=write