int pdflush_operation(void (*fn)(unsigned long), unsigned long arg0) {

unsigned long flags; int ret = 0;

struct pdflush_work *pdf;


pdflush_operation accepts two arguments that specify the worker function and its argument.

If the list pdflush_list is empty and thus no pdflush daemon can be awoken, an error code is returned. If a sleeping pdflush instance is in the queue, it is removed and is no longer available to any other part of the kernel. The values for the worker function and argument are assigned to the corresponding fields of pdflush_work, and immediately thereafter the thread is woken with wake_up_process. Thanks to the who element in pdflush_work, the kernel knows which process is meant.

To ensure that there are always enough worker threads, the kernel checks whether the pdflush_list list is empty after removing the current instance, but before waking the thread. If it is, last_empty_jifs is set to the current system time. When a thread terminates, the kernel uses this information to check the period during which no surplus threads were available — it can then start a new thread as described above.

pdf = list_entry(, struct pdflush_work, list);

if (list_empty(&pdflush_list))

last_empty_jifs = jiffies; pdf->fn = fn; pdf->arg0 = arg0; wake_up_process(pdf->who);


2The time the pdflush_list list was last empty is noted in the global variable last_empty_jifs.

Continue reading here: Periodic Flushing

Was this article helpful?

0 0