[Devel] [PATCH rh7 5/5] mm/filemap: add pfcache support to filemap_map_pages

Andrey Ryabinin aryabinin at virtuozzo.com
Wed Feb 26 16:49:45 MSK 2020


Make filmeap_map_pages to map pages from pfcache if that's available.

https://jira.sw.ru/browse/PSBM-101300
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/filemap.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index bbddfeb2675d..af1618bf97a6 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2409,11 +2409,11 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 }
 EXPORT_SYMBOL(filemap_fault);
 
-void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf)
+static void __filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf,
+				struct file *file)
 {
 	struct radix_tree_iter iter;
 	void **slot;
-	struct file *file = vma->vm_file;
 	struct address_space *mapping = file->f_mapping;
 	loff_t size;
 	struct page *page;
@@ -2421,7 +2421,6 @@ void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf)
 	unsigned long addr;
 	pte_t *pte;
 
-	rcu_read_lock();
 	radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, vmf->pgoff) {
 		if (iter.index > vmf->max_pgoff)
 			break;
@@ -2477,7 +2476,25 @@ void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf)
 		if (iter.index == vmf->max_pgoff)
 			break;
 	}
+}
+
+void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+	struct file *file = vma->vm_file;
+	struct file *peer_file;
+
+	rcu_read_lock();
+	__filemap_map_pages(vma, vmf, file);
+
+	peer_file = rcu_dereference(file->f_mapping->i_peer_file);
+	if (peer_file && atomic_long_inc_not_zero(&peer_file->f_count))
+		__filemap_map_pages(vma, vmf, peer_file);
+	else
+		peer_file = NULL;
 	rcu_read_unlock();
+
+	if (peer_file)
+		fput(peer_file);
 }
 EXPORT_SYMBOL(filemap_map_pages);
 
-- 
2.24.1



More information about the Devel mailing list