Lines Matching full:page
159 void release_pages(struct page **pages, int nr);
162 * speculatively take a reference to a page.
163 * If the page is free (_refcount == 0), then _refcount is untouched, and 0
167 * been used to lookup the page in the pagecache radix-tree (or page table):
173 * page has been finished with, no matter what it is subsequently allocated
180 * 1. find page in radix tree
182 * 3. check the page is still in pagecache (if no, goto 1)
187 * B. remove page from pagecache
188 * C. free the page
193 * subsequently, B will complete and 1 will find no page, causing the
196 * It is possible that between 1 and 2, the page is removed then the exact same
197 * page is inserted into the same position in pagecache. That's OK: the
202 * will find the page or it will not. Likewise, the old find_get_page could run
205 static inline int __page_cache_add_speculative(struct page *page, int count) in __page_cache_add_speculative() argument
216 * found a page in the radix tree here, we have pinned its refcount by in __page_cache_add_speculative()
220 VM_BUG_ON_PAGE(page_count(page) == 0, page); in __page_cache_add_speculative()
221 page_ref_add(page, count); in __page_cache_add_speculative()
224 if (unlikely(!page_ref_add_unless(page, count, 0))) { in __page_cache_add_speculative()
226 * Either the page has been freed, or will be freed. in __page_cache_add_speculative()
233 VM_BUG_ON_PAGE(PageTail(page), page); in __page_cache_add_speculative()
238 static inline int page_cache_get_speculative(struct page *page) in page_cache_get_speculative() argument
240 return __page_cache_add_speculative(page, 1); in page_cache_get_speculative()
243 static inline int page_cache_add_speculative(struct page *page, int count) in page_cache_add_speculative() argument
245 return __page_cache_add_speculative(page, count); in page_cache_add_speculative()
249 * attach_page_private - Attach private data to a page.
250 * @page: Page to attach data to.
251 * @data: Data to attach to page.
253 * Attaching private data to a page increments the page's reference count.
254 * The data must be detached before the page will be freed.
256 static inline void attach_page_private(struct page *page, void *data) in attach_page_private() argument
258 get_page(page); in attach_page_private()
259 set_page_private(page, (unsigned long)data); in attach_page_private()
260 SetPagePrivate(page); in attach_page_private()
264 * detach_page_private - Detach private data from a page.
265 * @page: Page to detach data from.
267 * Removes the data that was previously attached to the page and decrements
268 * the refcount on the page.
270 * Return: Data that was attached to the page.
272 static inline void *detach_page_private(struct page *page) in detach_page_private() argument
274 void *data = (void *)page_private(page); in detach_page_private()
276 if (!PagePrivate(page)) in detach_page_private()
278 ClearPagePrivate(page); in detach_page_private()
279 set_page_private(page, 0); in detach_page_private()
280 put_page(page); in detach_page_private()
286 extern struct page *__page_cache_alloc(gfp_t gfp);
288 static inline struct page *__page_cache_alloc(gfp_t gfp) in __page_cache_alloc()
294 static inline struct page *page_cache_alloc(struct address_space *x) in page_cache_alloc()
301 typedef int filler_t(void *, struct page *);
317 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
321 * find_get_page - find and get a page reference
323 * @offset: the page index
325 * Looks up the page cache slot at @mapping & @offset. If there is a
326 * page cache page, it is returned with an increased refcount.
330 static inline struct page *find_get_page(struct address_space *mapping, in find_get_page()
336 static inline struct page *find_get_page_flags(struct address_space *mapping, in find_get_page_flags()
343 * find_lock_page - locate, pin and lock a pagecache page
345 * @index: the page index
347 * Looks up the page cache entry at @mapping & @index. If there is a
348 * page cache page, it is returned locked and with an increased
352 * Return: A struct page or %NULL if there is no page in the cache for this
355 static inline struct page *find_lock_page(struct address_space *mapping, in find_lock_page()
362 * find_lock_head - Locate, pin and lock a pagecache page.
364 * @index: The page index.
366 * Looks up the page cache entry at @mapping & @index. If there is a
367 * page cache page, its head page is returned locked and with an increased
371 * Return: A struct page which is !PageTail, or %NULL if there is no page
374 static inline struct page *find_lock_head(struct address_space *mapping, in find_lock_head()
381 * find_or_create_page - locate or add a pagecache page
382 * @mapping: the page's address_space
383 * @index: the page's index into the mapping
384 * @gfp_mask: page allocation mode
386 * Looks up the page cache slot at @mapping & @offset. If there is a
387 * page cache page, it is returned locked and with an increased
390 * If the page is not present, a new page is allocated using @gfp_mask
391 * and added to the page cache and the VM's LRU list. The page is
399 static inline struct page *find_or_create_page(struct address_space *mapping, in find_or_create_page()
408 * grab_cache_page_nowait - returns locked page at given index in given cache
410 * @index: the page index
412 * Same as grab_cache_page(), but do not wait if the page is unavailable.
414 * be regenerated if the page couldn't be grabbed. This routine should
415 * be safe to call while holding the lock for another page.
417 * Clear __GFP_FS when allocating the page to avoid recursion into the fs
418 * and deadlock against the caller's locked page.
420 static inline struct page *grab_cache_page_nowait(struct address_space *mapping, in grab_cache_page_nowait()
428 /* Does this page contain this index? */
429 static inline bool thp_contains(struct page *head, pgoff_t index) in thp_contains()
431 /* HugeTLBfs indexes the page cache in units of hpage_size */ in thp_contains()
438 * Given the page we found in the page cache, return the page corresponding
441 static inline struct page *find_subpage(struct page *head, pgoff_t index) in find_subpage()
443 /* HugeTLBfs wants the head page regardless */ in find_subpage()
451 unsigned int nr_entries, struct page **entries,
455 struct page **pages);
458 struct page **pages) in find_get_pages()
464 unsigned int nr_pages, struct page **pages);
467 struct page **pages);
470 struct page **pages) in find_get_pages_tag()
476 struct page *grab_cache_page_write_begin(struct address_space *mapping,
480 * Returns locked page at given index in given cache, creating it if needed.
482 static inline struct page *grab_cache_page(struct address_space *mapping, in grab_cache_page()
488 extern struct page * read_cache_page(struct address_space *mapping,
490 extern struct page * read_cache_page_gfp(struct address_space *mapping,
495 static inline struct page *read_mapping_page(struct address_space *mapping, in read_mapping_page()
502 * Get index of the page within radix-tree (but not for hugetlb pages).
505 static inline pgoff_t page_to_index(struct page *page) in page_to_index() argument
509 if (likely(!PageTransTail(page))) in page_to_index()
510 return page->index; in page_to_index()
514 * head page in page_to_index()
516 pgoff = compound_head(page)->index; in page_to_index()
517 pgoff += page - compound_head(page); in page_to_index()
521 extern pgoff_t hugetlb_basepage_index(struct page *page);
527 static inline pgoff_t page_to_pgoff(struct page *page) in page_to_pgoff() argument
529 if (unlikely(PageHuge(page))) in page_to_pgoff()
530 return hugetlb_basepage_index(page); in page_to_pgoff()
531 return page_to_index(page); in page_to_pgoff()
535 * Return byte-offset into filesystem object for page.
537 static inline loff_t page_offset(struct page *page) in page_offset() argument
539 return ((loff_t)page->index) << PAGE_SHIFT; in page_offset()
542 static inline loff_t page_file_offset(struct page *page) in page_file_offset() argument
544 return ((loff_t)page_index(page)) << PAGE_SHIFT; in page_file_offset()
562 struct page *page; member
568 struct page *page; member
576 if (wait_page->page != key->page) in wake_page_match()
586 extern void __lock_page(struct page *page);
587 extern int __lock_page_killable(struct page *page);
588 extern int __lock_page_async(struct page *page, struct wait_page_queue *wait);
589 extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
591 extern void unlock_page(struct page *page);
594 * Return true if the page was successfully locked
596 static inline int trylock_page(struct page *page) in trylock_page() argument
598 page = compound_head(page); in trylock_page()
599 return (likely(!test_and_set_bit_lock(PG_locked, &page->flags))); in trylock_page()
603 * lock_page may only be called if we have the page's inode pinned.
605 static inline __sched void lock_page(struct page *page) in lock_page() argument
608 if (!trylock_page(page)) in lock_page()
609 __lock_page(page); in lock_page()
614 * signals. It returns 0 if it locked the page and -EINTR if it was
617 static inline __sched int lock_page_killable(struct page *page) in lock_page_killable() argument
620 if (!trylock_page(page)) in lock_page_killable()
621 return __lock_page_killable(page); in lock_page_killable()
626 * lock_page_async - Lock the page, unless this would block. If the page
627 * is already locked, then queue a callback when the page becomes unlocked.
630 * Returns 0 if the page is locked successfully, or -EIOCBQUEUED if the page
633 static inline __sched int lock_page_async(struct page *page, in lock_page_async() argument
636 if (!trylock_page(page)) in lock_page_async()
637 return __lock_page_async(page, wait); in lock_page_async()
642 * lock_page_or_retry - Lock the page, unless this would block and the
648 static inline __sched int lock_page_or_retry(struct page *page, struct mm_struct *mm, in lock_page_or_retry() argument
652 return trylock_page(page) || __lock_page_or_retry(page, mm, flags); in lock_page_or_retry()
659 extern void wait_on_page_bit(struct page *page, int bit_nr);
660 extern int wait_on_page_bit_killable(struct page *page, int bit_nr);
663 * Wait for a page to be unlocked.
665 * This must be called with the caller "holding" the page,
666 * ie with increased "page->count" so that the page won't
669 static inline __sched void wait_on_page_locked(struct page *page) in wait_on_page_locked() argument
671 if (PageLocked(page)) in wait_on_page_locked()
672 wait_on_page_bit(compound_head(page), PG_locked); in wait_on_page_locked()
675 static inline __sched int wait_on_page_locked_killable(struct page *page) in wait_on_page_locked_killable() argument
677 if (!PageLocked(page)) in wait_on_page_locked_killable()
679 return wait_on_page_bit_killable(compound_head(page), PG_locked); in wait_on_page_locked_killable()
682 extern void put_and_wait_on_page_locked(struct page *page);
684 void wait_on_page_writeback(struct page *page);
685 extern void end_page_writeback(struct page *page);
686 void wait_for_stable_page(struct page *page);
688 void page_endio(struct page *page, bool is_write, int err);
691 * Add an arbitrary waiter to a page's wait queue
693 extern void add_page_wait_queue(struct page *page, wait_queue_entry_t *waiter);
717 /* Check whether the range spilled into the next page. */ in fault_in_pages_writeable()
742 /* Check whether the range spilled into the next page. */ in fault_in_pages_readable()
752 int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
754 int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
756 extern void delete_from_page_cache(struct page *page);
757 extern void __delete_from_page_cache(struct page *page, void *shadow);
758 int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask);
764 * the page is new, so we can just run __SetPageLocked() against it.
766 static inline int add_to_page_cache(struct page *page, in add_to_page_cache() argument
771 __SetPageLocked(page); in add_to_page_cache()
772 error = add_to_page_cache_locked(page, mapping, offset, gfp_mask); in add_to_page_cache()
774 __ClearPageLocked(page); in add_to_page_cache()
784 * each page in the request.
816 struct page *, unsigned long req_count);
823 * @index: Index of first page to be read.
845 * @page: The page at @index which triggered the readahead call.
846 * @index: Index of first page to be read.
849 * page_cache_async_readahead() should be called when a page is used which
857 struct page *page, pgoff_t index, unsigned long req_count) in page_cache_async_readahead() argument
860 page_cache_async_ra(&ractl, ra, page, req_count); in page_cache_async_readahead()
864 * readahead_page - Get the next page to read.
867 * Context: The page is locked and has an elevated refcount. The caller
868 * should decreases the refcount once the page has been submitted for I/O
869 * and unlock the page once all I/O to that page has completed.
870 * Return: A pointer to the next page, or %NULL if we are done.
872 static inline struct page *readahead_page(struct readahead_control *rac) in readahead_page()
874 struct page *page; in readahead_page() local
885 page = xa_load(&rac->mapping->i_pages, rac->_index); in readahead_page()
886 VM_BUG_ON_PAGE(!PageLocked(page), page); in readahead_page()
887 rac->_batch_count = thp_nr_pages(page); in readahead_page()
889 return page; in readahead_page()
893 struct page **array, unsigned int array_sz) in __readahead_batch()
897 struct page *page; in __readahead_batch() local
906 xas_for_each(&xas, page, rac->_index + rac->_nr_pages - 1) { in __readahead_batch()
907 if (xas_retry(&xas, page)) in __readahead_batch()
909 VM_BUG_ON_PAGE(!PageLocked(page), page); in __readahead_batch()
910 VM_BUG_ON_PAGE(PageTail(page), page); in __readahead_batch()
911 array[i++] = page; in __readahead_batch()
912 rac->_batch_count += thp_nr_pages(page); in __readahead_batch()
915 * The page cache isn't using multi-index entries yet, in __readahead_batch()
917 * next index. This can be removed once the page cache in __readahead_batch()
920 if (PageHead(page)) in __readahead_batch()
934 * @array: An array of pointers to struct page.
937 * should decreases the refcount once the page has been submitted for I/O
938 * and unlock the page once all I/O to that page has completed.
964 * readahead_index - The index of the first page in this readahead request.
988 * page_mkwrite_check_truncate - check if page was truncated
989 * @page: the page to check
990 * @inode: the inode to check the page against
992 * Returns the number of bytes in the page up to EOF,
993 * or -EFAULT if the page was truncated.
995 static inline int page_mkwrite_check_truncate(struct page *page, in page_mkwrite_check_truncate() argument
1002 if (page->mapping != inode->i_mapping) in page_mkwrite_check_truncate()
1005 /* page is wholly inside EOF */ in page_mkwrite_check_truncate()
1006 if (page->index < index) in page_mkwrite_check_truncate()
1008 /* page is wholly past EOF */ in page_mkwrite_check_truncate()
1009 if (page->index > index || !offset) in page_mkwrite_check_truncate()
1011 /* page is partially inside EOF */ in page_mkwrite_check_truncate()
1016 * i_blocks_per_page - How many blocks fit in this page.
1018 * @page: The page (head page if the page is a THP).
1020 * If the block size is larger than the size of this page, return zero.
1022 * Context: The caller should hold a refcount on the page to prevent it
1024 * Return: The number of filesystem blocks covered by this page.
1027 unsigned int i_blocks_per_page(struct inode *inode, struct page *page) in i_blocks_per_page() argument
1029 return thp_size(page) >> inode->i_blkbits; in i_blocks_per_page()