11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * mm/truncate.c - code for taking down pages from address_spaces 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 2002, Linus Torvalds 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * 10Sep2002 akpm@zip.com.au 71da177e4SLinus Torvalds * Initial version. 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds #include <linux/kernel.h> 111da177e4SLinus Torvalds #include <linux/mm.h> 120fd0e6b0SNick Piggin #include <linux/swap.h> 131da177e4SLinus Torvalds #include <linux/module.h> 141da177e4SLinus Torvalds #include <linux/pagemap.h> 151da177e4SLinus Torvalds #include <linux/pagevec.h> 161da177e4SLinus Torvalds #include <linux/buffer_head.h> /* grr. try_to_release_page, 17aaa4059bSJan Kara do_invalidatepage */ 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds 20cf9a2ae8SDavid Howells /** 21cf9a2ae8SDavid Howells * do_invalidatepage - invalidate part of all of a page 22cf9a2ae8SDavid Howells * @page: the page which is affected 23cf9a2ae8SDavid Howells * @offset: the index of the truncation point 24cf9a2ae8SDavid Howells * 25cf9a2ae8SDavid Howells * do_invalidatepage() is called when all or part of the page has become 26cf9a2ae8SDavid Howells * invalidated by a truncate operation. 27cf9a2ae8SDavid Howells * 28cf9a2ae8SDavid Howells * do_invalidatepage() does not have to release all buffers, but it must 29cf9a2ae8SDavid Howells * ensure that no dirty buffer is left outside @offset and that no I/O 30cf9a2ae8SDavid Howells * is underway against any of the blocks which are outside the truncation 31cf9a2ae8SDavid Howells * point. Because the caller is about to free (and possibly reuse) those 32cf9a2ae8SDavid Howells * blocks on-disk. 33cf9a2ae8SDavid Howells */ 34cf9a2ae8SDavid Howells void do_invalidatepage(struct page *page, unsigned long offset) 35cf9a2ae8SDavid Howells { 36cf9a2ae8SDavid Howells void (*invalidatepage)(struct page *, unsigned long); 37cf9a2ae8SDavid Howells invalidatepage = page->mapping->a_ops->invalidatepage; 389361401eSDavid Howells #ifdef CONFIG_BLOCK 39cf9a2ae8SDavid Howells if (!invalidatepage) 40cf9a2ae8SDavid Howells invalidatepage = block_invalidatepage; 419361401eSDavid Howells #endif 42cf9a2ae8SDavid Howells if (invalidatepage) 43cf9a2ae8SDavid Howells (*invalidatepage)(page, offset); 44cf9a2ae8SDavid Howells } 45cf9a2ae8SDavid Howells 461da177e4SLinus Torvalds static inline void truncate_partial_page(struct page *page, unsigned partial) 471da177e4SLinus Torvalds { 481da177e4SLinus Torvalds memclear_highpage_flush(page, partial, PAGE_CACHE_SIZE-partial); 491da177e4SLinus Torvalds if (PagePrivate(page)) 501da177e4SLinus Torvalds do_invalidatepage(page, partial); 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* 541da177e4SLinus Torvalds * If truncate cannot remove the fs-private metadata from the page, the page 551da177e4SLinus Torvalds * becomes anonymous. It will be left on the LRU and may even be mapped into 561da177e4SLinus Torvalds * user pagetables if we're racing with filemap_nopage(). 571da177e4SLinus Torvalds * 581da177e4SLinus Torvalds * We need to bale out if page->mapping is no longer equal to the original 591da177e4SLinus Torvalds * mapping. This happens a) when the VM reclaimed the page while we waited on 601da177e4SLinus Torvalds * its lock, b) when a concurrent invalidate_inode_pages got there first and 611da177e4SLinus Torvalds * c) when tmpfs swizzles a page between a tmpfs inode and swapper_space. 621da177e4SLinus Torvalds */ 631da177e4SLinus Torvalds static void 641da177e4SLinus Torvalds truncate_complete_page(struct address_space *mapping, struct page *page) 651da177e4SLinus Torvalds { 661da177e4SLinus Torvalds if (page->mapping != mapping) 671da177e4SLinus Torvalds return; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds if (PagePrivate(page)) 701da177e4SLinus Torvalds do_invalidatepage(page, 0); 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds clear_page_dirty(page); 731da177e4SLinus Torvalds ClearPageUptodate(page); 741da177e4SLinus Torvalds ClearPageMappedToDisk(page); 751da177e4SLinus Torvalds remove_from_page_cache(page); 761da177e4SLinus Torvalds page_cache_release(page); /* pagecache ref */ 771da177e4SLinus Torvalds } 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* 801da177e4SLinus Torvalds * This is for invalidate_inode_pages(). That function can be called at 811da177e4SLinus Torvalds * any time, and is not supposed to throw away dirty pages. But pages can 820fd0e6b0SNick Piggin * be marked dirty at any time too, so use remove_mapping which safely 830fd0e6b0SNick Piggin * discards clean, unused pages. 841da177e4SLinus Torvalds * 851da177e4SLinus Torvalds * Returns non-zero if the page was successfully invalidated. 861da177e4SLinus Torvalds */ 871da177e4SLinus Torvalds static int 881da177e4SLinus Torvalds invalidate_complete_page(struct address_space *mapping, struct page *page) 891da177e4SLinus Torvalds { 900fd0e6b0SNick Piggin int ret; 910fd0e6b0SNick Piggin 921da177e4SLinus Torvalds if (page->mapping != mapping) 931da177e4SLinus Torvalds return 0; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds if (PagePrivate(page) && !try_to_release_page(page, 0)) 961da177e4SLinus Torvalds return 0; 971da177e4SLinus Torvalds 980fd0e6b0SNick Piggin ret = remove_mapping(mapping, page); 991da177e4SLinus Torvalds ClearPageUptodate(page); 1000fd0e6b0SNick Piggin 1010fd0e6b0SNick Piggin return ret; 1021da177e4SLinus Torvalds } 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds /** 105d7339071SHans Reiser * truncate_inode_pages - truncate range of pages specified by start and 106d7339071SHans Reiser * end byte offsets 1071da177e4SLinus Torvalds * @mapping: mapping to truncate 1081da177e4SLinus Torvalds * @lstart: offset from which to truncate 109d7339071SHans Reiser * @lend: offset to which to truncate 1101da177e4SLinus Torvalds * 111d7339071SHans Reiser * Truncate the page cache, removing the pages that are between 112d7339071SHans Reiser * specified offsets (and zeroing out partial page 113d7339071SHans Reiser * (if lstart is not page aligned)). 1141da177e4SLinus Torvalds * 1151da177e4SLinus Torvalds * Truncate takes two passes - the first pass is nonblocking. It will not 1161da177e4SLinus Torvalds * block on page locks and it will not block on writeback. The second pass 1171da177e4SLinus Torvalds * will wait. This is to prevent as much IO as possible in the affected region. 1181da177e4SLinus Torvalds * The first pass will remove most pages, so the search cost of the second pass 1191da177e4SLinus Torvalds * is low. 1201da177e4SLinus Torvalds * 1211da177e4SLinus Torvalds * When looking at page->index outside the page lock we need to be careful to 1221da177e4SLinus Torvalds * copy it into a local to avoid races (it could change at any time). 1231da177e4SLinus Torvalds * 1241da177e4SLinus Torvalds * We pass down the cache-hot hint to the page freeing code. Even if the 1251da177e4SLinus Torvalds * mapping is large, it is probably the case that the final pages are the most 1261da177e4SLinus Torvalds * recently touched, and freeing happens in ascending file offset order. 1271da177e4SLinus Torvalds */ 128d7339071SHans Reiser void truncate_inode_pages_range(struct address_space *mapping, 129d7339071SHans Reiser loff_t lstart, loff_t lend) 1301da177e4SLinus Torvalds { 1311da177e4SLinus Torvalds const pgoff_t start = (lstart + PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT; 132d7339071SHans Reiser pgoff_t end; 1331da177e4SLinus Torvalds const unsigned partial = lstart & (PAGE_CACHE_SIZE - 1); 1341da177e4SLinus Torvalds struct pagevec pvec; 1351da177e4SLinus Torvalds pgoff_t next; 1361da177e4SLinus Torvalds int i; 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds if (mapping->nrpages == 0) 1391da177e4SLinus Torvalds return; 1401da177e4SLinus Torvalds 141d7339071SHans Reiser BUG_ON((lend & (PAGE_CACHE_SIZE - 1)) != (PAGE_CACHE_SIZE - 1)); 142d7339071SHans Reiser end = (lend >> PAGE_CACHE_SHIFT); 143d7339071SHans Reiser 1441da177e4SLinus Torvalds pagevec_init(&pvec, 0); 1451da177e4SLinus Torvalds next = start; 146d7339071SHans Reiser while (next <= end && 147d7339071SHans Reiser pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) { 1481da177e4SLinus Torvalds for (i = 0; i < pagevec_count(&pvec); i++) { 1491da177e4SLinus Torvalds struct page *page = pvec.pages[i]; 1501da177e4SLinus Torvalds pgoff_t page_index = page->index; 1511da177e4SLinus Torvalds 152d7339071SHans Reiser if (page_index > end) { 153d7339071SHans Reiser next = page_index; 154d7339071SHans Reiser break; 155d7339071SHans Reiser } 156d7339071SHans Reiser 1571da177e4SLinus Torvalds if (page_index > next) 1581da177e4SLinus Torvalds next = page_index; 1591da177e4SLinus Torvalds next++; 1601da177e4SLinus Torvalds if (TestSetPageLocked(page)) 1611da177e4SLinus Torvalds continue; 1621da177e4SLinus Torvalds if (PageWriteback(page)) { 1631da177e4SLinus Torvalds unlock_page(page); 1641da177e4SLinus Torvalds continue; 1651da177e4SLinus Torvalds } 1661da177e4SLinus Torvalds truncate_complete_page(mapping, page); 1671da177e4SLinus Torvalds unlock_page(page); 1681da177e4SLinus Torvalds } 1691da177e4SLinus Torvalds pagevec_release(&pvec); 1701da177e4SLinus Torvalds cond_resched(); 1711da177e4SLinus Torvalds } 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds if (partial) { 1741da177e4SLinus Torvalds struct page *page = find_lock_page(mapping, start - 1); 1751da177e4SLinus Torvalds if (page) { 1761da177e4SLinus Torvalds wait_on_page_writeback(page); 1771da177e4SLinus Torvalds truncate_partial_page(page, partial); 1781da177e4SLinus Torvalds unlock_page(page); 1791da177e4SLinus Torvalds page_cache_release(page); 1801da177e4SLinus Torvalds } 1811da177e4SLinus Torvalds } 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds next = start; 1841da177e4SLinus Torvalds for ( ; ; ) { 1851da177e4SLinus Torvalds cond_resched(); 1861da177e4SLinus Torvalds if (!pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) { 1871da177e4SLinus Torvalds if (next == start) 1881da177e4SLinus Torvalds break; 1891da177e4SLinus Torvalds next = start; 1901da177e4SLinus Torvalds continue; 1911da177e4SLinus Torvalds } 192d7339071SHans Reiser if (pvec.pages[0]->index > end) { 193d7339071SHans Reiser pagevec_release(&pvec); 194d7339071SHans Reiser break; 195d7339071SHans Reiser } 1961da177e4SLinus Torvalds for (i = 0; i < pagevec_count(&pvec); i++) { 1971da177e4SLinus Torvalds struct page *page = pvec.pages[i]; 1981da177e4SLinus Torvalds 199d7339071SHans Reiser if (page->index > end) 200d7339071SHans Reiser break; 2011da177e4SLinus Torvalds lock_page(page); 2021da177e4SLinus Torvalds wait_on_page_writeback(page); 2031da177e4SLinus Torvalds if (page->index > next) 2041da177e4SLinus Torvalds next = page->index; 2051da177e4SLinus Torvalds next++; 2061da177e4SLinus Torvalds truncate_complete_page(mapping, page); 2071da177e4SLinus Torvalds unlock_page(page); 2081da177e4SLinus Torvalds } 2091da177e4SLinus Torvalds pagevec_release(&pvec); 2101da177e4SLinus Torvalds } 2111da177e4SLinus Torvalds } 212d7339071SHans Reiser EXPORT_SYMBOL(truncate_inode_pages_range); 2131da177e4SLinus Torvalds 214d7339071SHans Reiser /** 215d7339071SHans Reiser * truncate_inode_pages - truncate *all* the pages from an offset 216d7339071SHans Reiser * @mapping: mapping to truncate 217d7339071SHans Reiser * @lstart: offset from which to truncate 218d7339071SHans Reiser * 2191b1dcc1bSJes Sorensen * Called under (and serialised by) inode->i_mutex. 220d7339071SHans Reiser */ 221d7339071SHans Reiser void truncate_inode_pages(struct address_space *mapping, loff_t lstart) 222d7339071SHans Reiser { 223d7339071SHans Reiser truncate_inode_pages_range(mapping, lstart, (loff_t)-1); 224d7339071SHans Reiser } 2251da177e4SLinus Torvalds EXPORT_SYMBOL(truncate_inode_pages); 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds /** 2281da177e4SLinus Torvalds * invalidate_mapping_pages - Invalidate all the unlocked pages of one inode 2291da177e4SLinus Torvalds * @mapping: the address_space which holds the pages to invalidate 2301da177e4SLinus Torvalds * @start: the offset 'from' which to invalidate 2311da177e4SLinus Torvalds * @end: the offset 'to' which to invalidate (inclusive) 2321da177e4SLinus Torvalds * 2331da177e4SLinus Torvalds * This function only removes the unlocked pages, if you want to 2341da177e4SLinus Torvalds * remove all the pages of one inode, you must call truncate_inode_pages. 2351da177e4SLinus Torvalds * 2361da177e4SLinus Torvalds * invalidate_mapping_pages() will not block on IO activity. It will not 2371da177e4SLinus Torvalds * invalidate pages which are dirty, locked, under writeback or mapped into 2381da177e4SLinus Torvalds * pagetables. 2391da177e4SLinus Torvalds */ 2401da177e4SLinus Torvalds unsigned long invalidate_mapping_pages(struct address_space *mapping, 2411da177e4SLinus Torvalds pgoff_t start, pgoff_t end) 2421da177e4SLinus Torvalds { 2431da177e4SLinus Torvalds struct pagevec pvec; 2441da177e4SLinus Torvalds pgoff_t next = start; 2451da177e4SLinus Torvalds unsigned long ret = 0; 2461da177e4SLinus Torvalds int i; 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds pagevec_init(&pvec, 0); 2491da177e4SLinus Torvalds while (next <= end && 2501da177e4SLinus Torvalds pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) { 2511da177e4SLinus Torvalds for (i = 0; i < pagevec_count(&pvec); i++) { 2521da177e4SLinus Torvalds struct page *page = pvec.pages[i]; 253e0f23603SNeilBrown pgoff_t index; 254e0f23603SNeilBrown int lock_failed; 2551da177e4SLinus Torvalds 256e0f23603SNeilBrown lock_failed = TestSetPageLocked(page); 257e0f23603SNeilBrown 258e0f23603SNeilBrown /* 259e0f23603SNeilBrown * We really shouldn't be looking at the ->index of an 260e0f23603SNeilBrown * unlocked page. But we're not allowed to lock these 261e0f23603SNeilBrown * pages. So we rely upon nobody altering the ->index 262e0f23603SNeilBrown * of this (pinned-by-us) page. 263e0f23603SNeilBrown */ 264e0f23603SNeilBrown index = page->index; 265e0f23603SNeilBrown if (index > next) 266e0f23603SNeilBrown next = index; 2671da177e4SLinus Torvalds next++; 268e0f23603SNeilBrown if (lock_failed) 2691da177e4SLinus Torvalds continue; 270e0f23603SNeilBrown 2711da177e4SLinus Torvalds if (PageDirty(page) || PageWriteback(page)) 2721da177e4SLinus Torvalds goto unlock; 2731da177e4SLinus Torvalds if (page_mapped(page)) 2741da177e4SLinus Torvalds goto unlock; 2751da177e4SLinus Torvalds ret += invalidate_complete_page(mapping, page); 2761da177e4SLinus Torvalds unlock: 2771da177e4SLinus Torvalds unlock_page(page); 2781da177e4SLinus Torvalds if (next > end) 2791da177e4SLinus Torvalds break; 2801da177e4SLinus Torvalds } 2811da177e4SLinus Torvalds pagevec_release(&pvec); 2821da177e4SLinus Torvalds } 2831da177e4SLinus Torvalds return ret; 2841da177e4SLinus Torvalds } 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds unsigned long invalidate_inode_pages(struct address_space *mapping) 2871da177e4SLinus Torvalds { 2881da177e4SLinus Torvalds return invalidate_mapping_pages(mapping, 0, ~0UL); 2891da177e4SLinus Torvalds } 2901da177e4SLinus Torvalds EXPORT_SYMBOL(invalidate_inode_pages); 2911da177e4SLinus Torvalds 292bd4c8ce4SAndrew Morton /* 293bd4c8ce4SAndrew Morton * This is like invalidate_complete_page(), except it ignores the page's 294bd4c8ce4SAndrew Morton * refcount. We do this because invalidate_inode_pages2() needs stronger 295bd4c8ce4SAndrew Morton * invalidation guarantees, and cannot afford to leave pages behind because 296bd4c8ce4SAndrew Morton * shrink_list() has a temp ref on them, or because they're transiently sitting 297bd4c8ce4SAndrew Morton * in the lru_cache_add() pagevecs. 298bd4c8ce4SAndrew Morton */ 299bd4c8ce4SAndrew Morton static int 300bd4c8ce4SAndrew Morton invalidate_complete_page2(struct address_space *mapping, struct page *page) 301bd4c8ce4SAndrew Morton { 302bd4c8ce4SAndrew Morton if (page->mapping != mapping) 303bd4c8ce4SAndrew Morton return 0; 304bd4c8ce4SAndrew Morton 305*887ed2f3STrond Myklebust if (PagePrivate(page) && !try_to_release_page(page, GFP_KERNEL)) 306bd4c8ce4SAndrew Morton return 0; 307bd4c8ce4SAndrew Morton 308bd4c8ce4SAndrew Morton write_lock_irq(&mapping->tree_lock); 309bd4c8ce4SAndrew Morton if (PageDirty(page)) 310bd4c8ce4SAndrew Morton goto failed; 311bd4c8ce4SAndrew Morton 312bd4c8ce4SAndrew Morton BUG_ON(PagePrivate(page)); 313bd4c8ce4SAndrew Morton __remove_from_page_cache(page); 314bd4c8ce4SAndrew Morton write_unlock_irq(&mapping->tree_lock); 315bd4c8ce4SAndrew Morton ClearPageUptodate(page); 316bd4c8ce4SAndrew Morton page_cache_release(page); /* pagecache ref */ 317bd4c8ce4SAndrew Morton return 1; 318bd4c8ce4SAndrew Morton failed: 319bd4c8ce4SAndrew Morton write_unlock_irq(&mapping->tree_lock); 320bd4c8ce4SAndrew Morton return 0; 321bd4c8ce4SAndrew Morton } 322bd4c8ce4SAndrew Morton 3231da177e4SLinus Torvalds /** 3241da177e4SLinus Torvalds * invalidate_inode_pages2_range - remove range of pages from an address_space 32567be2dd1SMartin Waitz * @mapping: the address_space 3261da177e4SLinus Torvalds * @start: the page offset 'from' which to invalidate 3271da177e4SLinus Torvalds * @end: the page offset 'to' which to invalidate (inclusive) 3281da177e4SLinus Torvalds * 3291da177e4SLinus Torvalds * Any pages which are found to be mapped into pagetables are unmapped prior to 3301da177e4SLinus Torvalds * invalidation. 3311da177e4SLinus Torvalds * 3321da177e4SLinus Torvalds * Returns -EIO if any pages could not be invalidated. 3331da177e4SLinus Torvalds */ 3341da177e4SLinus Torvalds int invalidate_inode_pages2_range(struct address_space *mapping, 3351da177e4SLinus Torvalds pgoff_t start, pgoff_t end) 3361da177e4SLinus Torvalds { 3371da177e4SLinus Torvalds struct pagevec pvec; 3381da177e4SLinus Torvalds pgoff_t next; 3391da177e4SLinus Torvalds int i; 3401da177e4SLinus Torvalds int ret = 0; 3411da177e4SLinus Torvalds int did_range_unmap = 0; 3421da177e4SLinus Torvalds int wrapped = 0; 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds pagevec_init(&pvec, 0); 3451da177e4SLinus Torvalds next = start; 3461da177e4SLinus Torvalds while (next <= end && !ret && !wrapped && 3471da177e4SLinus Torvalds pagevec_lookup(&pvec, mapping, next, 3481da177e4SLinus Torvalds min(end - next, (pgoff_t)PAGEVEC_SIZE - 1) + 1)) { 3491da177e4SLinus Torvalds for (i = 0; !ret && i < pagevec_count(&pvec); i++) { 3501da177e4SLinus Torvalds struct page *page = pvec.pages[i]; 3511da177e4SLinus Torvalds pgoff_t page_index; 3521da177e4SLinus Torvalds int was_dirty; 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds lock_page(page); 3551da177e4SLinus Torvalds if (page->mapping != mapping) { 3561da177e4SLinus Torvalds unlock_page(page); 3571da177e4SLinus Torvalds continue; 3581da177e4SLinus Torvalds } 3591da177e4SLinus Torvalds page_index = page->index; 3601da177e4SLinus Torvalds next = page_index + 1; 3611da177e4SLinus Torvalds if (next == 0) 3621da177e4SLinus Torvalds wrapped = 1; 3631da177e4SLinus Torvalds if (page_index > end) { 3641da177e4SLinus Torvalds unlock_page(page); 3651da177e4SLinus Torvalds break; 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds wait_on_page_writeback(page); 3681da177e4SLinus Torvalds while (page_mapped(page)) { 3691da177e4SLinus Torvalds if (!did_range_unmap) { 3701da177e4SLinus Torvalds /* 3711da177e4SLinus Torvalds * Zap the rest of the file in one hit. 3721da177e4SLinus Torvalds */ 3731da177e4SLinus Torvalds unmap_mapping_range(mapping, 374479ef592SOleg Drokin (loff_t)page_index<<PAGE_CACHE_SHIFT, 375479ef592SOleg Drokin (loff_t)(end - page_index + 1) 3761da177e4SLinus Torvalds << PAGE_CACHE_SHIFT, 3771da177e4SLinus Torvalds 0); 3781da177e4SLinus Torvalds did_range_unmap = 1; 3791da177e4SLinus Torvalds } else { 3801da177e4SLinus Torvalds /* 3811da177e4SLinus Torvalds * Just zap this page 3821da177e4SLinus Torvalds */ 3831da177e4SLinus Torvalds unmap_mapping_range(mapping, 384479ef592SOleg Drokin (loff_t)page_index<<PAGE_CACHE_SHIFT, 3851da177e4SLinus Torvalds PAGE_CACHE_SIZE, 0); 3861da177e4SLinus Torvalds } 3871da177e4SLinus Torvalds } 3881da177e4SLinus Torvalds was_dirty = test_clear_page_dirty(page); 389bd4c8ce4SAndrew Morton if (!invalidate_complete_page2(mapping, page)) { 3901da177e4SLinus Torvalds if (was_dirty) 3911da177e4SLinus Torvalds set_page_dirty(page); 3921da177e4SLinus Torvalds ret = -EIO; 3931da177e4SLinus Torvalds } 3941da177e4SLinus Torvalds unlock_page(page); 3951da177e4SLinus Torvalds } 3961da177e4SLinus Torvalds pagevec_release(&pvec); 3971da177e4SLinus Torvalds cond_resched(); 3981da177e4SLinus Torvalds } 3998258d4a5SAndrew Morton WARN_ON_ONCE(ret); 4001da177e4SLinus Torvalds return ret; 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds EXPORT_SYMBOL_GPL(invalidate_inode_pages2_range); 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds /** 4051da177e4SLinus Torvalds * invalidate_inode_pages2 - remove all pages from an address_space 40667be2dd1SMartin Waitz * @mapping: the address_space 4071da177e4SLinus Torvalds * 4081da177e4SLinus Torvalds * Any pages which are found to be mapped into pagetables are unmapped prior to 4091da177e4SLinus Torvalds * invalidation. 4101da177e4SLinus Torvalds * 4111da177e4SLinus Torvalds * Returns -EIO if any pages could not be invalidated. 4121da177e4SLinus Torvalds */ 4131da177e4SLinus Torvalds int invalidate_inode_pages2(struct address_space *mapping) 4141da177e4SLinus Torvalds { 4151da177e4SLinus Torvalds return invalidate_inode_pages2_range(mapping, 0, -1); 4161da177e4SLinus Torvalds } 4171da177e4SLinus Torvalds EXPORT_SYMBOL_GPL(invalidate_inode_pages2); 418