[PATCH][2.6.20-rc1-mm1] sparsemem vmem_map optimzed pfn_valid() [1/2] generic arch.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch is for implementing optimized pfn_valid() for sparsemem_vmemmap.
By this, we can avoid accessing mem_section[] in usual codes.
(memory hotplug will access it.)

This patch checks vmem_map is mapped or not by get_user().
If fault, pfn is not valid.

Because sparsemem_vmemmap's virtual mem_map per section is always aligned to
PAGE_SIZE, pfn_valid(pfn) can assume a whole struct page is fully mapped.
So it only access the first byte.

How to use:
 1. set ARCH_SPARSEMEM_VMEMMAP_OPT_PFNVALID config in arch/Kconfig
 2. modify page fault handler in each arch to handle fault in mem_map range.

Signed-Off-By: KAMEZAWA Hiroyuki <[email protected]>

 include/linux/mmzone.h |   10 ++++++++++
 mm/Kconfig             |    4 ++++
 mm/sparse.c            |    7 +++++++
 3 files changed, 21 insertions(+)

Index: devel-2.6.20-rc1-mm1/include/linux/mmzone.h
===================================================================
--- devel-2.6.20-rc1-mm1.orig/include/linux/mmzone.h	2006-12-16 13:48:52.000000000 +0900
+++ devel-2.6.20-rc1-mm1/include/linux/mmzone.h	2006-12-16 14:43:08.000000000 +0900
@@ -752,12 +752,22 @@
 	return __nr_to_section(pfn_to_section_nr(pfn));
 }
 
+#ifdef CONFIG_SPARSEMEM_VMEMMAP_OPT_PFNVALID
+extern int vmemmap_test_valid(struct page *pg);
+static inline int pfn_valid(unsigned long pfn)
+{
+	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
+		return 0;
+	return vmemmap_test_valid(pfn_to_page(pfn));
+}
+#else
 static inline int pfn_valid(unsigned long pfn)
 {
 	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
 		return 0;
 	return valid_section(__nr_to_section(pfn_to_section_nr(pfn)));
 }
+#endif
 
 /*
  * These are _only_ used during initialisation, therefore they
Index: devel-2.6.20-rc1-mm1/mm/Kconfig
===================================================================
--- devel-2.6.20-rc1-mm1.orig/mm/Kconfig	2006-12-16 13:48:53.000000000 +0900
+++ devel-2.6.20-rc1-mm1/mm/Kconfig	2006-12-16 13:52:06.000000000 +0900
@@ -125,6 +125,10 @@
 	def_bool y
 	depends on ARCH_SPARSEMEM_VMEMMAP_STATIC
 
+config SPARSEMEM_VMEMMAP_OPT_PFNVALID
+	def_bool y
+	depends on SPARSEMEM_VMEMMAP && ARCH_SPARSEMEM_VMEMMAP_OPT_PFN_VALID
+
 # eventually, we can have this option just 'select SPARSEMEM'
 config MEMORY_HOTPLUG
 	bool "Allow for memory hot-add"
Index: devel-2.6.20-rc1-mm1/mm/sparse.c
===================================================================
--- devel-2.6.20-rc1-mm1.orig/mm/sparse.c	2006-12-16 13:48:53.000000000 +0900
+++ devel-2.6.20-rc1-mm1/mm/sparse.c	2006-12-16 14:03:41.000000000 +0900
@@ -108,6 +108,13 @@
 	int nid;
 };
 
+int vmemmap_test_valid(struct page *pg)
+{
+	char byte;
+	/* vmemmap per section is always aligned to PAGE_SIZE */
+	return (__get_user(byte, (char __user *)pg) == 0);
+}
+
 /* call backs for memory map */
 static int
 __init pte_alloc_vmemmap_boot(pmd_t *pmd, unsigned long addr, void *data)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux