filemap.c (c7bad633e6b749b2d64e2421cc9d4ee0d1540a8a) | filemap.c (41139aa4c3a31ee7e072fc63353c74035aade2ff) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * linux/mm/filemap.c 4 * 5 * Copyright (C) 1994-1999 Linus Torvalds 6 */ 7 8/* --- 2539 unchanged lines hidden (view full) --- 2548 IS_DAX(inode)) 2549 return retval; 2550 } 2551 2552 return filemap_read(iocb, iter, retval); 2553} 2554EXPORT_SYMBOL(generic_file_read_iter); 2555 | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * linux/mm/filemap.c 4 * 5 * Copyright (C) 1994-1999 Linus Torvalds 6 */ 7 8/* --- 2539 unchanged lines hidden (view full) --- 2548 IS_DAX(inode)) 2549 return retval; 2550 } 2551 2552 return filemap_read(iocb, iter, retval); 2553} 2554EXPORT_SYMBOL(generic_file_read_iter); 2555 |
2556static inline bool page_seek_match(struct page *page, bool seek_data) 2557{ 2558 if (xa_is_value(page) || PageUptodate(page)) 2559 return seek_data; 2560 return !seek_data; 2561} 2562 2563static inline 2564unsigned int seek_page_size(struct xa_state *xas, struct page *page) 2565{ 2566 if (xa_is_value(page)) 2567 return PAGE_SIZE << xa_get_order(xas->xa, xas->xa_index); 2568 return thp_size(page); 2569} 2570 2571/** 2572 * mapping_seek_hole_data - Seek for SEEK_DATA / SEEK_HOLE in the page cache. 2573 * @mapping: Address space to search. 2574 * @start: First byte to consider. 2575 * @end: Limit of search (exclusive). 2576 * @whence: Either SEEK_HOLE or SEEK_DATA. 2577 * 2578 * If the page cache knows which blocks contain holes and which blocks 2579 * contain data, your filesystem can use this function to implement 2580 * SEEK_HOLE and SEEK_DATA. This is useful for filesystems which are 2581 * entirely memory-based such as tmpfs, and filesystems which support 2582 * unwritten extents. 2583 * 2584 * Return: The requested offset on successs, or -ENXIO if @whence specifies 2585 * SEEK_DATA and there is no data after @start. There is an implicit hole 2586 * after @end - 1, so SEEK_HOLE returns @end if all the bytes between @start 2587 * and @end contain data. 2588 */ 2589loff_t mapping_seek_hole_data(struct address_space *mapping, loff_t start, 2590 loff_t end, int whence) 2591{ 2592 XA_STATE(xas, &mapping->i_pages, start >> PAGE_SHIFT); 2593 pgoff_t max = (end - 1) / PAGE_SIZE; 2594 bool seek_data = (whence == SEEK_DATA); 2595 struct page *page; 2596 2597 if (end <= start) 2598 return -ENXIO; 2599 2600 rcu_read_lock(); 2601 while ((page = find_get_entry(&xas, max, XA_PRESENT))) { 2602 loff_t pos = xas.xa_index * PAGE_SIZE; 2603 2604 if (start < pos) { 2605 if (!seek_data) 2606 goto unlock; 2607 start = pos; 2608 } 2609 2610 if (page_seek_match(page, seek_data)) 2611 goto unlock; 2612 start = pos + seek_page_size(&xas, page); 2613 if (!xa_is_value(page)) 2614 put_page(page); 2615 } 2616 rcu_read_unlock(); 2617 2618 if (seek_data) 2619 return -ENXIO; 2620 goto out; 2621 2622unlock: 2623 rcu_read_unlock(); 2624 if (!xa_is_value(page)) 2625 put_page(page); 2626out: 2627 if (start > end) 2628 return end; 2629 return start; 2630} 2631 |
|
2556#ifdef CONFIG_MMU 2557#define MMAP_LOTSAMISS (100) 2558/* 2559 * lock_page_maybe_drop_mmap - lock the page, possibly dropping the mmap_lock 2560 * @vmf - the vm_fault for this fault. 2561 * @page - the page to lock. 2562 * @fpin - the pointer to the file we may pin (or is already pinned). 2563 * --- 1052 unchanged lines hidden --- | 2632#ifdef CONFIG_MMU 2633#define MMAP_LOTSAMISS (100) 2634/* 2635 * lock_page_maybe_drop_mmap - lock the page, possibly dropping the mmap_lock 2636 * @vmf - the vm_fault for this fault. 2637 * @page - the page to lock. 2638 * @fpin - the pointer to the file we may pin (or is already pinned). 2639 * --- 1052 unchanged lines hidden --- |