3

Can anyone tell me the working of dirty_bytes and dirty_background_bytes in the Linux VM tunable parameters.

I infer that dirty_bytes specifies the amount of memory after which the application doing a write, starts writing directly to disk. Is it correct or if the amount of memory allocated is used up, that portion is first transferred to disk and then new data is again stored in memory. eg. suppose I want to transfer a 1 GB file to disk and I set dirty_bytes to be 100 MB then once 100 MB have been written to memory, the application doing the writing now starts writing the data directly to disk or the 100 MB is transferred to the disk and then again 100 MB is written to memory and then transferred to disk and so on?

And in case of dirty_background_bytes, when the portion of dirty memory exceeds this then pdflush writes the dirty data back to disk in the background.

Is my understanding correct for these 2 parameters?

1 Answer 1

7

No, exceeding dirty_bytes (or dirty_ratio) does not cause processes to start writing directly to disk.

Instead, when a process dirties a page in excess of the limit, that process is used to perform synchronous writeout of some dirty pages - exactly which ones is still decided by the usual heuristics. They may not necessarily even be pages that were originally dirtied by that particular process.

Effectively, the process sees its write (which may just be a memory write) suspended until some writeout has occurred.

You are correct about dirty_background_*. When the background limit is exceeded, asynchronous writeout is started, but the userspace process is allowed to continue.

3
  • and since dirty_background_bytes and dirty_bytes control the write cache, are there any parameters or any way to control the size of the read cache?
    – randy7
    Commented Jul 28, 2011 at 12:55
  • @randy7: The swappiness parameter tunes the balance between reclaming memory by swapping out inactive anonymous pages and reclaiming from the page cache. A lower number here will make the kernel prefer page cache reclaim more.
    – caf
    Commented Jul 29, 2011 at 4:43
  • @randy7 dirty_background_bytes and dirty_bytes do not control write cache size. They tell kernel when to write dirty pages into backend storage. The data will stay in the filesystem cache.
    – kofemann
    Commented Dec 2, 2016 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.