Skip to contentSkip to conversation

Page Cache Policy V0.0 5/5 - use file policy for page cache

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

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

Page Cache Policy V0.0 5/5 - use file policy for page cache

This patch implements a "get_file_policy()" function, analogous to get_vma_policy(), but for a given file[inode/mapping] at at specified offset, using the shared_policy, if any, in the file's address_space. If no shared policy, returns the default policy.

Implement alloc_page_pol() to allocate a page given a policy and
an offset. No vma,addr needed. alloc_page_pol() duplicated some
of the code in alloc_page_vma(), so this patch revises alloc_page_vma() to just call alloc_page_pol() after looking up the policy. This change rippled into the interleaving functions. Was able to eliminate interleave_nid() by computing the offset at the call sites and calling [modified] offset_il_node() directly.

	#if out interleave_nid() for now.  If noone complains,
	we can remove it.

Enhance page_cache_alloc[_cold]() to use get_file_policy() and alloc_page_pol(). Because this would have duplicated a fair bit of code, the patch extracts the common bits into __page_cache_alloc() and passes the __GFP_COLD flag when called from page_cache_alloc_cold(), 0 otherwise.

page_cache_alloc[_cold]() now take an additional offset/index argument, available at all call sites, to lookup the appropriate policy. The patches fixes all in kernel users of the modified interfaces.

mm/filemap.c +39 -14
Index: linux-2.6.17-rc1-mm2/mm/filemap.c
===================================================================
@@ -439,23 +439,48 @@ int add_to_page_cache_lru(struct page *p
 }
 
 #ifdef CONFIG_NUMA
-struct page *page_cache_alloc(struct address_space *x)
+/*
+ * Return effective policy for file [address_space] at pgoff
+ */
+static struct mempolicy *get_file_policy(struct address_space *x, pgoff_t pgoff)
+{
+	struct shared_policy *sp = x->spolicy;
+	struct mempolicy *pol = NULL;
+
+	if (sp)
+		pol = mpol_shared_policy_lookup(sp, pgoff);
+	if (pol)
+		return pol;
+
+	return &default_policy;
+}
+
+static struct page *__page_cache_alloc(struct address_space *x, pgoff_t pgoff,
+					int cold)
 {
-	if (cpuset_do_page_mem_spread()) {
+	struct mempolicy *pol = get_file_policy(x, pgoff);
+	gfp_t gfp = mapping_gfp_mask(x) | cold;
+
+	/*
+	 * Only spread if default policy
+	 */
+	if (pol->policy == MPOL_DEFAULT && cpuset_do_page_mem_spread()) {
 		int n = cpuset_mem_spread_node();
-		return alloc_pages_node(n, mapping_gfp_mask(x), 0);
+		return alloc_pages_node(n, gfp, 0);
 	}
-	return alloc_pages(mapping_gfp_mask(x), 0);
+
+	return alloc_page_pol(gfp, pol, pgoff);
+}
+
+struct page *page_cache_alloc(struct address_space *x, pgoff_t pgoff)
+{
+	return __page_cache_alloc(x, pgoff, 0);
 }
 EXPORT_SYMBOL(page_cache_alloc);
 
-struct page *page_cache_alloc_cold(struct address_space *x)
+struct page *page_cache_alloc_cold(struct address_space *x, pgoff_t pgoff)
 {
-	if (cpuset_do_page_mem_spread()) {
-		int n = cpuset_mem_spread_node();
-		return alloc_pages_node(n, mapping_gfp_mask(x)|__GFP_COLD, 0);
-	}
-	return alloc_pages(mapping_gfp_mask(x)|__GFP_COLD, 0);
+	return __page_cache_alloc(x, pgoff, __GFP_COLD);
 }
 EXPORT_SYMBOL(page_cache_alloc_cold);
 
@@ -973,7 +998,7 @@ no_cached_page:
 		 * page..
 		 */
 		if (!cached_page) {
-			cached_page = page_cache_alloc_cold(mapping);
+			cached_page = page_cache_alloc_cold(mapping, index);
 			if (!cached_page) {
 				desc->error = -ENOMEM;
 				goto out;
@@ -1237,7 +1262,7 @@ static int fastcall page_cache_read(stru
 	int ret;
 
 	do {
-		page = page_cache_alloc_cold(mapping);
+		page = page_cache_alloc_cold(mapping, offset);
 		if (!page)
 			return -ENOMEM;
 
@@ -1691,7 +1716,7 @@ repeat:
 	page = find_get_page(mapping, index);
 	if (!page) {
 		if (!cached_page) {
-			cached_page = page_cache_alloc_cold(mapping);
+			cached_page = page_cache_alloc_cold(mapping, index);
 			if (!cached_page)
 				return ERR_PTR(-ENOMEM);
 		}
@@ -1773,7 +1798,7 @@ repeat:
 	page = find_lock_page(mapping, index);
 	if (!page) {
 		if (!*cached_page) {
-			*cached_page = page_cache_alloc(mapping);
+			*cached_page = page_cache_alloc(mapping, index);
 			if (!*cached_page)
 				return NULL;
 		}
include/linux/gfp.h +3 -0
Index: linux-2.6.17-rc1-mm2/include/linux/gfp.h
===================================================================
@@ -133,10 +133,13 @@ alloc_pages(gfp_t gfp_mask, unsigned int
 }
 extern struct page *alloc_page_vma(gfp_t gfp_mask,
 			struct vm_area_struct *vma, unsigned long addr);
+struct mempolicy;
+extern struct page *alloc_page_pol(gfp_t, struct mempolicy *, pgoff_t);
 #else
 #define alloc_pages(gfp_mask, order) \
 		alloc_pages_node(numa_node_id(), gfp_mask, order)
 #define alloc_page_vma(gfp_mask, vma, addr) alloc_pages(gfp_mask, 0)
+#define alloc_page_pol(gfp_mask, pol, off)  alloc_pages(gfp_mask, 0)
 #endif
 #define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
 
mm/mempolicy.c +30 -13

84 lines not on this page · raw message

include/linux/pagemap.h +6 -4
Index: linux-2.6.17-rc1-mm2/include/linux/pagemap.h
===================================================================
@@ -52,15 +52,17 @@ static inline void mapping_set_gfp_mask(
 void release_pages(struct page **pages, int nr, int cold);
 
 #ifdef CONFIG_NUMA
-extern struct page *page_cache_alloc(struct address_space *x);
-extern struct page *page_cache_alloc_cold(struct address_space *x);
+extern struct page *page_cache_alloc(struct address_space *, pgoff_t);
+extern struct page *page_cache_alloc_cold(struct address_space *, pgoff_t);
 #else
-static inline struct page *page_cache_alloc(struct address_space *x)
+static inline struct page *page_cache_alloc(struct address_space *x,
+						pgoff_t off)
 {
 	return alloc_pages(mapping_gfp_mask(x), 0);
 }
 
-static inline struct page *page_cache_alloc_cold(struct address_space *x)
+static inline struct page *page_cache_alloc_cold(struct address_space *x,
+						pgoff_t off)
 {
 	return alloc_pages(mapping_gfp_mask(x)|__GFP_COLD, 0);
 }
drivers/mtd/devices/block2mtd.c +1 -1
Index: linux-2.6.17-rc1-mm2/drivers/mtd/devices/block2mtd.c
===================================================================
@@ -72,7 +72,7 @@ static void cache_readahead(struct addre
 		if (page)
 			continue;
 		read_unlock_irq(&mapping->tree_lock);
-		page = page_cache_alloc_cold(mapping);
+		page = page_cache_alloc_cold(mapping, pagei);
 		read_lock_irq(&mapping->tree_lock);
 		if (!page)
 			break;
fs/splice.c +1 -1
Index: linux-2.6.17-rc1-mm2/fs/splice.c
===================================================================
@@ -278,7 +278,7 @@ find_page:
 			/*
 			 * page didn't exist, allocate one
 			 */
-			page = page_cache_alloc_cold(mapping);
+			page = page_cache_alloc_cold(mapping, index);
 			if (!page)
 				break;
 
mm/readahead.c +1 -1
Index: linux-2.6.17-rc1-mm2/mm/readahead.c
===================================================================
@@ -298,7 +298,7 @@ __do_page_cache_readahead(struct address
 			continue;
 
 		read_unlock_irq(&mapping->tree_lock);
-		page = page_cache_alloc_cold(mapping);
+		page = page_cache_alloc_cold(mapping, page_offset);
 		read_lock_irq(&mapping->tree_lock);
 		if (!page)
 			break;
fs/ntfs/file.c +1 -1
Index: linux-2.6.17-rc1-mm2/fs/ntfs/file.c
===================================================================
@@ -425,7 +425,7 @@ static inline int __ntfs_grab_cache_page
 		pages[nr] = find_lock_page(mapping, index);
 		if (!pages[nr]) {
 			if (!*cached_page) {
-				*cached_page = page_cache_alloc(mapping);
+				*cached_page = page_cache_alloc(mapping, index);
 				if (unlikely(!*cached_page)) {
 					err = -ENOMEM;
 					goto err_out;

--
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>