History

mm: rename page trylock

Converting page lock to new locking bitops requires a change of page flag operation naming, so we might as well convert it to something nicer (!TestSetPageLocked_Lock => trylock_page, SetPageLocked => set_page_locked). This also facilitates lockdeping of page lock.

Nick Piggin committed 18 years ago

Commit 529ae9a1 parent e9ba96920 files · +74 −59Browse files

Unified · Split

20 files
  1. drivers/scsi/sg.c +1 −1
  2. fs/afs/write.c +1 −1
  3. fs/cifs/file.c +1 −1
  4. fs/jbd/commit.c +2 −2
  5. fs/jbd2/commit.c +1 −1
  6. fs/reiserfs/journal.c +1 −1
  7. fs/splice.c +1 −1
  8. fs/xfs/linux-2.6/xfs_aops.c +2 −2
  9. include/linux/page-flags.h +1 −1
  10. include/linux/pagemap.h +41 −26
  11. mm/filemap.c +6 −6
  12. mm/memory.c +1 −1
  13. mm/migrate.c +2 −2
  14. mm/rmap.c +1 −1
  15. mm/shmem.c +2 −2
  16. mm/swap.c +1 −1
  17. mm/swap_state.c +4 −4
  18. mm/swapfile.c +1 −1
  19. mm/truncate.c +2 −2
  20. mm/vmscan.c +2 −2
drivers/scsi/sg.c+1−1
@@ -1747,7 +1747,7 @@ st_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages, · 1746 unmodified lines
17471747 */
17481748 flush_dcache_page(pages[i]);
17491749 /* ?? Is locking needed? I don't think so */
1750− /* if (TestSetPageLocked(pages[i]))
1750+ /* if (!trylock_page(pages[i]))
17511751 goto out_unlock; */
17521752 }
17531753
fs/afs/write.c+1−1
@@ -404,7 +404,7 @@ static int afs_write_back_from_locked_page(struct afs_writeback *wb, · 403 unmodified lines
404404 page = pages[loop];
405405 if (page->index > wb->last)
406406 break;
407− if (TestSetPageLocked(page))
407+ if (!trylock_page(page))
408408 break;
409409 if (!PageDirty(page) ||
410410 page_private(page) != (unsigned long) wb) {
fs/cifs/file.c+1−1
@@ -1280,7 +1280,7 @@ retry: · 1279 unmodified lines
12801280
12811281 if (first < 0)
12821282 lock_page(page);
1283− else if (TestSetPageLocked(page))
1283+ else if (!trylock_page(page))
12841284 break;
12851285
12861286 if (unlikely(page->mapping != mapping)) {
fs/jbd/commit.c+2−2
@@ -63,7 +63,7 @@ static void release_buffer_page(struct buffer_head *bh) · 62 unmodified lines
6363 goto nope;
6464
6565 /* OK, it's a truncated page */
66− if (TestSetPageLocked(page))
66+ if (!trylock_page(page))
6767 goto nope;
6868
6969 page_cache_get(page);
@@ -446,7 +446,7 @@ void journal_commit_transaction(journal_t *journal) · 376 unmodified lines
446446 spin_lock(&journal->j_list_lock);
447447 }
448448 if (unlikely(!buffer_uptodate(bh))) {
449− if (TestSetPageLocked(bh->b_page)) {
449+ if (!trylock_page(bh->b_page)) {
450450 spin_unlock(&journal->j_list_lock);
451451 lock_page(bh->b_page);
452452 spin_lock(&journal->j_list_lock);
fs/jbd2/commit.c+1−1
@@ -67,7 +67,7 @@ static void release_buffer_page(struct buffer_head *bh) · 66 unmodified lines
6767 goto nope;
6868
6969 /* OK, it's a truncated page */
70− if (TestSetPageLocked(page))
70+ if (!trylock_page(page))
7171 goto nope;
7272
7373 page_cache_get(page);
fs/reiserfs/journal.c+1−1
@@ -627,7 +627,7 @@ static int journal_list_still_alive(struct super_block *s, · 626 unmodified lines
627627 static void release_buffer_page(struct buffer_head *bh)
628628 {
629629 struct page *page = bh->b_page;
630− if (!page->mapping && !TestSetPageLocked(page)) {
630+ if (!page->mapping && trylock_page(page)) {
631631 page_cache_get(page);
632632 put_bh(bh);
633633 if (!page->mapping)
fs/splice.c+1−1
@@ -371,7 +371,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos, · 370 unmodified lines
371371 * for an in-flight io page
372372 */
373373 if (flags & SPLICE_F_NONBLOCK) {
374− if (TestSetPageLocked(page)) {
374+ if (!trylock_page(page)) {
375375 error = -EAGAIN;
376376 break;
377377 }
fs/xfs/linux-2.6/xfs_aops.c+2−2
@@ -675,7 +675,7 @@ xfs_probe_cluster( · 674 unmodified lines
675675 } else
676676 pg_offset = PAGE_CACHE_SIZE;
677677
678− if (page->index == tindex && !TestSetPageLocked(page)) {
678+ if (page->index == tindex && trylock_page(page)) {
679679 pg_len = xfs_probe_page(page, pg_offset, mapped);
680680 unlock_page(page);
681681 }
@@ -759,7 +759,7 @@ xfs_convert_page( · 77 unmodified lines
759759
760760 if (page->index != tindex)
761761 goto fail;
762− if (TestSetPageLocked(page))
762+ if (!trylock_page(page))
763763 goto fail;
764764 if (PageWriteback(page))
765765 goto fail_unlock_page;
include/linux/page-flags.h+1−1
@@ -163,7 +163,7 @@ static inline int Page##uname(struct page *page) \ · 162 unmodified lines
163163
164164 struct page; /* forward declaration */
165165
166−PAGEFLAG(Locked, locked) TESTSCFLAG(Locked, locked)
166+TESTPAGEFLAG(Locked, locked)
167167 PAGEFLAG(Error, error)
168168 PAGEFLAG(Referenced, referenced) TESTCLEARFLAG(Referenced, referenced)
169169 PAGEFLAG(Dirty, dirty) TESTSCFLAG(Dirty, dirty) __CLEARPAGEFLAG(Dirty, dirty)
include/linux/pagemap.h+41−26
@@ -250,29 +250,6 @@ static inline struct page *read_mapping_page(struct address_space *mapping, · 249 unmodified lines
250250 return read_cache_page(mapping, index, filler, data);
251251 }
252252
253−int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
254− pgoff_t index, gfp_t gfp_mask);
255−int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
256− pgoff_t index, gfp_t gfp_mask);
257−extern void remove_from_page_cache(struct page *page);
258−extern void __remove_from_page_cache(struct page *page);
259−
260−/*
261− * Like add_to_page_cache_locked, but used to add newly allocated pages:
262− * the page is new, so we can just run SetPageLocked() against it.
263− */
264−static inline int add_to_page_cache(struct page *page,
265− struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask)
266−{
267− int error;
268−
269− SetPageLocked(page);
270− error = add_to_page_cache_locked(page, mapping, offset, gfp_mask);
271− if (unlikely(error))
272− ClearPageLocked(page);
273− return error;
274−}
275−
276253 /*
277254 * Return byte-offset into filesystem object for page.
278255 */
@@ -294,13 +271,28 @@ extern int __lock_page_killable(struct page *page); · 15 unmodified lines
294271 extern void __lock_page_nosync(struct page *page);
295272 extern void unlock_page(struct page *page);
296273
274+static inline void set_page_locked(struct page *page)
275+{
276+ set_bit(PG_locked, &page->flags);
277+}
278+
279+static inline void clear_page_locked(struct page *page)
280+{
281+ clear_bit(PG_locked, &page->flags);
282+}
283+
284+static inline int trylock_page(struct page *page)
285+{
286+ return !test_and_set_bit(PG_locked, &page->flags);
287+}
288+
297289 /*
298290 * lock_page may only be called if we have the page's inode pinned.
299291 */
300292 static inline void lock_page(struct page *page)
301293 {
302294 might_sleep();
303− if (TestSetPageLocked(page))
295+ if (!trylock_page(page))
304296 __lock_page(page);
305297 }
306298
@@ -312,7 +304,7 @@ static inline void lock_page(struct page *page) · 5 unmodified lines
312304 static inline int lock_page_killable(struct page *page)
313305 {
314306 might_sleep();
315− if (TestSetPageLocked(page))
307+ if (!trylock_page(page))
316308 return __lock_page_killable(page);
317309 return 0;
318310 }
@@ -324,7 +316,7 @@ static inline int lock_page_killable(struct page *page) · 5 unmodified lines
324316 static inline void lock_page_nosync(struct page *page)
325317 {
326318 might_sleep();
327− if (TestSetPageLocked(page))
319+ if (!trylock_page(page))
328320 __lock_page_nosync(page);
329321 }
330322
@@ -409,4 +401,27 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size) · 78 unmodified lines
409401 return ret;
410402 }
411403
404+int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
405+ pgoff_t index, gfp_t gfp_mask);
406+int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
407+ pgoff_t index, gfp_t gfp_mask);
408+extern void remove_from_page_cache(struct page *page);
409+extern void __remove_from_page_cache(struct page *page);
410+
411+/*
412+ * Like add_to_page_cache_locked, but used to add newly allocated pages:
413+ * the page is new, so we can just run set_page_locked() against it.
414+ */
415+static inline int add_to_page_cache(struct page *page,
416+ struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask)
417+{
418+ int error;
419+
420+ set_page_locked(page);
421+ error = add_to_page_cache_locked(page, mapping, offset, gfp_mask);
422+ if (unlikely(error))
423+ clear_page_locked(page);
424+ return error;
425+}
426+
412427 #endif /* _LINUX_PAGEMAP_H */
mm/filemap.c+6−6
@@ -558,14 +558,14 @@ EXPORT_SYMBOL(wait_on_page_bit); · 557 unmodified lines
558558 * But that's OK - sleepers in wait_on_page_writeback() just go back to sleep.
559559 *
560560 * The first mb is necessary to safely close the critical section opened by the
561− * TestSetPageLocked(), the second mb is necessary to enforce ordering between
562− * the clear_bit and the read of the waitqueue (to avoid SMP races with a
563− * parallel wait_on_page_locked()).
561+ * test_and_set_bit() to lock the page; the second mb is necessary to enforce
562+ * ordering between the clear_bit and the read of the waitqueue (to avoid SMP
563+ * races with a parallel wait_on_page_locked()).
564564 */
565565 void unlock_page(struct page *page)
566566 {
567567 smp_mb__before_clear_bit();
568− if (!TestClearPageLocked(page))
568+ if (!test_and_clear_bit(PG_locked, &page->flags))
569569 BUG();
570570 smp_mb__after_clear_bit();
571571 wake_up_page(page, PG_locked);
@@ -931,7 +931,7 @@ grab_cache_page_nowait(struct address_space *mapping, pgoff_t index) · 359 unmodified lines
931931 struct page *page = find_get_page(mapping, index);
932932
933933 if (page) {
934− if (!TestSetPageLocked(page))
934+ if (trylock_page(page))
935935 return page;
936936 page_cache_release(page);
937937 return NULL;
@@ -1027,7 +1027,7 @@ find_page: · 89 unmodified lines
10271027 if (inode->i_blkbits == PAGE_CACHE_SHIFT ||
10281028 !mapping->a_ops->is_partially_uptodate)
10291029 goto page_not_up_to_date;
1030− if (TestSetPageLocked(page))
1030+ if (!trylock_page(page))
10311031 goto page_not_up_to_date;
10321032 if (!mapping->a_ops->is_partially_uptodate(page,
10331033 desc, offset))
mm/memory.c+1−1
@@ -1789,7 +1789,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, · 1788 unmodified lines
17891789 * not dirty accountable.
17901790 */
17911791 if (PageAnon(old_page)) {
1792− if (!TestSetPageLocked(old_page)) {
1792+ if (trylock_page(old_page)) {
17931793 reuse = can_share_swap_page(old_page);
17941794 unlock_page(old_page);
17951795 }
mm/migrate.c+2−2
@@ -605,7 +605,7 @@ static int move_to_new_page(struct page *newpage, struct page *page) · 604 unmodified lines
605605 * establishing additional references. We are the only one
606606 * holding a reference to the new page at this point.
607607 */
608− if (TestSetPageLocked(newpage))
608+ if (!trylock_page(newpage))
609609 BUG();
610610
611611 /* Prepare mapping for the new page.*/
@@ -667,7 +667,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, · 55 unmodified lines
667667 BUG_ON(charge);
668668
669669 rc = -EAGAIN;
670− if (TestSetPageLocked(page)) {
670+ if (!trylock_page(page)) {
671671 if (!force)
672672 goto move_newpage;
673673 lock_page(page);
mm/rmap.c+1−1
@@ -422,7 +422,7 @@ int page_referenced(struct page *page, int is_locked, · 421 unmodified lines
422422 referenced += page_referenced_anon(page, mem_cont);
423423 else if (is_locked)
424424 referenced += page_referenced_file(page, mem_cont);
425− else if (TestSetPageLocked(page))
425+ else if (!trylock_page(page))
426426 referenced++;
427427 else {
428428 if (page->mapping)
mm/shmem.c+2−2
@@ -1265,7 +1265,7 @@ repeat: · 1264 unmodified lines
12651265 }
12661266
12671267 /* We have to do this with page locked to prevent races */
1268− if (TestSetPageLocked(swappage)) {
1268+ if (!trylock_page(swappage)) {
12691269 shmem_swp_unmap(entry);
12701270 spin_unlock(&info->lock);
12711271 wait_on_page_locked(swappage);
@@ -1329,7 +1329,7 @@ repeat: · 57 unmodified lines
13291329 shmem_swp_unmap(entry);
13301330 filepage = find_get_page(mapping, idx);
13311331 if (filepage &&
1332− (!PageUptodate(filepage) || TestSetPageLocked(filepage))) {
1332+ (!PageUptodate(filepage) || !trylock_page(filepage))) {
13331333 spin_unlock(&info->lock);
13341334 wait_on_page_locked(filepage);
13351335 page_cache_release(filepage);
mm/swap.c+1−1
@@ -444,7 +444,7 @@ void pagevec_strip(struct pagevec *pvec) · 443 unmodified lines
444444 for (i = 0; i < pagevec_count(pvec); i++) {
445445 struct page *page = pvec->pages[i];
446446
447− if (PagePrivate(page) && !TestSetPageLocked(page)) {
447+ if (PagePrivate(page) && trylock_page(page)) {
448448 if (PagePrivate(page))
449449 try_to_release_page(page, 0);
450450 unlock_page(page);
mm/swap_state.c+4−4
@@ -201,7 +201,7 @@ void delete_from_swap_cache(struct page *page) · 200 unmodified lines
201201 */
202202 static inline void free_swap_cache(struct page *page)
203203 {
204− if (PageSwapCache(page) && !TestSetPageLocked(page)) {
204+ if (PageSwapCache(page) && trylock_page(page)) {
205205 remove_exclusive_swap_page(page);
206206 unlock_page(page);
207207 }
@@ -302,9 +302,9 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, · 94 unmodified lines
302302 * re-using the just freed swap entry for an existing page.
303303 * May fail (-ENOMEM) if radix-tree node allocation failed.
304304 */
305− SetPageLocked(new_page);
305+ set_page_locked(new_page);
306306 err = add_to_swap_cache(new_page, entry, gfp_mask & GFP_KERNEL);
307− if (!err) {
307+ if (likely(!err)) {
308308 /*
309309 * Initiate read into locked page and return.
310310 */
@@ -312,7 +312,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, · 1 unmodified line
312312 swap_readpage(NULL, new_page);
313313 return new_page;
314314 }
315− ClearPageLocked(new_page);
315+ clear_page_locked(new_page);
316316 swap_free(entry);
317317 } while (err != -ENOMEM);
318318
mm/swapfile.c+1−1
@@ -403,7 +403,7 @@ void free_swap_and_cache(swp_entry_t entry) · 402 unmodified lines
403403 if (p) {
404404 if (swap_entry_free(p, swp_offset(entry)) == 1) {
405405 page = find_get_page(&swapper_space, entry.val);
406− if (page && unlikely(TestSetPageLocked(page))) {
406+ if (page && unlikely(!trylock_page(page))) {
407407 page_cache_release(page);
408408 page = NULL;
409409 }
mm/truncate.c+2−2
@@ -187,7 +187,7 @@ void truncate_inode_pages_range(struct address_space *mapping, · 186 unmodified lines
187187 if (page_index > next)
188188 next = page_index;
189189 next++;
190− if (TestSetPageLocked(page))
190+ if (!trylock_page(page))
191191 continue;
192192 if (PageWriteback(page)) {
193193 unlock_page(page);
@@ -280,7 +280,7 @@ unsigned long __invalidate_mapping_pages(struct address_space *mapping, · 86 unmodified lines
280280 pgoff_t index;
281281 int lock_failed;
282282
283− lock_failed = TestSetPageLocked(page);
283+ lock_failed = !trylock_page(page);
284284
285285 /*
286286 * We really shouldn't be looking at the ->index of an
mm/vmscan.c+2−2
@@ -496,7 +496,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, · 495 unmodified lines
496496 page = lru_to_page(page_list);
497497 list_del(&page->lru);
498498
499− if (TestSetPageLocked(page))
499+ if (!trylock_page(page))
500500 goto keep;
501501
502502 VM_BUG_ON(PageActive(page));
@@ -582,7 +582,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, · 79 unmodified lines
582582 * A synchronous write - probably a ramdisk. Go
583583 * ahead and try to reclaim the page.
584584 */
585− if (TestSetPageLocked(page))
585+ if (!trylock_page(page))
586586 goto keep;
587587 if (PageDirty(page) || PageWriteback(page))
588588 goto keep_locked;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t