diff options
Diffstat (limited to 'mm/truncate.c')
| -rw-r--r-- | mm/truncate.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/mm/truncate.c b/mm/truncate.c index c6ab55ec6883..a654928323dc 100644 --- a/mm/truncate.c +++ b/mm/truncate.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/mm.h> | 11 | #include <linux/mm.h> |
| 12 | #include <linux/swap.h> | ||
| 12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 13 | #include <linux/pagemap.h> | 14 | #include <linux/pagemap.h> |
| 14 | #include <linux/pagevec.h> | 15 | #include <linux/pagevec.h> |
| @@ -52,36 +53,26 @@ truncate_complete_page(struct address_space *mapping, struct page *page) | |||
| 52 | /* | 53 | /* |
| 53 | * This is for invalidate_inode_pages(). That function can be called at | 54 | * This is for invalidate_inode_pages(). That function can be called at |
| 54 | * any time, and is not supposed to throw away dirty pages. But pages can | 55 | * any time, and is not supposed to throw away dirty pages. But pages can |
| 55 | * be marked dirty at any time too. So we re-check the dirtiness inside | 56 | * be marked dirty at any time too, so use remove_mapping which safely |
| 56 | * ->tree_lock. That provides exclusion against the __set_page_dirty | 57 | * discards clean, unused pages. |
| 57 | * functions. | ||
| 58 | * | 58 | * |
| 59 | * Returns non-zero if the page was successfully invalidated. | 59 | * Returns non-zero if the page was successfully invalidated. |
| 60 | */ | 60 | */ |
| 61 | static int | 61 | static int |
| 62 | invalidate_complete_page(struct address_space *mapping, struct page *page) | 62 | invalidate_complete_page(struct address_space *mapping, struct page *page) |
| 63 | { | 63 | { |
| 64 | int ret; | ||
| 65 | |||
| 64 | if (page->mapping != mapping) | 66 | if (page->mapping != mapping) |
| 65 | return 0; | 67 | return 0; |
| 66 | 68 | ||
| 67 | if (PagePrivate(page) && !try_to_release_page(page, 0)) | 69 | if (PagePrivate(page) && !try_to_release_page(page, 0)) |
| 68 | return 0; | 70 | return 0; |
| 69 | 71 | ||
| 70 | write_lock_irq(&mapping->tree_lock); | 72 | ret = remove_mapping(mapping, page); |
| 71 | if (PageDirty(page)) | ||
| 72 | goto failed; | ||
| 73 | if (page_count(page) != 2) /* caller's ref + pagecache ref */ | ||
| 74 | goto failed; | ||
| 75 | |||
| 76 | BUG_ON(PagePrivate(page)); | ||
| 77 | __remove_from_page_cache(page); | ||
| 78 | write_unlock_irq(&mapping->tree_lock); | ||
| 79 | ClearPageUptodate(page); | 73 | ClearPageUptodate(page); |
| 80 | page_cache_release(page); /* pagecache ref */ | 74 | |
| 81 | return 1; | 75 | return ret; |
| 82 | failed: | ||
| 83 | write_unlock_irq(&mapping->tree_lock); | ||
| 84 | return 0; | ||
| 85 | } | 76 | } |
| 86 | 77 | ||
| 87 | /** | 78 | /** |
