Lines Matching full:page
163 void release_pages(struct page **pages, int nr);
168 static inline struct address_space *page_mapping_file(struct page *page) in page_mapping_file() argument
170 if (unlikely(PageSwapCache(page))) in page_mapping_file()
172 return page_mapping(page); in page_mapping_file()
176 * speculatively take a reference to a page.
177 * If the page is free (_refcount == 0), then _refcount is untouched, and 0
181 * been used to lookup the page in the pagecache radix-tree (or page table):
187 * page has been finished with, no matter what it is subsequently allocated
194 * 1. find page in radix tree
196 * 3. check the page is still in pagecache (if no, goto 1)
201 * B. remove page from pagecache
202 * C. free the page
207 * subsequently, B will complete and 1 will find no page, causing the
210 * It is possible that between 1 and 2, the page is removed then the exact same
211 * page is inserted into the same position in pagecache. That's OK: the
216 * will find the page or it will not. Likewise, the old find_get_page could run
219 static inline int __page_cache_add_speculative(struct page *page, int count) in __page_cache_add_speculative() argument
230 * found a page in the radix tree here, we have pinned its refcount by in __page_cache_add_speculative()
234 VM_BUG_ON_PAGE(page_count(page) == 0, page); in __page_cache_add_speculative()
235 page_ref_add(page, count); in __page_cache_add_speculative()
238 if (unlikely(!page_ref_add_unless(page, count, 0))) { in __page_cache_add_speculative()
240 * Either the page has been freed, or will be freed. in __page_cache_add_speculative()
247 VM_BUG_ON_PAGE(PageTail(page), page); in __page_cache_add_speculative()
252 static inline int page_cache_get_speculative(struct page *page) in page_cache_get_speculative() argument
254 return __page_cache_add_speculative(page, 1); in page_cache_get_speculative()
257 static inline int page_cache_add_speculative(struct page *page, int count) in page_cache_add_speculative() argument
259 return __page_cache_add_speculative(page, count); in page_cache_add_speculative()
263 * attach_page_private - Attach private data to a page.
264 * @page: Page to attach data to.
265 * @data: Data to attach to page.
267 * Attaching private data to a page increments the page's reference count.
268 * The data must be detached before the page will be freed.
270 static inline void attach_page_private(struct page *page, void *data) in attach_page_private() argument
272 get_page(page); in attach_page_private()
273 set_page_private(page, (unsigned long)data); in attach_page_private()
274 SetPagePrivate(page); in attach_page_private()
278 * detach_page_private - Detach private data from a page.
279 * @page: Page to detach data from.
281 * Removes the data that was previously attached to the page and decrements
282 * the refcount on the page.
284 * Return: Data that was attached to the page.
286 static inline void *detach_page_private(struct page *page) in detach_page_private() argument
288 void *data = (void *)page_private(page); in detach_page_private()
290 if (!PagePrivate(page)) in detach_page_private()
292 ClearPagePrivate(page); in detach_page_private()
293 set_page_private(page, 0); in detach_page_private()
294 put_page(page); in detach_page_private()
300 extern struct page *__page_cache_alloc(gfp_t gfp);
302 static inline struct page *__page_cache_alloc(gfp_t gfp) in __page_cache_alloc()
308 static inline struct page *page_cache_alloc(struct address_space *x) in page_cache_alloc()
318 typedef int filler_t(void *, struct page *);
335 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
339 * find_get_page - find and get a page reference
341 * @offset: the page index
343 * Looks up the page cache slot at @mapping & @offset. If there is a
344 * page cache page, it is returned with an increased refcount.
348 static inline struct page *find_get_page(struct address_space *mapping, in find_get_page()
354 static inline struct page *find_get_page_flags(struct address_space *mapping, in find_get_page_flags()
361 * find_lock_page - locate, pin and lock a pagecache page
363 * @index: the page index
365 * Looks up the page cache entry at @mapping & @index. If there is a
366 * page cache page, it is returned locked and with an increased
370 * Return: A struct page or %NULL if there is no page in the cache for this
373 static inline struct page *find_lock_page(struct address_space *mapping, in find_lock_page()
380 * find_lock_head - Locate, pin and lock a pagecache page.
382 * @index: The page index.
384 * Looks up the page cache entry at @mapping & @index. If there is a
385 * page cache page, its head page is returned locked and with an increased
389 * Return: A struct page which is !PageTail, or %NULL if there is no page
392 static inline struct page *find_lock_head(struct address_space *mapping, in find_lock_head()
399 * find_or_create_page - locate or add a pagecache page
400 * @mapping: the page's address_space
401 * @index: the page's index into the mapping
402 * @gfp_mask: page allocation mode
404 * Looks up the page cache slot at @mapping & @offset. If there is a
405 * page cache page, it is returned locked and with an increased
408 * If the page is not present, a new page is allocated using @gfp_mask
409 * and added to the page cache and the VM's LRU list. The page is
417 static inline struct page *find_or_create_page(struct address_space *mapping, in find_or_create_page()
426 * grab_cache_page_nowait - returns locked page at given index in given cache
428 * @index: the page index
430 * Same as grab_cache_page(), but do not wait if the page is unavailable.
432 * be regenerated if the page couldn't be grabbed. This routine should
433 * be safe to call while holding the lock for another page.
435 * Clear __GFP_FS when allocating the page to avoid recursion into the fs
436 * and deadlock against the caller's locked page.
438 static inline struct page *grab_cache_page_nowait(struct address_space *mapping, in grab_cache_page_nowait()
446 /* Does this page contain this index? */
447 static inline bool thp_contains(struct page *head, pgoff_t index) in thp_contains()
449 /* HugeTLBfs indexes the page cache in units of hpage_size */ in thp_contains()
456 * Given the page we found in the page cache, return the page corresponding
459 static inline struct page *find_subpage(struct page *head, pgoff_t index) in find_subpage()
461 /* HugeTLBfs wants the head page regardless */ in find_subpage()
472 struct page **pages);
475 struct page **pages) in find_get_pages()
481 unsigned int nr_pages, struct page **pages);
484 struct page **pages);
487 struct page **pages) in find_get_pages_tag()
493 struct page *grab_cache_page_write_begin(struct address_space *mapping,
497 * Returns locked page at given index in given cache, creating it if needed.
499 static inline struct page *grab_cache_page(struct address_space *mapping, in grab_cache_page()
505 extern struct page * read_cache_page(struct address_space *mapping,
507 extern struct page * read_cache_page_gfp(struct address_space *mapping,
512 static inline struct page *read_mapping_page(struct address_space *mapping, in read_mapping_page()
519 * Get index of the page within radix-tree (but not for hugetlb pages).
522 static inline pgoff_t page_to_index(struct page *page) in page_to_index() argument
524 struct page *head; in page_to_index()
526 if (likely(!PageTransTail(page))) in page_to_index()
527 return page->index; in page_to_index()
529 head = compound_head(page); in page_to_index()
532 * head page in page_to_index()
534 return head->index + page - head; in page_to_index()
537 extern pgoff_t hugetlb_basepage_index(struct page *page);
543 static inline pgoff_t page_to_pgoff(struct page *page) in page_to_pgoff() argument
545 if (unlikely(PageHuge(page))) in page_to_pgoff()
546 return hugetlb_basepage_index(page); in page_to_pgoff()
547 return page_to_index(page); in page_to_pgoff()
551 * Return byte-offset into filesystem object for page.
553 static inline loff_t page_offset(struct page *page) in page_offset() argument
555 return ((loff_t)page->index) << PAGE_SHIFT; in page_offset()
558 static inline loff_t page_file_offset(struct page *page) in page_file_offset() argument
560 return ((loff_t)page_index(page)) << PAGE_SHIFT; in page_file_offset()
578 struct page *page; member
584 struct page *page; member
592 if (wait_page->page != key->page) in wake_page_match()
602 extern void __lock_page(struct page *page);
603 extern int __lock_page_killable(struct page *page);
604 extern int __lock_page_async(struct page *page, struct wait_page_queue *wait);
605 extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
607 extern void unlock_page(struct page *page);
610 * Return true if the page was successfully locked
612 static inline int trylock_page(struct page *page) in trylock_page() argument
614 page = compound_head(page); in trylock_page()
615 return (likely(!test_and_set_bit_lock(PG_locked, &page->flags))); in trylock_page()
619 * lock_page may only be called if we have the page's inode pinned.
621 static inline void lock_page(struct page *page) in lock_page() argument
624 if (!trylock_page(page)) in lock_page()
625 __lock_page(page); in lock_page()
630 * signals. It returns 0 if it locked the page and -EINTR if it was
633 static inline int lock_page_killable(struct page *page) in lock_page_killable() argument
636 if (!trylock_page(page)) in lock_page_killable()
637 return __lock_page_killable(page); in lock_page_killable()
642 * lock_page_async - Lock the page, unless this would block. If the page
643 * is already locked, then queue a callback when the page becomes unlocked.
646 * Returns 0 if the page is locked successfully, or -EIOCBQUEUED if the page
649 static inline int lock_page_async(struct page *page, in lock_page_async() argument
652 if (!trylock_page(page)) in lock_page_async()
653 return __lock_page_async(page, wait); in lock_page_async()
658 * lock_page_or_retry - Lock the page, unless this would block and the
664 static inline int lock_page_or_retry(struct page *page, struct mm_struct *mm, in lock_page_or_retry() argument
668 return trylock_page(page) || __lock_page_or_retry(page, mm, flags); in lock_page_or_retry()
675 extern void wait_on_page_bit(struct page *page, int bit_nr);
676 extern int wait_on_page_bit_killable(struct page *page, int bit_nr);
679 * Wait for a page to be unlocked.
681 * This must be called with the caller "holding" the page,
682 * ie with increased "page->count" so that the page won't
685 static inline void wait_on_page_locked(struct page *page) in wait_on_page_locked() argument
687 if (PageLocked(page)) in wait_on_page_locked()
688 wait_on_page_bit(compound_head(page), PG_locked); in wait_on_page_locked()
691 static inline int wait_on_page_locked_killable(struct page *page) in wait_on_page_locked_killable() argument
693 if (!PageLocked(page)) in wait_on_page_locked_killable()
695 return wait_on_page_bit_killable(compound_head(page), PG_locked); in wait_on_page_locked_killable()
698 int put_and_wait_on_page_locked(struct page *page, int state);
699 void wait_on_page_writeback(struct page *page);
700 int wait_on_page_writeback_killable(struct page *page);
701 extern void end_page_writeback(struct page *page);
702 void wait_for_stable_page(struct page *page);
704 void __set_page_dirty(struct page *, struct address_space *, int warn);
705 int __set_page_dirty_nobuffers(struct page *page);
706 int __set_page_dirty_no_writeback(struct page *page);
708 void page_endio(struct page *page, bool is_write, int err);
711 * set_page_private_2 - Set PG_private_2 on a page and take a ref
712 * @page: The page.
714 * Set the PG_private_2 flag on a page and take the reference needed for the VM
719 static inline void set_page_private_2(struct page *page) in set_page_private_2() argument
721 page = compound_head(page); in set_page_private_2()
722 get_page(page); in set_page_private_2()
723 SetPagePrivate2(page); in set_page_private_2()
726 void end_page_private_2(struct page *page);
727 void wait_on_page_private_2(struct page *page);
728 int wait_on_page_private_2_killable(struct page *page);
731 * Add an arbitrary waiter to a page's wait queue
733 extern void add_page_wait_queue(struct page *page, wait_queue_entry_t *waiter);
757 /* Check whether the range spilled into the next page. */ in fault_in_pages_writeable()
782 /* Check whether the range spilled into the next page. */ in fault_in_pages_readable()
792 int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
794 int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
796 extern void delete_from_page_cache(struct page *page);
797 extern void __delete_from_page_cache(struct page *page, void *shadow);
798 void replace_page_cache_page(struct page *old, struct page *new);
806 * the page is new, so we can just run __SetPageLocked() against it.
808 static inline int add_to_page_cache(struct page *page, in add_to_page_cache() argument
813 __SetPageLocked(page); in add_to_page_cache()
814 error = add_to_page_cache_locked(page, mapping, offset, gfp_mask); in add_to_page_cache()
816 __ClearPageLocked(page); in add_to_page_cache()
826 * each page in the request.
859 void page_cache_async_ra(struct readahead_control *, struct page *,
869 * @index: Index of first page to be read.
891 * @page: The page at @index which triggered the readahead call.
892 * @index: Index of first page to be read.
895 * page_cache_async_readahead() should be called when a page is used which
903 struct page *page, pgoff_t index, unsigned long req_count) in page_cache_async_readahead() argument
906 page_cache_async_ra(&ractl, page, req_count); in page_cache_async_readahead()
910 * readahead_page - Get the next page to read.
913 * Context: The page is locked and has an elevated refcount. The caller
914 * should decreases the refcount once the page has been submitted for I/O
915 * and unlock the page once all I/O to that page has completed.
916 * Return: A pointer to the next page, or %NULL if we are done.
918 static inline struct page *readahead_page(struct readahead_control *rac) in readahead_page()
920 struct page *page; in readahead_page() local
931 page = xa_load(&rac->mapping->i_pages, rac->_index); in readahead_page()
932 VM_BUG_ON_PAGE(!PageLocked(page), page); in readahead_page()
933 rac->_batch_count = thp_nr_pages(page); in readahead_page()
935 return page; in readahead_page()
939 struct page **array, unsigned int array_sz) in __readahead_batch()
943 struct page *page; in __readahead_batch() local
952 xas_for_each(&xas, page, rac->_index + rac->_nr_pages - 1) { in __readahead_batch()
953 if (xas_retry(&xas, page)) in __readahead_batch()
955 VM_BUG_ON_PAGE(!PageLocked(page), page); in __readahead_batch()
956 VM_BUG_ON_PAGE(PageTail(page), page); in __readahead_batch()
957 array[i++] = page; in __readahead_batch()
958 rac->_batch_count += thp_nr_pages(page); in __readahead_batch()
961 * The page cache isn't using multi-index entries yet, in __readahead_batch()
963 * next index. This can be removed once the page cache in __readahead_batch()
966 if (PageHead(page)) in __readahead_batch()
980 * @array: An array of pointers to struct page.
983 * should decreases the refcount once the page has been submitted for I/O
984 * and unlock the page once all I/O to that page has completed.
1010 * readahead_index - The index of the first page in this readahead request.
1043 * page_mkwrite_check_truncate - check if page was truncated
1044 * @page: the page to check
1045 * @inode: the inode to check the page against
1047 * Returns the number of bytes in the page up to EOF,
1048 * or -EFAULT if the page was truncated.
1050 static inline int page_mkwrite_check_truncate(struct page *page, in page_mkwrite_check_truncate() argument
1057 if (page->mapping != inode->i_mapping) in page_mkwrite_check_truncate()
1060 /* page is wholly inside EOF */ in page_mkwrite_check_truncate()
1061 if (page->index < index) in page_mkwrite_check_truncate()
1063 /* page is wholly past EOF */ in page_mkwrite_check_truncate()
1064 if (page->index > index || !offset) in page_mkwrite_check_truncate()
1066 /* page is partially inside EOF */ in page_mkwrite_check_truncate()
1071 * i_blocks_per_page - How many blocks fit in this page.
1073 * @page: The page (head page if the page is a THP).
1075 * If the block size is larger than the size of this page, return zero.
1077 * Context: The caller should hold a refcount on the page to prevent it
1079 * Return: The number of filesystem blocks covered by this page.
1082 unsigned int i_blocks_per_page(struct inode *inode, struct page *page) in i_blocks_per_page() argument
1084 return thp_size(page) >> inode->i_blkbits; in i_blocks_per_page()