Writing Dirty Buffers to Disk

Unix systems allow the deferred writes of dirty buffers into block devices, since this noticeably improves system performance. Several write operations on a buffer could be satisfied by just one slow physical update of the corresponding disk block. Moreover, write operations are less critical than read operations, since a process is usually not suspended because of delayed writings, while it is most often suspended because of delayed reads. Thanks to deferred writes, each physical block device will service, on the average, many more read requests than write ones.

A dirty buffer might stay in main memory until the last possible moment — that is, until system shutdown. However, pushing the delayed-write strategy to its limits has two major drawbacks:

• If a hardware or power supply failure occurs, the contents of RAM can no longer be retrieved, so many file updates that were made since the system was booted are lost.

• The size of the buffer cache, and hence of the RAM required to contain it, would have to be huge—at least as big as the size of the accessed block devices.

Therefore, dirty buffers are flushed (written) to disk under the following conditions:

• The buffer cache gets too full and more buffers are needed, or the number of dirty buffers becomes too large; when one of these conditions occurs, the bdflush kernel thread is activated.

• Too much time has elapsed since a buffer has stayed dirty; the kupdate kernel thread regularly flushes old buffers.

• A process requests all the buffers of block devices or of particular files to be flushed; it does this by invoking the sync( ), fsync( ), or fdatasync( ) system call.

As explained in the earlier section Section 14.2.2, a buffer page is dirty (pg_dirty flag set) if some of its buffers are dirty. As soon as the kernel flushes all dirty buffers in a buffer page to disk, it resets the pg_dirty flag of the page.

14.2.4.1 The bdflush kernel thread

The bdflush kernel thread (also called kflushd ) is created during system initialization. It executes the bdflush( ) function, which selects some dirty buffers and forces an update of the corresponding blocks on the physical block devices.

Some system parameters control the behavior of bdflush; they are stored in the b_un field of the bdf_prm table and are accessible either by means of the /proc/sys/vm/bdflush file or by invoking the bdflush( ) system call. Each parameter has a default standard value, although it may vary within a minimum and a maximum value stored in the bdflush_min and bdflush_max tables, respectively. The parameters are listed in Table 14-4. 14]

Continue reading here: [4 The bdfprm table also includes several other unused fields

Was this article helpful?

+3 0

Responses

  • helvi
    How check the dirty buffers in a database in linux?
    2 years ago
  • bladud
    What is Linux dirty write?
    2 years ago