Skip to contentSkip to conversation

Page Cache Policy V0.0 4/5 add generic file set/get policy vm ops

PATCH/RFC Lee Schermerhorn 1 participant 1 message Apr 20, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Page Cache Policy V0.0 4/5 add generic file set/get policy vm ops

Add set/get policy vm ops to generic_file_vm_ops in support of mmap()ed file memory policies.

Note that these ops are identical in all but name to the shmem policy vm ops as modified by this series. Perhaps shmem could use the "generic" ones if this series is eventually accepted.

mm/filemap.c +28 -0
Index: linux-2.6.17-rc1-mm2/mm/filemap.c
===================================================================
@@ -31,6 +31,7 @@
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/cpuset.h>
+#include <linux/mempolicy.h>
 #include "filemap.h"
 #include "internal.h"
 
@@ -457,6 +458,29 @@ struct page *page_cache_alloc_cold(struc
 	return alloc_pages(mapping_gfp_mask(x)|__GFP_COLD, 0);
 }
 EXPORT_SYMBOL(page_cache_alloc_cold);
+
+int generic_file_set_policy(struct vm_area_struct *vma, unsigned long start,
+			unsigned long end, struct mempolicy *new)
+{
+	struct shared_policy *sp = vma->vm_file->f_mapping->spolicy;
+
+	if (!sp) {
+		sp = mpol_shared_policy_new(MPOL_DEFAULT, NULL);
+		vma->vm_file->f_mapping->spolicy = sp;
+	}
+	return mpol_set_shared_policy(sp, vma, start, end, new);
+}
+
+struct mempolicy *
+generic_file_get_policy(struct vm_area_struct *vma, unsigned long addr)
+{
+	struct shared_policy *sp = vma->vm_file->f_mapping->spolicy;
+	if (!sp)
+		return NULL;
+
+	return mpol_shared_policy_lookup(sp,
+				 vma_addr_to_pgoff(vma, addr, PAGE_SHIFT));
+}
 #endif
 
 /*
@@ -1614,6 +1638,10 @@ EXPORT_SYMBOL(filemap_populate);
 struct vm_operations_struct generic_file_vm_ops = {
 	.nopage		= filemap_nopage,
 	.populate	= filemap_populate,
+#ifdef CONFIG_NUMA
+	.set_policy     = generic_file_set_policy,
+	.get_policy     = generic_file_get_policy,
+#endif
 };
 
 /* This is used for a general mmap of a disk file */

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>