Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


have created dirty pages on a mapping. If the number of dirty pages in the system becomes too
large, thenbackground_writeoutis used to start synchronizing. In contrast to all cases discussed
above, thepdflushthread may not operate on all queues of the system. Only the queue of the
backing device to which the dirtied page belongs is considered.

17.13 Laptop Mode


Laptop users have a natural tendency to reduce power consumption of their machines as much as
possible — this is because laptop batteries, on the other side, have a natural tendency to provide power
forntime units whenn+ktime units (withk>0) are required to finish some really important work
far away from any power outlet. There are some points wherepdflushcan contribute. Hard disks are,
with today’s hardware, implemented bydisksin the true sense of the word — alternatives in the form of
solid-state devices have started to appear on the horizon, but are still far from being widespread. A hard
disk needs to spin in order to be operational. This consumes power, and spinning down the hard disk
when it is not needed thus helps to decrease power consumption.

What is still worse than a spinning hard disk is, however, a hard disk that accelerates. This requires more
energy than a disk running at constant speed. The optimization goals of the kernel are therefore twofold:


  1. Keep the disk spun down as long as possible. This can be satisfied by deferring write
    requests longer than usual.

  2. When accelerating the disk cannot be avoided, perform all pending write operations even
    if these would still be delayed under normal circumstances.^7 This helps to prevent the disk
    from spinning up and down.
    Essentially, disk operations need to be performed in bursts: If data must be read in from the
    device, then all pending write operations can be performed since the device is now active
    anyway.


To achieve these goals, the kernel offers alaptop modethat can be activated via/proc/sys/vm/laptop_
mode. The global variablelaptop_modeacts as a Boolean indicator if laptop mode is currently active. User-
land daemons can, for instance, use this file to enable and disable laptop mode depending on whether the
device operates from a battery or a power supply. Notice that some documentation about this technique
is available inDocumentation/laptop-mode.txt.

Laptop mode requires astonishingly few changes in the synchronization code:

❑ Anewpdflushworker routine is used:laptop_flushjust callssys_syncto synchronize all dirty
data present in the system (the effect is identical to calling thesyncsystem call). Since this will
generate a whole lot of disk I/O, it is essential to activate the thread only when it is known that
the disk is up and running.
When requests are processed, block devices use the standard functionend_that_request_last
to signal that the last request in a series has been submitted. Since this ensures that a disk
is up and running, the function callslaptop_io_completion, which installs a timer on
laptop_mode_wb_timerthat executeslaptop_timer_fn1 second from now.

(^7) Read operations require spinning up the disk anyway, so there’s little that can be done here except to avoid useless reads.

Free download pdf