mm + fs: prepare for non-page entries in page cache radix trees
[linux-2.6-microblaze.git] / mm / truncate.c
1 /*
2  * mm/truncate.c - code for taking down pages from address_spaces
3  *
4  * Copyright (C) 2002, Linus Torvalds
5  *
6  * 10Sep2002    Andrew Morton
7  *              Initial version.
8  */
9
10 #include <linux/kernel.h>
11 #include <linux/backing-dev.h>
12 #include <linux/gfp.h>
13 #include <linux/mm.h>
14 #include <linux/swap.h>
15 #include <linux/export.h>
16 #include <linux/pagemap.h>
17 #include <linux/highmem.h>
18 #include <linux/pagevec.h>
19 #include <linux/task_io_accounting_ops.h>
20 #include <linux/buffer_head.h>  /* grr. try_to_release_page,
21                                    do_invalidatepage */
22 #include <linux/cleancache.h>
23 #include "internal.h"
24
25 static void clear_exceptional_entry(struct address_space *mapping,
26                                     pgoff_t index, void *entry)
27 {
28         /* Handled by shmem itself */
29         if (shmem_mapping(mapping))
30                 return;
31
32         spin_lock_irq(&mapping->tree_lock);
33         /*
34          * Regular page slots are stabilized by the page lock even
35          * without the tree itself locked.  These unlocked entries
36          * need verification under the tree lock.
37          */
38         radix_tree_delete_item(&mapping->page_tree, index, entry);
39         spin_unlock_irq(&mapping->tree_lock);
40 }
41
42 /**
43  * do_invalidatepage - invalidate part or all of a page
44  * @page: the page which is affected
45  * @offset: start of the range to invalidate
46  * @length: length of the range to invalidate
47  *
48  * do_invalidatepage() is called when all or part of the page has become
49  * invalidated by a truncate operation.
50  *
51  * do_invalidatepage() does not have to release all buffers, but it must
52  * ensure that no dirty buffer is left outside @offset and that no I/O
53  * is underway against any of the blocks which are outside the truncation
54  * point.  Because the caller is about to free (and possibly reuse) those
55  * blocks on-disk.
56  */
57 void do_invalidatepage(struct page *page, unsigned int offset,
58                        unsigned int length)
59 {
60         void (*invalidatepage)(struct page *, unsigned int, unsigned int);
61
62         invalidatepage = page->mapping->a_ops->invalidatepage;
63 #ifdef CONFIG_BLOCK
64         if (!invalidatepage)
65                 invalidatepage = block_invalidatepage;
66 #endif
67         if (invalidatepage)
68                 (*invalidatepage)(page, offset, length);
69 }
70
71 /*
72  * This cancels just the dirty bit on the kernel page itself, it
73  * does NOT actually remove dirty bits on any mmap's that may be
74  * around. It also leaves the page tagged dirty, so any sync
75  * activity will still find it on the dirty lists, and in particular,
76  * clear_page_dirty_for_io() will still look at the dirty bits in
77  * the VM.
78  *
79  * Doing this should *normally* only ever be done when a page
80  * is truncated, and is not actually mapped anywhere at all. However,
81  * fs/buffer.c does this when it notices that somebody has cleaned
82  * out all the buffers on a page without actually doing it through
83  * the VM. Can you say "ext3 is horribly ugly"? Tought you could.
84  */
85 void cancel_dirty_page(struct page *page, unsigned int account_size)
86 {
87         if (TestClearPageDirty(page)) {
88                 struct address_space *mapping = page->mapping;
89                 if (mapping && mapping_cap_account_dirty(mapping)) {
90                         dec_zone_page_state(page, NR_FILE_DIRTY);
91                         dec_bdi_stat(mapping->backing_dev_info,
92                                         BDI_RECLAIMABLE);
93                         if (account_size)
94                                 task_io_account_cancelled_write(account_size);
95                 }
96         }
97 }
98 EXPORT_SYMBOL(cancel_dirty_page);
99
100 /*
101  * If truncate cannot remove the fs-private metadata from the page, the page
102  * becomes orphaned.  It will be left on the LRU and may even be mapped into
103  * user pagetables if we're racing with filemap_fault().
104  *
105  * We need to bale out if page->mapping is no longer equal to the original
106  * mapping.  This happens a) when the VM reclaimed the page while we waited on
107  * its lock, b) when a concurrent invalidate_mapping_pages got there first and
108  * c) when tmpfs swizzles a page between a tmpfs inode and swapper_space.
109  */
110 static int
111 truncate_complete_page(struct address_space *mapping, struct page *page)
112 {
113         if (page->mapping != mapping)
114                 return -EIO;
115
116         if (page_has_private(page))
117                 do_invalidatepage(page, 0, PAGE_CACHE_SIZE);
118
119         cancel_dirty_page(page, PAGE_CACHE_SIZE);
120
121         ClearPageMappedToDisk(page);
122         delete_from_page_cache(page);
123         return 0;
124 }
125
126 /*
127  * This is for invalidate_mapping_pages().  That function can be called at
128  * any time, and is not supposed to throw away dirty pages.  But pages can
129  * be marked dirty at any time too, so use remove_mapping which safely
130  * discards clean, unused pages.
131  *
132  * Returns non-zero if the page was successfully invalidated.
133  */
134 static int
135 invalidate_complete_page(struct address_space *mapping, struct page *page)
136 {
137         int ret;
138
139         if (page->mapping != mapping)
140                 return 0;
141
142         if (page_has_private(page) && !try_to_release_page(page, 0))
143                 return 0;
144
145         ret = remove_mapping(mapping, page);
146
147         return ret;
148 }
149
150 int truncate_inode_page(struct address_space *mapping, struct page *page)
151 {
152         if (page_mapped(page)) {
153                 unmap_mapping_range(mapping,
154                                    (loff_t)page->index << PAGE_CACHE_SHIFT,
155                                    PAGE_CACHE_SIZE, 0);
156         }
157         return truncate_complete_page(mapping, page);
158 }
159
160 /*
161  * Used to get rid of pages on hardware memory corruption.
162  */
163 int generic_error_remove_page(struct address_space *mapping, struct page *page)
164 {
165         if (!mapping)
166                 return -EINVAL;
167         /*
168          * Only punch for normal data pages for now.
169          * Handling other types like directories would need more auditing.
170          */
171         if (!S_ISREG(mapping->host->i_mode))
172                 return -EIO;
173         return truncate_inode_page(mapping, page);
174 }
175 EXPORT_SYMBOL(generic_error_remove_page);
176
177 /*
178  * Safely invalidate one page from its pagecache mapping.
179  * It only drops clean, unused pages. The page must be locked.
180  *
181  * Returns 1 if the page is successfully invalidated, otherwise 0.
182  */
183 int invalidate_inode_page(struct page *page)
184 {
185         struct address_space *mapping = page_mapping(page);
186         if (!mapping)
187                 return 0;
188         if (PageDirty(page) || PageWriteback(page))
189                 return 0;
190         if (page_mapped(page))
191                 return 0;
192         return invalidate_complete_page(mapping, page);
193 }
194
195 /**
196  * truncate_inode_pages_range - truncate range of pages specified by start & end byte offsets
197  * @mapping: mapping to truncate
198  * @lstart: offset from which to truncate
199  * @lend: offset to which to truncate (inclusive)
200  *
201  * Truncate the page cache, removing the pages that are between
202  * specified offsets (and zeroing out partial pages
203  * if lstart or lend + 1 is not page aligned).
204  *
205  * Truncate takes two passes - the first pass is nonblocking.  It will not
206  * block on page locks and it will not block on writeback.  The second pass
207  * will wait.  This is to prevent as much IO as possible in the affected region.
208  * The first pass will remove most pages, so the search cost of the second pass
209  * is low.
210  *
211  * We pass down the cache-hot hint to the page freeing code.  Even if the
212  * mapping is large, it is probably the case that the final pages are the most
213  * recently touched, and freeing happens in ascending file offset order.
214  *
215  * Note that since ->invalidatepage() accepts range to invalidate
216  * truncate_inode_pages_range is able to handle cases where lend + 1 is not
217  * page aligned properly.
218  */
219 void truncate_inode_pages_range(struct address_space *mapping,
220                                 loff_t lstart, loff_t lend)
221 {
222         pgoff_t         start;          /* inclusive */
223         pgoff_t         end;            /* exclusive */
224         unsigned int    partial_start;  /* inclusive */
225         unsigned int    partial_end;    /* exclusive */
226         struct pagevec  pvec;
227         pgoff_t         indices[PAGEVEC_SIZE];
228         pgoff_t         index;
229         int             i;
230
231         cleancache_invalidate_inode(mapping);
232         if (mapping->nrpages == 0)
233                 return;
234
235         /* Offsets within partial pages */
236         partial_start = lstart & (PAGE_CACHE_SIZE - 1);
237         partial_end = (lend + 1) & (PAGE_CACHE_SIZE - 1);
238
239         /*
240          * 'start' and 'end' always covers the range of pages to be fully
241          * truncated. Partial pages are covered with 'partial_start' at the
242          * start of the range and 'partial_end' at the end of the range.
243          * Note that 'end' is exclusive while 'lend' is inclusive.
244          */
245         start = (lstart + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
246         if (lend == -1)
247                 /*
248                  * lend == -1 indicates end-of-file so we have to set 'end'
249                  * to the highest possible pgoff_t and since the type is
250                  * unsigned we're using -1.
251                  */
252                 end = -1;
253         else
254                 end = (lend + 1) >> PAGE_CACHE_SHIFT;
255
256         pagevec_init(&pvec, 0);
257         index = start;
258         while (index < end && pagevec_lookup_entries(&pvec, mapping, index,
259                         min(end - index, (pgoff_t)PAGEVEC_SIZE),
260                         indices)) {
261                 mem_cgroup_uncharge_start();
262                 for (i = 0; i < pagevec_count(&pvec); i++) {
263                         struct page *page = pvec.pages[i];
264
265                         /* We rely upon deletion not changing page->index */
266                         index = indices[i];
267                         if (index >= end)
268                                 break;
269
270                         if (radix_tree_exceptional_entry(page)) {
271                                 clear_exceptional_entry(mapping, index, page);
272                                 continue;
273                         }
274
275                         if (!trylock_page(page))
276                                 continue;
277                         WARN_ON(page->index != index);
278                         if (PageWriteback(page)) {
279                                 unlock_page(page);
280                                 continue;
281                         }
282                         truncate_inode_page(mapping, page);
283                         unlock_page(page);
284                 }
285                 pagevec_remove_exceptionals(&pvec);
286                 pagevec_release(&pvec);
287                 mem_cgroup_uncharge_end();
288                 cond_resched();
289                 index++;
290         }
291
292         if (partial_start) {
293                 struct page *page = find_lock_page(mapping, start - 1);
294                 if (page) {
295                         unsigned int top = PAGE_CACHE_SIZE;
296                         if (start > end) {
297                                 /* Truncation within a single page */
298                                 top = partial_end;
299                                 partial_end = 0;
300                         }
301                         wait_on_page_writeback(page);
302                         zero_user_segment(page, partial_start, top);
303                         cleancache_invalidate_page(mapping, page);
304                         if (page_has_private(page))
305                                 do_invalidatepage(page, partial_start,
306                                                   top - partial_start);
307                         unlock_page(page);
308                         page_cache_release(page);
309                 }
310         }
311         if (partial_end) {
312                 struct page *page = find_lock_page(mapping, end);
313                 if (page) {
314                         wait_on_page_writeback(page);
315                         zero_user_segment(page, 0, partial_end);
316                         cleancache_invalidate_page(mapping, page);
317                         if (page_has_private(page))
318                                 do_invalidatepage(page, 0,
319                                                   partial_end);
320                         unlock_page(page);
321                         page_cache_release(page);
322                 }
323         }
324         /*
325          * If the truncation happened within a single page no pages
326          * will be released, just zeroed, so we can bail out now.
327          */
328         if (start >= end)
329                 return;
330
331         index = start;
332         for ( ; ; ) {
333                 cond_resched();
334                 if (!pagevec_lookup_entries(&pvec, mapping, index,
335                         min(end - index, (pgoff_t)PAGEVEC_SIZE),
336                         indices)) {
337                         if (index == start)
338                                 break;
339                         index = start;
340                         continue;
341                 }
342                 if (index == start && indices[0] >= end) {
343                         pagevec_remove_exceptionals(&pvec);
344                         pagevec_release(&pvec);
345                         break;
346                 }
347                 mem_cgroup_uncharge_start();
348                 for (i = 0; i < pagevec_count(&pvec); i++) {
349                         struct page *page = pvec.pages[i];
350
351                         /* We rely upon deletion not changing page->index */
352                         index = indices[i];
353                         if (index >= end)
354                                 break;
355
356                         if (radix_tree_exceptional_entry(page)) {
357                                 clear_exceptional_entry(mapping, index, page);
358                                 continue;
359                         }
360
361                         lock_page(page);
362                         WARN_ON(page->index != index);
363                         wait_on_page_writeback(page);
364                         truncate_inode_page(mapping, page);
365                         unlock_page(page);
366                 }
367                 pagevec_remove_exceptionals(&pvec);
368                 pagevec_release(&pvec);
369                 mem_cgroup_uncharge_end();
370                 index++;
371         }
372         cleancache_invalidate_inode(mapping);
373 }
374 EXPORT_SYMBOL(truncate_inode_pages_range);
375
376 /**
377  * truncate_inode_pages - truncate *all* the pages from an offset
378  * @mapping: mapping to truncate
379  * @lstart: offset from which to truncate
380  *
381  * Called under (and serialised by) inode->i_mutex.
382  *
383  * Note: When this function returns, there can be a page in the process of
384  * deletion (inside __delete_from_page_cache()) in the specified range.  Thus
385  * mapping->nrpages can be non-zero when this function returns even after
386  * truncation of the whole mapping.
387  */
388 void truncate_inode_pages(struct address_space *mapping, loff_t lstart)
389 {
390         truncate_inode_pages_range(mapping, lstart, (loff_t)-1);
391 }
392 EXPORT_SYMBOL(truncate_inode_pages);
393
394 /**
395  * invalidate_mapping_pages - Invalidate all the unlocked pages of one inode
396  * @mapping: the address_space which holds the pages to invalidate
397  * @start: the offset 'from' which to invalidate
398  * @end: the offset 'to' which to invalidate (inclusive)
399  *
400  * This function only removes the unlocked pages, if you want to
401  * remove all the pages of one inode, you must call truncate_inode_pages.
402  *
403  * invalidate_mapping_pages() will not block on IO activity. It will not
404  * invalidate pages which are dirty, locked, under writeback or mapped into
405  * pagetables.
406  */
407 unsigned long invalidate_mapping_pages(struct address_space *mapping,
408                 pgoff_t start, pgoff_t end)
409 {
410         pgoff_t indices[PAGEVEC_SIZE];
411         struct pagevec pvec;
412         pgoff_t index = start;
413         unsigned long ret;
414         unsigned long count = 0;
415         int i;
416
417         /*
418          * Note: this function may get called on a shmem/tmpfs mapping:
419          * pagevec_lookup() might then return 0 prematurely (because it
420          * got a gangful of swap entries); but it's hardly worth worrying
421          * about - it can rarely have anything to free from such a mapping
422          * (most pages are dirty), and already skips over any difficulties.
423          */
424
425         pagevec_init(&pvec, 0);
426         while (index <= end && pagevec_lookup_entries(&pvec, mapping, index,
427                         min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1,
428                         indices)) {
429                 mem_cgroup_uncharge_start();
430                 for (i = 0; i < pagevec_count(&pvec); i++) {
431                         struct page *page = pvec.pages[i];
432
433                         /* We rely upon deletion not changing page->index */
434                         index = indices[i];
435                         if (index > end)
436                                 break;
437
438                         if (radix_tree_exceptional_entry(page)) {
439                                 clear_exceptional_entry(mapping, index, page);
440                                 continue;
441                         }
442
443                         if (!trylock_page(page))
444                                 continue;
445                         WARN_ON(page->index != index);
446                         ret = invalidate_inode_page(page);
447                         unlock_page(page);
448                         /*
449                          * Invalidation is a hint that the page is no longer
450                          * of interest and try to speed up its reclaim.
451                          */
452                         if (!ret)
453                                 deactivate_page(page);
454                         count += ret;
455                 }
456                 pagevec_remove_exceptionals(&pvec);
457                 pagevec_release(&pvec);
458                 mem_cgroup_uncharge_end();
459                 cond_resched();
460                 index++;
461         }
462         return count;
463 }
464 EXPORT_SYMBOL(invalidate_mapping_pages);
465
466 /*
467  * This is like invalidate_complete_page(), except it ignores the page's
468  * refcount.  We do this because invalidate_inode_pages2() needs stronger
469  * invalidation guarantees, and cannot afford to leave pages behind because
470  * shrink_page_list() has a temp ref on them, or because they're transiently
471  * sitting in the lru_cache_add() pagevecs.
472  */
473 static int
474 invalidate_complete_page2(struct address_space *mapping, struct page *page)
475 {
476         if (page->mapping != mapping)
477                 return 0;
478
479         if (page_has_private(page) && !try_to_release_page(page, GFP_KERNEL))
480                 return 0;
481
482         spin_lock_irq(&mapping->tree_lock);
483         if (PageDirty(page))
484                 goto failed;
485
486         BUG_ON(page_has_private(page));
487         __delete_from_page_cache(page);
488         spin_unlock_irq(&mapping->tree_lock);
489         mem_cgroup_uncharge_cache_page(page);
490
491         if (mapping->a_ops->freepage)
492                 mapping->a_ops->freepage(page);
493
494         page_cache_release(page);       /* pagecache ref */
495         return 1;
496 failed:
497         spin_unlock_irq(&mapping->tree_lock);
498         return 0;
499 }
500
501 static int do_launder_page(struct address_space *mapping, struct page *page)
502 {
503         if (!PageDirty(page))
504                 return 0;
505         if (page->mapping != mapping || mapping->a_ops->launder_page == NULL)
506                 return 0;
507         return mapping->a_ops->launder_page(page);
508 }
509
510 /**
511  * invalidate_inode_pages2_range - remove range of pages from an address_space
512  * @mapping: the address_space
513  * @start: the page offset 'from' which to invalidate
514  * @end: the page offset 'to' which to invalidate (inclusive)
515  *
516  * Any pages which are found to be mapped into pagetables are unmapped prior to
517  * invalidation.
518  *
519  * Returns -EBUSY if any pages could not be invalidated.
520  */
521 int invalidate_inode_pages2_range(struct address_space *mapping,
522                                   pgoff_t start, pgoff_t end)
523 {
524         pgoff_t indices[PAGEVEC_SIZE];
525         struct pagevec pvec;
526         pgoff_t index;
527         int i;
528         int ret = 0;
529         int ret2 = 0;
530         int did_range_unmap = 0;
531
532         cleancache_invalidate_inode(mapping);
533         pagevec_init(&pvec, 0);
534         index = start;
535         while (index <= end && pagevec_lookup_entries(&pvec, mapping, index,
536                         min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1,
537                         indices)) {
538                 mem_cgroup_uncharge_start();
539                 for (i = 0; i < pagevec_count(&pvec); i++) {
540                         struct page *page = pvec.pages[i];
541
542                         /* We rely upon deletion not changing page->index */
543                         index = indices[i];
544                         if (index > end)
545                                 break;
546
547                         if (radix_tree_exceptional_entry(page)) {
548                                 clear_exceptional_entry(mapping, index, page);
549                                 continue;
550                         }
551
552                         lock_page(page);
553                         WARN_ON(page->index != index);
554                         if (page->mapping != mapping) {
555                                 unlock_page(page);
556                                 continue;
557                         }
558                         wait_on_page_writeback(page);
559                         if (page_mapped(page)) {
560                                 if (!did_range_unmap) {
561                                         /*
562                                          * Zap the rest of the file in one hit.
563                                          */
564                                         unmap_mapping_range(mapping,
565                                            (loff_t)index << PAGE_CACHE_SHIFT,
566                                            (loff_t)(1 + end - index)
567                                                          << PAGE_CACHE_SHIFT,
568                                             0);
569                                         did_range_unmap = 1;
570                                 } else {
571                                         /*
572                                          * Just zap this page
573                                          */
574                                         unmap_mapping_range(mapping,
575                                            (loff_t)index << PAGE_CACHE_SHIFT,
576                                            PAGE_CACHE_SIZE, 0);
577                                 }
578                         }
579                         BUG_ON(page_mapped(page));
580                         ret2 = do_launder_page(mapping, page);
581                         if (ret2 == 0) {
582                                 if (!invalidate_complete_page2(mapping, page))
583                                         ret2 = -EBUSY;
584                         }
585                         if (ret2 < 0)
586                                 ret = ret2;
587                         unlock_page(page);
588                 }
589                 pagevec_remove_exceptionals(&pvec);
590                 pagevec_release(&pvec);
591                 mem_cgroup_uncharge_end();
592                 cond_resched();
593                 index++;
594         }
595         cleancache_invalidate_inode(mapping);
596         return ret;
597 }
598 EXPORT_SYMBOL_GPL(invalidate_inode_pages2_range);
599
600 /**
601  * invalidate_inode_pages2 - remove all pages from an address_space
602  * @mapping: the address_space
603  *
604  * Any pages which are found to be mapped into pagetables are unmapped prior to
605  * invalidation.
606  *
607  * Returns -EBUSY if any pages could not be invalidated.
608  */
609 int invalidate_inode_pages2(struct address_space *mapping)
610 {
611         return invalidate_inode_pages2_range(mapping, 0, -1);
612 }
613 EXPORT_SYMBOL_GPL(invalidate_inode_pages2);
614
615 /**
616  * truncate_pagecache - unmap and remove pagecache that has been truncated
617  * @inode: inode
618  * @newsize: new file size
619  *
620  * inode's new i_size must already be written before truncate_pagecache
621  * is called.
622  *
623  * This function should typically be called before the filesystem
624  * releases resources associated with the freed range (eg. deallocates
625  * blocks). This way, pagecache will always stay logically coherent
626  * with on-disk format, and the filesystem would not have to deal with
627  * situations such as writepage being called for a page that has already
628  * had its underlying blocks deallocated.
629  */
630 void truncate_pagecache(struct inode *inode, loff_t newsize)
631 {
632         struct address_space *mapping = inode->i_mapping;
633         loff_t holebegin = round_up(newsize, PAGE_SIZE);
634
635         /*
636          * unmap_mapping_range is called twice, first simply for
637          * efficiency so that truncate_inode_pages does fewer
638          * single-page unmaps.  However after this first call, and
639          * before truncate_inode_pages finishes, it is possible for
640          * private pages to be COWed, which remain after
641          * truncate_inode_pages finishes, hence the second
642          * unmap_mapping_range call must be made for correctness.
643          */
644         unmap_mapping_range(mapping, holebegin, 0, 1);
645         truncate_inode_pages(mapping, newsize);
646         unmap_mapping_range(mapping, holebegin, 0, 1);
647 }
648 EXPORT_SYMBOL(truncate_pagecache);
649
650 /**
651  * truncate_setsize - update inode and pagecache for a new file size
652  * @inode: inode
653  * @newsize: new file size
654  *
655  * truncate_setsize updates i_size and performs pagecache truncation (if
656  * necessary) to @newsize. It will be typically be called from the filesystem's
657  * setattr function when ATTR_SIZE is passed in.
658  *
659  * Must be called with inode_mutex held and before all filesystem specific
660  * block truncation has been performed.
661  */
662 void truncate_setsize(struct inode *inode, loff_t newsize)
663 {
664         i_size_write(inode, newsize);
665         truncate_pagecache(inode, newsize);
666 }
667 EXPORT_SYMBOL(truncate_setsize);
668
669 /**
670  * truncate_pagecache_range - unmap and remove pagecache that is hole-punched
671  * @inode: inode
672  * @lstart: offset of beginning of hole
673  * @lend: offset of last byte of hole
674  *
675  * This function should typically be called before the filesystem
676  * releases resources associated with the freed range (eg. deallocates
677  * blocks). This way, pagecache will always stay logically coherent
678  * with on-disk format, and the filesystem would not have to deal with
679  * situations such as writepage being called for a page that has already
680  * had its underlying blocks deallocated.
681  */
682 void truncate_pagecache_range(struct inode *inode, loff_t lstart, loff_t lend)
683 {
684         struct address_space *mapping = inode->i_mapping;
685         loff_t unmap_start = round_up(lstart, PAGE_SIZE);
686         loff_t unmap_end = round_down(1 + lend, PAGE_SIZE) - 1;
687         /*
688          * This rounding is currently just for example: unmap_mapping_range
689          * expands its hole outwards, whereas we want it to contract the hole
690          * inwards.  However, existing callers of truncate_pagecache_range are
691          * doing their own page rounding first.  Note that unmap_mapping_range
692          * allows holelen 0 for all, and we allow lend -1 for end of file.
693          */
694
695         /*
696          * Unlike in truncate_pagecache, unmap_mapping_range is called only
697          * once (before truncating pagecache), and without "even_cows" flag:
698          * hole-punching should not remove private COWed pages from the hole.
699          */
700         if ((u64)unmap_end > (u64)unmap_start)
701                 unmap_mapping_range(mapping, unmap_start,
702                                     1 + unmap_end - unmap_start, 0);
703         truncate_inode_pages_range(mapping, lstart, lend);
704 }
705 EXPORT_SYMBOL(truncate_pagecache_range);