Li-Wen Hsu’s Blog

October 11th, 2006

Resource Limits

剛剛, 商業團體的 ieon (在msn) 還有 far (在 IRC) 問,
有沒有辦法限一個 process 的 resource limits

直覺上是用 limits 限單一 user,從 /etc/login.conf 也是差不多,
要執行程式前用個 wrapper 把 process 變成受限的 user
這樣的解法感覺上不是相當漂亮。

IRC 上,mhsin 提到了 setrlimit(2) 然後也是用 wrap 的方法,
不過 kcwu 說,用 limits(1) 就可以
(果然 manpage 要多看,我一直以為 limits 是要設 global value 的…)

不過這個方法是限,cpu time,也就是 top(1) 時看到的 TIME 那欄

我比較好奇的是,有沒有限 WCPU (weighted cpu percentage) 的方法?

之前 openfoundry 那邊用 jail 也是有 resouce limits 的問題,
就是關於 WCPU 的部份 (似乎是 moztw.org 造成的問題 XD)
這在今年的 SoC 有了初步的成果:

而作者(Chris Jones)在 FreeBSD WikiJailResourceLimits 提到:

This system does not prevent a jailed process from monopolizing the CPU when there are no other runnable processes; rather, it only prevents a jail from using more CPU time than its share if there are other jailed processes (in which case they will tend to share CPU time in proportion to their respective CPU share allocations).

雖然不能限制單一 process 占據整個 cpu, 不過一想, 整台電腦就只有他在吃cpu時,
就給他吃嘛 :)

Filed under: FreeBSD, OS, Computer — lwhsu @ 02:43

Powered by WordPress