New FAMILUG

The PyMiers

Tuesday 5 August 2014

[OS] niceness

Như đã viết một ít ở bài này http://www.familug.org/2013/12/monitoring-iostat-hien-thi-cac-thong.html . niceness là một khái niệm không nên xa lạ với bất kỳ ai.

nice là gì?
là một khái niệm tương đương với priority nhưng ngược lại.
Khi CPU hoạt động, việc phân chia, lập lịch cho các process sẽ sử dụng khái niệm priority để tính mức độ ưu tiên. Một process được set priority càng cao (ưu tiên cao) sẽ được sử dụng CPU trước so với các priority thấp hơn. Khái niệm nice được đưa ra với ý nghĩa ngược lại của priority:
priority cao - niceness thấp
priority thấp - niceness cao

niceness
 (độ nice - độ tốt) là một kiểu dùng từ hay ho, khi nói 1 process có niceness cao tức là nói process đó "tốt bụng", sẵn sàng nhường CPU cho các process khác. Mức độ tốt bụng của 1 process được đánh số từ -20 đến 19. 0 là giá trị cơ bản, khi không chỉ định gì, một process sẽ có niceness = 0.

Trong manpage của renice lại nói niceness là 20 mới là nicest (giá trị nice cao nhất), nhưng khi thử set giá trị này thì không được (theo wikipedia thì giá trị max này là 19 hoặc 20, tuỳ hệ điều hành)
# renice 20 -p 19287
19287 (process ID) old priority 0, new priority 19
Các chương trình liên quan niceness 

trên:
# lsb_release -dc
Description:    Ubuntu 12.04 LTS
Codename:    precise
có các chương trình sau:
# apropos nice
ionice (1)           - set or get process I/O scheduling class and priority
nice (1)             - run a program with modified scheduling priority
renice (1)           - alter priority of running processes
Để chạy 1 program với nice tuỳ ý, dùng lệnh nice
Để thay đổi niceness của 1 program đang chạy, dùng renice
Để thay đổi  niceness sử dụng I/O của 1 process, dùng ionice
snice là 1 chương trình đã hết thời và bạn không cần quan tâm đến nó.

Đọc thêm
man 1 nice
Nicenesses range from  -20  (most  favorable  scheduling)  to  19   (least favorable).
man 1 renice
Users other than the super-user may only alter the priority of processes they own, and can only monotonically increase their ``nice value'' (for security reasons) within the range 0 to PRIO_MAX (20), unless a nice resource limit is set (Linux 2.6.12 and higher). The super-user may alter the priority of any process and set the priority to any value in the range PRIO_MIN (-20) to PRIO_MAX. Useful priorities are: 20 (the affected processes will run only when nothing else in the system wants to), 0 (the ``base'' scheduling priority), anything negative (to make things go very fast).
Hết.

No comments:

Post a Comment