Understanding Linux Kernel의 15.3 장을 찾아보면 아래와 같은 구절이 나옵니다.
--- /proc/sys/vm/dirty_background_ratio
Quote:
Moreover, a pdflush kernel thread executing the background_writeout( ) callback function is woken up by every process that modifies the contents of pages in the page cache and causes the fraction of dirty pages to rise above some dirty background threshold. The background threshold is typically set to 10% of all pages in the system, but its value can be adjusted by writing in the /proc/sys/vm/dirty_background_ratio file.
--- /proc/sys/vm/dirty_ratio
Quote:
The background_writeout( ) function acts on a single parameter: nr_pages, the minimum number of pages that should be flushed to disk. It essentially executes the following steps:
1. Reads from the page_state per-CPU variable the number of pages and dirty pages currently stored in the page cache. If the fraction of dirty pages is below a given threshold and at least nr_pages have been flushed to disk, the function terminates. The value of this threshold is typically set to about 40% of the number of pages in the system; it could be adjusted by writing into the /proc/sys/vm/dirty_ratio file.
나름대로 두줄요약
1. dirty_background_ratio --> pdflush 커널 쓰레드가 깨어날 조건
2. dirty_ratio --> pdflush 가 다시 자기 위한 '필요'조건, '충분'조건은 아님
Contains, as a percentage of total system memory, the number of pages at which the pdflush background writeback daemon will start writing out dirty data.
==> pdflush 커널 쓰레드가 깨어날 조건, background_writeout()가 불리는 것 같습니다.
---- dirty_ratio
Contains, as 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.
==> 디스크 쓰기를 생성하는 프로세스가 dirty data를 쓰기 시작할 조건, balance_dirty_pages()가 불리는 것 같습니다.
The percentage of memory that is allowed to contain "dirty" or unsaved data
before a writeback is forced, while laptop mode is active. Corresponds to
the /proc/sys/vm/dirty_ratio sysctl.
DIRTY_BACKGROUND_RATIO:
The percentage of memory that is allowed to contain "dirty" or unsaved data
after a forced writeback is done due to an exceeding of DIRTY_RATIO. Set
this nice and low. This corresponds to the /proc/sys/vm/dirty_background_ratio
sysctl.
Note that the behaviour of dirty_background_ratio is quite different
when laptop mode is active and when it isn't. When laptop mode is inactive,
dirty_background_ratio is the threshold percentage at which background writeouts
start taking place. When laptop mode is active, however, background writeouts
are disabled, and the dirty_background_ratio only determines how much writeback
is done when dirty_ratio is reached.
Note: Proposed changes need to be verified with Dell and Novell staff, tested and if they help implemented one at a time.
For fast disk subsystems, it is desirable to use large flushes of dirty memory pages.
The value stored in /proc/sys/vm/dirty_background_ratio defines at what percentage of main memory the pdflush daemon should write data out to the disk.
If larger flushes are desired then increasing the default value of 10% to a larger value will cause less frequent flushes.
As in the example above the value can be changed to 25 as shown in
# sysctl -w vm.dirty_background_ratio=25
Another related setting in the virtual memory subsystem is the ratio at which dirty pages created by application disk writes will be flushed out to disk.
The default value 10 means that data will be written into system memory until the file system cache has a size of 10% of the server’s RAM.
The ratio at which dirty pages are written to disk can be altered as follows to a setting of 20% of the system memory
dirty_background_ratio은 dirty_ratio는 각각 asynchronous page flushing과 synchronous page flushing과 관련됩니다.
1. asynchronous page flushing
pdflush 커널 쓰레드가 수행하는 asynchronous page flushing은 전역적(global)이고 비동기적
(asynchronous)인 특징이 있습니다.
- asynchronous
pdflush는 dirty page가 dirty_background_ratio를 넘는지를 검사합니다. 이때 검사하는 시점이 중요한데, dirty page가 증가할 때마다 검사하는 것이 아니라 타이머를 두어서 일정한 시간마다 검사하게됩니다. 즉 dirty page가 증가하는 시점과 flushing할 지 여부를 검사하는 시점이 다릅니다. 이런 특정을 asynchronous하다고 합니다.
- global
pdflush는 모든 파일을 대상으로 합니다. 즉 모든 파일의 page cache들을 뒤져서 dirty page를 찾아낸 뒤 디스크에 플러슁합니다. 이런 특징으로 global하다고 할 수 있습니다.
2. synchronous page flushing
Synchronous page flushing은 지역적(local)이고 동기적(synchronous)입니다.
이런 동작이 일어나는 상황을 생각해보죠. 사용자 프로세스가 특정 파일 F에 쓰기 작업을 하면서 관련된 시스템 호출 (system call) 를 부릅니다. 그러면 커널 모드로 전환이 되어 F의 page cache에 dirty page가 증가하게 됩니다.
- synchronous
dirty page가 증가할 때 dirty_ratio와 비교를 합니다. 따라서 동기적입니다.
- local
만약 파일 F에 해당하는 dirty page가 증가하였다면 flushing의 대상은 파일 F의 page cache만입니다.
정리하면 다음과 같은 표를 얻을 수 있겠습니다.
------------------------------------------------------------------
| flushing 시작시점 flushing 대상
------------------------------------------------------------------
asynchronous page flushing | asynchronous global
synchronous page flushing | synchronous local
------------------------------------------------------------------
여기까지가 제가 정리한 내용입니다. 참고로 "global asynchronous vs. local synchronous"는 page flushing에만 적용되는 것이 아니고 linux kernel의 다른 subsystem에서도 나타납니다.
Understanding Linux
Understanding Linux Kernel의 15.3 장을 찾아보면 아래와 같은 구절이 나옵니다.
--- /proc/sys/vm/dirty_background_ratio
--- /proc/sys/vm/dirty_ratio
나름대로 두줄요약
1. dirty_background_ratio --> pdflush 커널 쓰레드가 깨어날 조건
2. dirty_ratio --> pdflush 가 다시 자기 위한 '필요'조건, '충분'조건은 아님
그건 그렇고 찾아 보셨다던 원문을 제가 알 수 없을까요. 어떻게 쓰여져 있나 궁금하네요.
아무래도 제가 올린
아무래도 제가 올린 이 답변의 내용은 잘못된 것 같네요.
위의 해석대로라면 pdflush가 너무 자주 깨어날 것 같습니다. "dirty_background_ratio < dirty_ratio" 이니까요.
http://www.linuxinsight.com/proc_sys_vm_dirty_background_ratio.html
위 주소를 보니 다음과 같이 적혀있네요.
---- dirty_background_ratio
Contains, as a percentage of total system memory, the number of pages at which the pdflush background writeback daemon will start writing out dirty data.
==> pdflush 커널 쓰레드가 깨어날 조건, background_writeout()가 불리는 것 같습니다.
---- dirty_ratio
Contains, as 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.
==> 디스크 쓰기를 생성하는 프로세스가 dirty data를 쓰기 시작할 조건, balance_dirty_pages()가 불리는 것 같습니다.
제가 찾아본 내용들입니다.
우선 답변 감사합니다.
제가 찾아본 정보는 아래와 같습니다.
DIRTY_RATIO:
The percentage of memory that is allowed to contain "dirty" or unsaved data
before a writeback is forced, while laptop mode is active. Corresponds to
the /proc/sys/vm/dirty_ratio sysctl.
DIRTY_BACKGROUND_RATIO:
The percentage of memory that is allowed to contain "dirty" or unsaved data
after a forced writeback is done due to an exceeding of DIRTY_RATIO. Set
this nice and low. This corresponds to the /proc/sys/vm/dirty_background_ratio
sysctl.
Note that the behaviour of dirty_background_ratio is quite different
when laptop mode is active and when it isn't. When laptop mode is inactive,
dirty_background_ratio is the threshold percentage at which background writeouts
start taking place. When laptop mode is active, however, background writeouts
are disabled, and the dirty_background_ratio only determines how much writeback
is done when dirty_ratio is reached.
그리고
http://cafe.naver.com/linuxdevdrv.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=51
또,
Disk subsystem tuning
Note: Proposed changes need to be verified with Dell and Novell staff, tested and if they help implemented one at a time.
For fast disk subsystems, it is desirable to use large flushes of dirty memory pages.
The value stored in /proc/sys/vm/dirty_background_ratio defines at what percentage of main memory the pdflush daemon should write data out to the disk.
If larger flushes are desired then increasing the default value of 10% to a larger value will cause less frequent flushes.
As in the example above the value can be changed to 25 as shown in
# sysctl -w vm.dirty_background_ratio=25
Another related setting in the virtual memory subsystem is the ratio at which dirty pages created by application disk writes will be flushed out to disk.
The default value 10 means that data will be written into system memory until the file system cache has a size of 10% of the server’s RAM.
The ratio at which dirty pages are written to disk can be altered as follows to a setting of 20% of the system memory
# sysctl -w vm.dirty_ratio=20
이런 정보를 확인 했는데, 두개이 차이점을 정확히 구분짓기가 힘드네요.
제가 '나름대로'
제가 '나름대로' 정리해보았습니다.
dirty_background_ratio은 dirty_ratio는 각각 asynchronous page flushing과 synchronous page flushing과 관련됩니다.
1. asynchronous page flushing
pdflush 커널 쓰레드가 수행하는 asynchronous page flushing은 전역적(global)이고 비동기적
(asynchronous)인 특징이 있습니다.
- asynchronous
pdflush는 dirty page가 dirty_background_ratio를 넘는지를 검사합니다. 이때 검사하는 시점이 중요한데, dirty page가 증가할 때마다 검사하는 것이 아니라 타이머를 두어서 일정한 시간마다 검사하게됩니다. 즉 dirty page가 증가하는 시점과 flushing할 지 여부를 검사하는 시점이 다릅니다. 이런 특정을 asynchronous하다고 합니다.
- global
pdflush는 모든 파일을 대상으로 합니다. 즉 모든 파일의 page cache들을 뒤져서 dirty page를 찾아낸 뒤 디스크에 플러슁합니다. 이런 특징으로 global하다고 할 수 있습니다.
2. synchronous page flushing
Synchronous page flushing은 지역적(local)이고 동기적(synchronous)입니다.
이런 동작이 일어나는 상황을 생각해보죠. 사용자 프로세스가 특정 파일 F에 쓰기 작업을 하면서 관련된 시스템 호출 (system call) 를 부릅니다. 그러면 커널 모드로 전환이 되어 F의 page cache에 dirty page가 증가하게 됩니다.
- synchronous
dirty page가 증가할 때 dirty_ratio와 비교를 합니다. 따라서 동기적입니다.
- local
만약 파일 F에 해당하는 dirty page가 증가하였다면 flushing의 대상은 파일 F의 page cache만입니다.
정리하면 다음과 같은 표를 얻을 수 있겠습니다.
여기까지가 제가 정리한 내용입니다. 참고로 "global asynchronous vs. local synchronous"는 page flushing에만 적용되는 것이 아니고 linux kernel의 다른 subsystem에서도 나타납니다.
댓글 달기