Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 17: Data Synchronization


Block
device

Pdflush threads Queues

Create &
destroy
threads

Order data integrity
or flushing writeback

Policy

1

3

(^2) deviceBlock
Block
device
Figure 17-2: Overview of thepdflushmechanism.
17.3 Starting a New Thread
Thepdflushmechanism consists of two central components — a data structure to describe the work of
the thread and a strategy routine to help perform the work.
The data structure is defined as follows:
mm/pdflush.c
struct pdflush_work {
struct task_struct who; / The thread /
void (
fn)(unsigned long); / A callback function /
unsigned long arg0; / An argument to the callback /
struct list_head list; / On pdflush_list, when idle /
unsigned long when_i_went_to_sleep;
};
As usual, the fact that the data structure is defined in a C header file instead of a header file indicates to
the kernel that the structure may be used only by internal code. Generic code uses other mechanisms to
access the kernel synchronization capabilities that are examined below:
❑ whois a pointer to the kernel threadtask_structinstance used to represent the specificpdflush
instance in the process table.
❑ Several instances ofpdflush_workcan be grouped together in a doubly linked standard
list using thelistlist head. The kernel uses the global variablepdflush_list(defined in
mm/pdflush.c) to draw up a list of the work still to be done.
❑ The extraordinarily longwhen_i_went_to_sleepelement stores the time in jiffies when
the thread last went to sleep. This value is used to remove superfluouspdflushthreads
from the system (i.e., threads that are still in memory but have been idle for a longer
period).
❑ Thefnfunction pointer (in conjunction witharg0) is the backbone of the structure. It holds the
function in which the actual work to be done is implemented.arg0is passed as an argument
when the function is invoked.
By using different function pointers forfn, the kernel is able to incorporate a variety of synchro-
nization routines in thepdflushframework so that the right routine can be selected for the job
in hand.

Free download pdf