Lines Matching full:page
158 void release_pages(struct page **pages, int nr);
161 * speculatively take a reference to a page.
162 * If the page is free (_refcount == 0), then _refcount is untouched, and 0
166 * been used to lookup the page in the pagecache radix-tree (or page table):
172 * page has been finished with, no matter what it is subsequently allocated
179 * 1. find page in radix tree
181 * 3. check the page is still in pagecache (if no, goto 1)
186 * B. remove page from pagecache
187 * C. free the page
192 * subsequently, B will complete and 1 will find no page, causing the
195 * It is possible that between 1 and 2, the page is removed then the exact same
196 * page is inserted into the same position in pagecache. That's OK: the
201 * will find the page or it will not. Likewise, the old find_get_page could run
204 static inline int __page_cache_add_speculative(struct page *page, int count) in __page_cache_add_speculative() argument
215 * found a page in the radix tree here, we have pinned its refcount by in __page_cache_add_speculative()
219 VM_BUG_ON_PAGE(page_count(page) == 0, page); in __page_cache_add_speculative()
220 page_ref_add(page, count); in __page_cache_add_speculative()
223 if (unlikely(!page_ref_add_unless(page, count, 0))) { in __page_cache_add_speculative()
225 * Either the page has been freed, or will be freed. in __page_cache_add_speculative()
232 VM_BUG_ON_PAGE(PageTail(page), page); in __page_cache_add_speculative()
237 static inline int page_cache_get_speculative(struct page *page) in page_cache_get_speculative() argument
239 return __page_cache_add_speculative(page, 1); in page_cache_get_speculative()
242 static inline int page_cache_add_speculative(struct page *page, int count) in page_cache_add_speculative() argument
244 return __page_cache_add_speculative(page, count); in page_cache_add_speculative()
248 * attach_page_private - Attach private data to a page.
249 * @page: Page to attach data to.
250 * @data: Data to attach to page.
252 * Attaching private data to a page increments the page's reference count.
253 * The data must be detached before the page will be freed.
255 static inline void attach_page_private(struct page *page, void *data) in attach_page_private() argument
257 get_page(page); in attach_page_private()
258 set_page_private(page, (unsigned long)data); in attach_page_private()
259 SetPagePrivate(page); in attach_page_private()
263 * detach_page_private - Detach private data from a page.
264 * @page: Page to detach data from.
266 * Removes the data that was previously attached to the page and decrements
267 * the refcount on the page.
269 * Return: Data that was attached to the page.
271 static inline void *detach_page_private(struct page *page) in detach_page_private() argument
273 void *data = (void *)page_private(page); in detach_page_private()
275 if (!PagePrivate(page)) in detach_page_private()
277 ClearPagePrivate(page); in detach_page_private()
278 set_page_private(page, 0); in detach_page_private()
279 put_page(page); in detach_page_private()
285 extern struct page *__page_cache_alloc(gfp_t gfp);
287 static inline struct page *__page_cache_alloc(gfp_t gfp) in __page_cache_alloc()
293 static inline struct page *page_cache_alloc(struct address_space *x) in page_cache_alloc()
303 typedef int filler_t(void *, struct page *);
319 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
323 * find_get_page - find and get a page reference
325 * @offset: the page index
327 * Looks up the page cache slot at @mapping & @offset. If there is a
328 * page cache page, it is returned with an increased refcount.
332 static inline struct page *find_get_page(struct address_space *mapping, in find_get_page()
338 static inline struct page *find_get_page_flags(struct address_space *mapping, in find_get_page_flags()
345 * find_lock_page - locate, pin and lock a pagecache page
347 * @index: the page index
349 * Looks up the page cache entry at @mapping & @index. If there is a
350 * page cache page, it is returned locked and with an increased
354 * Return: A struct page or %NULL if there is no page in the cache for this
357 static inline struct page *find_lock_page(struct address_space *mapping, in find_lock_page()
364 * find_lock_head - Locate, pin and lock a pagecache page.
366 * @index: The page index.
368 * Looks up the page cache entry at @mapping & @index. If there is a
369 * page cache page, its head page is returned locked and with an increased
373 * Return: A struct page which is !PageTail, or %NULL if there is no page
376 static inline struct page *find_lock_head(struct address_space *mapping, in find_lock_head()
383 * find_or_create_page - locate or add a pagecache page
384 * @mapping: the page's address_space
385 * @index: the page's index into the mapping
386 * @gfp_mask: page allocation mode
388 * Looks up the page cache slot at @mapping & @offset. If there is a
389 * page cache page, it is returned locked and with an increased
392 * If the page is not present, a new page is allocated using @gfp_mask
393 * and added to the page cache and the VM's LRU list. The page is
401 static inline struct page *find_or_create_page(struct address_space *mapping, in find_or_create_page()
410 * grab_cache_page_nowait - returns locked page at given index in given cache
412 * @index: the page index
414 * Same as grab_cache_page(), but do not wait if the page is unavailable.
416 * be regenerated if the page couldn't be grabbed. This routine should
417 * be safe to call while holding the lock for another page.
419 * Clear __GFP_FS when allocating the page to avoid recursion into the fs
420 * and deadlock against the caller's locked page.
422 static inline struct page *grab_cache_page_nowait(struct address_space *mapping, in grab_cache_page_nowait()
430 /* Does this page contain this index? */
431 static inline bool thp_contains(struct page *head, pgoff_t index) in thp_contains()
433 /* HugeTLBfs indexes the page cache in units of hpage_size */ in thp_contains()
440 * Given the page we found in the page cache, return the page corresponding
443 static inline struct page *find_subpage(struct page *head, pgoff_t index) in find_subpage()
445 /* HugeTLBfs wants the head page regardless */ in find_subpage()
453 unsigned int nr_entries, struct page **entries,
457 struct page **pages);
460 struct page **pages) in find_get_pages()
466 unsigned int nr_pages, struct page **pages);
469 struct page **pages);
472 struct page **pages) in find_get_pages_tag()
478 struct page *grab_cache_page_write_begin(struct address_space *mapping,
482 * Returns locked page at given index in given cache, creating it if needed.
484 static inline struct page *grab_cache_page(struct address_space *mapping, in grab_cache_page()
490 extern struct page * read_cache_page(struct address_space *mapping,
492 extern struct page * read_cache_page_gfp(struct address_space *mapping,
497 static inline struct page *read_mapping_page(struct address_space *mapping, in read_mapping_page()
504 * Get index of the page with in radix-tree
507 static inline pgoff_t page_to_index(struct page *page) in page_to_index() argument
511 if (likely(!PageTransTail(page))) in page_to_index()
512 return page->index; in page_to_index()
516 * head page in page_to_index()
518 pgoff = compound_head(page)->index; in page_to_index()
519 pgoff += page - compound_head(page); in page_to_index()
527 static inline pgoff_t page_to_pgoff(struct page *page) in page_to_pgoff() argument
529 if (unlikely(PageHeadHuge(page))) in page_to_pgoff()
530 return page->index << compound_order(page); in page_to_pgoff()
532 return page_to_index(page); in page_to_pgoff()
536 * Return byte-offset into filesystem object for page.
538 static inline loff_t page_offset(struct page *page) in page_offset() argument
540 return ((loff_t)page->index) << PAGE_SHIFT; in page_offset()
543 static inline loff_t page_file_offset(struct page *page) in page_file_offset() argument
545 return ((loff_t)page_index(page)) << PAGE_SHIFT; in page_file_offset()
564 struct page *page; member
570 struct page *page; member
578 if (wait_page->page != key->page) in wake_page_match()
588 extern void __lock_page(struct page *page);
589 extern int __lock_page_killable(struct page *page);
590 extern int __lock_page_async(struct page *page, struct wait_page_queue *wait);
591 extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
593 extern void unlock_page(struct page *page);
596 * Return true if the page was successfully locked
598 static inline int trylock_page(struct page *page) in trylock_page() argument
600 page = compound_head(page); in trylock_page()
601 return (likely(!test_and_set_bit_lock(PG_locked, &page->flags))); in trylock_page()
605 * lock_page may only be called if we have the page's inode pinned.
607 static inline void lock_page(struct page *page) in lock_page() argument
610 if (!trylock_page(page)) in lock_page()
611 __lock_page(page); in lock_page()
616 * signals. It returns 0 if it locked the page and -EINTR if it was
619 static inline int lock_page_killable(struct page *page) in lock_page_killable() argument
622 if (!trylock_page(page)) in lock_page_killable()
623 return __lock_page_killable(page); in lock_page_killable()
628 * lock_page_async - Lock the page, unless this would block. If the page
629 * is already locked, then queue a callback when the page becomes unlocked.
632 * Returns 0 if the page is locked successfully, or -EIOCBQUEUED if the page
635 static inline int lock_page_async(struct page *page, in lock_page_async() argument
638 if (!trylock_page(page)) in lock_page_async()
639 return __lock_page_async(page, wait); in lock_page_async()
644 * lock_page_or_retry - Lock the page, unless this would block and the
650 static inline int lock_page_or_retry(struct page *page, struct mm_struct *mm, in lock_page_or_retry() argument
654 return trylock_page(page) || __lock_page_or_retry(page, mm, flags); in lock_page_or_retry()
661 extern void wait_on_page_bit(struct page *page, int bit_nr);
662 extern int wait_on_page_bit_killable(struct page *page, int bit_nr);
665 * Wait for a page to be unlocked.
667 * This must be called with the caller "holding" the page,
668 * ie with increased "page->count" so that the page won't
671 static inline void wait_on_page_locked(struct page *page) in wait_on_page_locked() argument
673 if (PageLocked(page)) in wait_on_page_locked()
674 wait_on_page_bit(compound_head(page), PG_locked); in wait_on_page_locked()
677 static inline int wait_on_page_locked_killable(struct page *page) in wait_on_page_locked_killable() argument
679 if (!PageLocked(page)) in wait_on_page_locked_killable()
681 return wait_on_page_bit_killable(compound_head(page), PG_locked); in wait_on_page_locked_killable()
684 extern void put_and_wait_on_page_locked(struct page *page);
686 void wait_on_page_writeback(struct page *page);
687 extern void end_page_writeback(struct page *page);
688 void wait_for_stable_page(struct page *page);
690 void page_endio(struct page *page, bool is_write, int err);
693 * Add an arbitrary waiter to a page's wait queue
695 extern void add_page_wait_queue(struct page *page, wait_queue_entry_t *waiter);
719 /* Check whether the range spilled into the next page. */ in fault_in_pages_writeable()
744 /* Check whether the range spilled into the next page. */ in fault_in_pages_readable()
754 int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
756 int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
758 extern void delete_from_page_cache(struct page *page);
759 extern void __delete_from_page_cache(struct page *page, void *shadow);
760 int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask);
766 * the page is new, so we can just run __SetPageLocked() against it.
768 static inline int add_to_page_cache(struct page *page, in add_to_page_cache() argument
773 __SetPageLocked(page); in add_to_page_cache()
774 error = add_to_page_cache_locked(page, mapping, offset, gfp_mask); in add_to_page_cache()
776 __ClearPageLocked(page); in add_to_page_cache()
786 * each page in the request.
818 struct page *, unsigned long req_count);
825 * @index: Index of first page to be read.
847 * @page: The page at @index which triggered the readahead call.
848 * @index: Index of first page to be read.
851 * page_cache_async_readahead() should be called when a page is used which
859 struct page *page, pgoff_t index, unsigned long req_count) in page_cache_async_readahead() argument
862 page_cache_async_ra(&ractl, ra, page, req_count); in page_cache_async_readahead()
866 * readahead_page - Get the next page to read.
869 * Context: The page is locked and has an elevated refcount. The caller
870 * should decreases the refcount once the page has been submitted for I/O
871 * and unlock the page once all I/O to that page has completed.
872 * Return: A pointer to the next page, or %NULL if we are done.
874 static inline struct page *readahead_page(struct readahead_control *rac) in readahead_page()
876 struct page *page; in readahead_page() local
887 page = xa_load(&rac->mapping->i_pages, rac->_index); in readahead_page()
888 VM_BUG_ON_PAGE(!PageLocked(page), page); in readahead_page()
889 rac->_batch_count = thp_nr_pages(page); in readahead_page()
891 return page; in readahead_page()
895 struct page **array, unsigned int array_sz) in __readahead_batch()
899 struct page *page; in __readahead_batch() local
908 xas_for_each(&xas, page, rac->_index + rac->_nr_pages - 1) { in __readahead_batch()
909 if (xas_retry(&xas, page)) in __readahead_batch()
911 VM_BUG_ON_PAGE(!PageLocked(page), page); in __readahead_batch()
912 VM_BUG_ON_PAGE(PageTail(page), page); in __readahead_batch()
913 array[i++] = page; in __readahead_batch()
914 rac->_batch_count += thp_nr_pages(page); in __readahead_batch()
917 * The page cache isn't using multi-index entries yet, in __readahead_batch()
919 * next index. This can be removed once the page cache in __readahead_batch()
922 if (PageHead(page)) in __readahead_batch()
936 * @array: An array of pointers to struct page.
939 * should decreases the refcount once the page has been submitted for I/O
940 * and unlock the page once all I/O to that page has completed.
966 * readahead_index - The index of the first page in this readahead request.
990 * page_mkwrite_check_truncate - check if page was truncated
991 * @page: the page to check
992 * @inode: the inode to check the page against
994 * Returns the number of bytes in the page up to EOF,
995 * or -EFAULT if the page was truncated.
997 static inline int page_mkwrite_check_truncate(struct page *page, in page_mkwrite_check_truncate() argument
1004 if (page->mapping != inode->i_mapping) in page_mkwrite_check_truncate()
1007 /* page is wholly inside EOF */ in page_mkwrite_check_truncate()
1008 if (page->index < index) in page_mkwrite_check_truncate()
1010 /* page is wholly past EOF */ in page_mkwrite_check_truncate()
1011 if (page->index > index || !offset) in page_mkwrite_check_truncate()
1013 /* page is partially inside EOF */ in page_mkwrite_check_truncate()
1018 * i_blocks_per_page - How many blocks fit in this page.
1020 * @page: The page (head page if the page is a THP).
1022 * If the block size is larger than the size of this page, return zero.
1024 * Context: The caller should hold a refcount on the page to prevent it
1026 * Return: The number of filesystem blocks covered by this page.
1029 unsigned int i_blocks_per_page(struct inode *inode, struct page *page) in i_blocks_per_page() argument
1031 return thp_size(page) >> inode->i_blkbits; in i_blocks_per_page()