Re: [OT]: Understanding Linux kernel book

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le Fri, 7 Dec 2007 19:58:26 +0530,
"Adil Mujeeb" <mujeeb.adil@xxxxxxxxx> a écrit :

> void fastcall __lock_page(struct page *page)
> 
> {
> 
>         DEFINE_WAIT_BIT(wait, &page->flags, PG_locked);
> 
>          __wait_on_bit_lock(page_waitqueue(page), &wait, sync_page,
> TASK_UNINTERRUPTIBLE);
> 
> }
> 
> 
> I think "stores the process descriptor in a wait queue" should be
> corrected as "stores the page descriptor in a wait queue"

I think the text is correct, wait queues are list of processes.

Roughly, what the code does is:

 1) Using DEFINE_WAIT_BIT, allocate on the stack a wait_bit_queue
    element

 2) Call __wait_on_bit_lock(), which will do:

    a) Call() prepare_to_wait_exclusive to add the current process
       (defined by the wait_bit_queue allocated at 1)) in the waitqueue
       of the page (fetched by page_waitqueue(page) in the call to
       __wait_on_bit_lock())

    b) Test if the condition of wait is met or not (i.e in our case is
       page->flags contains PG_locked)

    c) If not, call the function sync_page() provided as argument to
       the __wait_on_bit_lock() function. The sync_page() will start an
       asynchronous I/O operation and call io_schedule() that will elect
       another process to be run.

       [We're now sleeping...the I/O operation is processed...and...]

       When the I/O operation completes, we're woken up and we exit
       from io_schedule(), then from sync_page(), and we're now back in
       __wait_on_bit_lock().

    d) The condition (page->flags contains PG_locked) is tested again.
       If it's still not met, then we try again. Otherwise, we're done!

For more information, see http://lwn.net/images/pdf/LDD3/ch06.pdf,
section « Introduction to Sleeping », page 14 of the PDF, page 148 of
the book. It explains how wait queues work.

Thomas
-- 
Thomas Petazzoni, thomas.petazzoni@xxxxxxxx, http://thomas.enix.org
Jabber, thomas.petazzoni@xxxxxxxxx
Toulibre, http://www.toulibre.org - APRIL, http://www.april.org
Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E  1624 F653 CB30 98D3 F7A7

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux