Dragonfly 发表于 2003-3-27 01:24:20

read code question

I read this one in filemap.c. and do not understand it.

static struct page * __find_lock_page_helper(struct address_space *mapping,
                                        unsigned long offset, struct page *hash)
{
struct page *page;

/*
* We scan the hash list read-only. Addition to and removal from
* the hash-list needs a held write-lock.
*/
repeat:
page = __find_page_nolock(mapping, offset, hash);
if (page) {
page_cache_get(page);
if (TryLockPage(page)) {
   spin_unlock(&pagecache_lock);
   lock_page(page);
   spin_lock(&pagecache_lock);

   /* Has the page been re-allocated while we slept? */
   if (page->mapping != mapping || page->index != offset) {
    UnlockPage(page);
    page_cache_release(page);
    goto repeat;
   }
}
}
return page;
}

why i need spin_unlock before lock the page, why not lock it directly. afterchecking it is reallocated, why i need release it?
can some one explain it? thx
页: [1]
查看完整版本: read code question