Commit 83f78668 authored by Wu Fengguang's avatar Wu Fengguang Committed by Andi Kleen

HWPOISON: Add invalidate_inode_page

Add a simple way to invalidate a single page
This is just a refactoring of the truncate.c code.
Originally from Fengguang, modified by Andi Kleen.
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
parent 750b4987
...@@ -796,6 +796,8 @@ extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end); ...@@ -796,6 +796,8 @@ extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end);
int truncate_inode_page(struct address_space *mapping, struct page *page); int truncate_inode_page(struct address_space *mapping, struct page *page);
int invalidate_inode_page(struct page *page);
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
extern int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, extern int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long address, unsigned int flags); unsigned long address, unsigned int flags);
......
...@@ -146,6 +146,24 @@ int truncate_inode_page(struct address_space *mapping, struct page *page) ...@@ -146,6 +146,24 @@ int truncate_inode_page(struct address_space *mapping, struct page *page)
return truncate_complete_page(mapping, page); return truncate_complete_page(mapping, page);
} }
/*
* Safely invalidate one page from its pagecache mapping.
* It only drops clean, unused pages. The page must be locked.
*
* Returns 1 if the page is successfully invalidated, otherwise 0.
*/
int invalidate_inode_page(struct page *page)
{
struct address_space *mapping = page_mapping(page);
if (!mapping)
return 0;
if (PageDirty(page) || PageWriteback(page))
return 0;
if (page_mapped(page))
return 0;
return invalidate_complete_page(mapping, page);
}
/** /**
* truncate_inode_pages - truncate range of pages specified by start & end byte offsets * truncate_inode_pages - truncate range of pages specified by start & end byte offsets
* @mapping: mapping to truncate * @mapping: mapping to truncate
...@@ -312,12 +330,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping, ...@@ -312,12 +330,8 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
if (lock_failed) if (lock_failed)
continue; continue;
if (PageDirty(page) || PageWriteback(page)) ret += invalidate_inode_page(page);
goto unlock;
if (page_mapped(page))
goto unlock;
ret += invalidate_complete_page(mapping, page);
unlock:
unlock_page(page); unlock_page(page);
if (next > end) if (next > end)
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment