用 4.5+ 的 Linux Kernel 限制 I/O 速度

在「Using cgroups to limit I/O」這邊看到作者試著用 cgroups 限制 I/O 速度。

作者前面花了不少篇幅解釋 cgroups v1 無法正確限制 I/O 速度,後面就在講 cgroups v2 怎麼做:

So, in order to limit I/O when this I/O may hit the writeback kernel cache, we need to use both memory and io controllers in the cgroups v2!

這會需要 4.5+ 的 kernel,可能會需要手動更新,或是直接使用比較新的 distribution:

Since kernel 4.5, the cgroups v2 implementation was marked non-experimental.

然後照抄就可以了 (不過這邊的指定都需要 root,作者用 $ 表示 shell 有點怪):

# mount -t cgroup2 nodev /cgroup2
# mkdir /cgroup2/cg2
# echo "+io" > /cgroup2/cgroup.subtree_control
# echo "8:0 wbps=1048576" > io.max
# echo $$ > /cgroup2/cg2/cgroup.procs

然後就可以跑 dd 測試速度了,同時間也可以跑 iostat 看。

Linux 下 RAID1 的 SSD 會有讀取不平均問題

在「Unbalanced reads from SSDs in software RAID mirrors in Linux」這邊看到作者看 S.M.A.R.T. 數據時發現兩顆 SSD 硬碟組成的 RAID1 有很明顯的讀取不平均的問題:

242 Total_LBAs_Read [...] 16838224623
242 Total_LBAs_Read [...] 1698394290

原因是因為 Linux 對 RAID1 的 SSD 有不一樣的演算法:

The current state of RAID1 read balancing is kind of complex, but the important thing here in all kernels since 2012 is that if you have SSDs and at least one disk is idle, the first idle disk will be chosen.

2016 時演算法就更激進了,變成非 SSD 會:

In kernels with the late 2016 change, this widens to if at least one disk is idle, the first idle disk will be chosen, even if all mirrors are HDs.

加上 SSD 很快,這造成 loading 幾乎都在第一顆上... 這對 SSD 應該是還好啦 (理論上 SSD 的讀取不傷壽命),不過還是有點怪就是了。

Debian 對 Reproducible Build 的討論

Debian 在討論 package 的可重製性:「debian-policy: Packages should be reproducible」。本來的討論其實還好,在 2017/08/12 的 DebConf17 後,看起來有一些人取得共識,於是討論熱了起來... 有興趣的人可以從 Message #107 開始看。

Debian 社群想做的事情是「給足夠的資訊以及 source code,就能產生出一模一樣的 binary package」,這樣就不需要盲目信任 Debian 官方。

Debian 官方的 Wiki 上有「ReproducibleBuilds Howto」可以參考,然後也看到「reproducible-builds.org」這個站。

Ubuntu 下雙螢幕進入省電模式後再起不能的問題

Update:後來還是有狀況,這篇的方法沒有完全解決... 等找出解法後再回來更新。

前陣子把家裡的 Ubuntu 桌機多塞了一顆 Dell 的 P2317H,打直拿來看程式碼,大致上是沒什麼問題,不過螢幕進入省電模式後就再起不能... (NVIDIA 的顯卡,一顆接 DisplayPort,另外一顆接 HDMI)

後來找到這一串討論:「DP1.2 connected monitor cannot be turned on again with DPMS」。

這串討論裡官方的人有給不少方式,後來試到第二頁的發法,是在 /etc/modprobe.d/disable-nouveau.conf 裡設定一些參數,重開機後就解決了:

blacklist nouveau
options nouveau modeset=0

看起來是 nouveau 的關係,現在總算是可以比較正常的使用了... (還有不少眉眉角角的地方要再找方法解...)

Travis CI 總算要把 Trusty 當作預設環境了...

Ubuntu 14.04 (Trusty Tahr) 放出三年後,Travis CI 總算想起來該更新了:「Trusty as default Linux is coming」。

With the recent EOL of Ubuntu Precise, we are planning to begin setting the default distribution for builds to Ubuntu Trusty 14.04 on Tuesday, the 18th of July.

然後剩不到兩年又要 EoL 了... XD

在 Linux 下引用 Windows 的 DLL 檔

作者為了在 Linux 下進行安全分析而弄出來的計畫:「Porting Windows Dynamic Link Libraries to Linux」。

作者對 Windows 的架構有不少抱怨 XDDD

Distributed, scalable fuzzing on Windows can be challenging and inefficient. This is especially true for endpoint security products, which use complex interconnected components that span across kernel and user space. This often requires spinning up an entire virtualized Windows environment to fuzz them or collect coverage data.

This is less of a problem on Linux, and I've found that porting components of Windows Antivirus products to Linux is often possible. This allows me to run the code I’m testing in minimal containers with very little overhead, and easily scale up testing.

This is just personal opinion, but I also think Linux has better tools. ¯\_(ツ)_/¯

而這個專案跟 WineHQ 完整模擬不一樣,這只是給 Linux 下原生的程式使用 Windows 下 DLL 內的功能:

This project does not replace Wine or Winelib.

Winelib is used to port Windows C++ projects to Linux, and Wine is intended to run full Windows applications. This project is intended to allow native Linux code to load simple Windows DLLs.

The closest analogy would be ndiswrapper but for userspace.

作者拿了 Windows Defender 當範例,示範在 Linux 下呼叫 Windows 的 DLL...

Ubuntu 12.04 終結 (EoL)

Ubuntu 12.04 (Precise Pangolin) 上個禮拜宣佈終結了:「Ubuntu 12.04 (Precise Pangolin) End of Life reached on April 28, 2017」。還有被迫要使用 12.04 的人可以買 ESM (Extended Security Maintenance):「Introducing Ubuntu 12.04 ESM (Extended Security Maintenance)」。

話說回來,16.04 用到現在 (都已經出到 16.04.2 了),用起來覺得整體的流暢度與穩定度比 14.04 差了一大截...

Amazon EC2 上的 Ubuntu 的效能提昇

UbuntuAWS 合作,對 AWS 上 EC2 的 kernel 最佳化:「Ubuntu on AWS gets serious performance boost with AWS-tuned kernel」。

透過各界面拉出來的 Ubuntu 16.04 都將會是對 kernel 最佳化過的版本了:

As of March 29th, Ubuntu Cloud Images for Amazon have been enabled with the AWS-tuned Ubuntu kernel by default. The AWS-tuned Ubuntu kernel will receive the same level of support and security maintenance as all supported Ubuntu kernels for the duration of the Ubuntu 16.04 LTS.


  • Up to 30% faster kernel boot speeds, on a 15% smaller kernel package
  • Full support for Elastic Network Adapter (ENA), including the latest driver version 1.1.2, supporting up to 20 Gbps network speeds for ENA instance types (currently I3, P2, R4, X1, and m4.16xlarge)
  • Improved i3 instance class support with NVMe storage disks under high IO load
  • Increased I/O performance for i3 instances
  • Improved instance initialization with NVMe backed storage disks
  • Disabled CONFIG_NO_HZ_FULL to eliminate deadlocks on some instance types
  • Resolved CPU throttling with AWS t2.micro instances

所以先前打包好的 AMI 都要再重打一次了... @_@