From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@osdl.org>, Kyle McMartin <kyle@mcmartin.ca>
Subject: [PATCH] unify pfn_to_page take3 [1/23] generic functions
Date: Tue, 14 Feb 2006 18:54:52 +0900 [thread overview]
Message-ID: <43F1A8EC.6000405@jp.fujitsu.com> (raw)
In-Reply-To: <43F1A753.2020003@jp.fujitsu.com>
There are 3 memory models, FLATMEM, DISCONTIGMEM, SPARSEMEM.
Each arch defines its own page_to_pfn(), pfn_to_page() for each models.
But most of them can use the same function.
This patch adds asm-generic/memory_model.h, which defines generic
page_to_pfn(), pfn_to_page() for each memory model.
When CONFIG_OUT_OF_LINE_PFN_TO_PAGE=y, out-of-line functions are
used instead of macro. This is enabled by some archs and reduces
text size.
Signed-Off-By: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Index: testtree/include/asm-generic/memory_model.h
===================================================================
--- /dev/null
+++ testtree/include/asm-generic/memory_model.h
@@ -0,0 +1,77 @@
+#ifndef __ASM_MEMORY_MODEL_H
+#define __ASM_MEMORY_MODEL_H
+
+#ifdef __KERNEL__
+#ifndef __ASSEMBLY__
+
+#if defined(CONFIG_FLATMEM)
+
+#ifndef ARCH_PFN_OFFSET
+#define ARCH_PFN_OFFSET (0UL)
+#endif
+
+#elif defined(CONFIG_DISCONTIGMEM)
+
+#ifndef arch_pfn_to_nid
+#define arch_pfn_to_nid(pfn) pfn_to_nid(pfn)
+#endif
+
+#ifndef arch_local_page_offset
+#define arch_local_page_offset(pfn, nid) \
+ ((pfn) - NODE_DATA(nid)->node_start_pfn)
+#endif
+
+#endif /* CONFIG_DISCONTIGMEM */
+
+#ifdef CONFIG_OUT_OF_LINE_PFN_TO_PAGE
+struct page;
+/* this is useful when inlined pfn_to_page is too big */
+extern struct page *pfn_to_page(unsigned long pfn);
+extern unsigned long page_to_pfn(struct page *page);
+#else
+/*
+ * supports 3 memory models.
+ */
+#if defined(CONFIG_FLATMEM)
+
+#define pfn_to_page(pfn) (mem_map + ((pfn) - ARCH_PFN_OFFSET))
+#define page_to_pfn(page) ((unsigned long)((page) - mem_map) + \
+ ARCH_PFN_OFFSET)
+#elif defined(CONFIG_DISCONTIGMEM)
+
+#define pfn_to_page(pfn) \
+({ unsigned long __pfn = (pfn); \
+ unsigned long __nid = arch_pfn_to_nid(pfn); \
+ NODE_DATA(__nid)->node_mem_map + arch_local_page_offset(__pfn, __nid);\
+})
+
+#define page_to_pfn(pg) \
+({ struct page *__pg = (pg); \
+ struct zone *__zone = page_zone(__pg); \
+ (unsigned long)(__pg - __zone->zone_mem_map) + \
+ __zone->zone_start_pfn; \
+})
+
+#elif defined(CONFIG_SPARSEMEM)
+/*
+ * Note: section's mem_map is encorded to reflect its start_pfn.
+ * section[i].section_mem_map == mem_map's address - start_pfn;
+ */
+#define page_to_pfn(pg) \
+({ struct page *__pg = (pg); \
+ int __sec = page_to_section(__pg); \
+ __pg - __section_mem_map_addr(__nr_to_section(__sec)); \
+})
+
+#define pfn_to_page(pfn) \
+({ unsigned long __pfn = (pfn); \
+ struct mem_section *__sec = __pfn_to_section(__pfn); \
+ __section_mem_map_addr(__sec) + __pfn; \
+})
+#endif /* CONFIG_FLATMEM/DISCONTIGMEM/SPARSEMEM */
+#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */
+
+#endif /* __ASSEMBLY__ */
+#endif /* __KERNEL__ */
+
+#endif
Index: testtree/include/linux/mmzone.h
===================================================================
--- testtree.orig/include/linux/mmzone.h
+++ testtree/include/linux/mmzone.h
@@ -602,17 +602,6 @@ static inline struct mem_section *__pfn_
return __nr_to_section(pfn_to_section_nr(pfn));
}
-#define pfn_to_page(pfn) \
-({ \
- unsigned long __pfn = (pfn); \
- __section_mem_map_addr(__pfn_to_section(__pfn)) + __pfn; \
-})
-#define page_to_pfn(page) \
-({ \
- page - __section_mem_map_addr(__nr_to_section( \
- page_to_section(page))); \
-})
-
static inline int pfn_valid(unsigned long pfn)
{
if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
Index: testtree/mm/page_alloc.c
===================================================================
--- testtree.orig/mm/page_alloc.c
+++ testtree/mm/page_alloc.c
@@ -2726,3 +2726,45 @@ void *__init alloc_large_system_hash(con
return table;
}
+
+#ifdef CONFIG_OUT_OF_LINE_PFN_TO_PAGE
+/*
+ * pfn <-> page translation. out-of-line version.
+ * (see asm-generic/memory_model.h)
+ */
+#if defined(CONFIG_FLATMEM)
+struct page *pfn_to_page(unsigned long pfn)
+{
+ return mem_map + (pfn - ARCH_PFN_OFFSET);
+}
+unsigned long page_to_pfn(struct page *page)
+{
+ return (page - mem_map) + ARCH_PFN_OFFSET;
+}
+#elif defined(CONFIG_DISCONTIGMEM)
+struct page *pfn_to_page(unsigned long pfn)
+{
+ int nid = arch_pfn_to_nid(pfn);
+ return NODE_DATA(nid)->node_mem_map + arch_local_page_offset(pfn,nid);
+}
+unsigned long page_to_pfn(struct page *page)
+{
+ struct zone *zone = page_zone(page);
+ return (page - zone->zone_mem_map) + zone->zone_start_pfn;
+
+}
+#elif defined(CONFIG_SPARSEMEM)
+struct page *pfn_to_page(unsigned long pfn)
+{
+ return __section_mem_map_addr(__pfn_to_section(pfn)) + pfn;
+}
+
+unsigned long page_to_pfn(struct page *page)
+{
+ long section_id = page_to_section(page);
+ return page - __section_mem_map_addr(__nr_to_section(section_id));
+}
+#endif /* CONFIG_FLATMEM/DISCONTIGMME/SPARSEMEM */
+EXPORT_SYMBOL(pfn_to_page);
+EXPORT_SYMBOL(page_to_pfn);
+#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */
next prev parent reply other threads:[~2006-02-14 9:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-14 9:48 [PATCH] unify pfn_to_page take3 [0/23] KAMEZAWA Hiroyuki
2006-02-14 9:54 ` KAMEZAWA Hiroyuki [this message]
2006-02-14 9:56 ` [PATCH] unify pfn_to_page take3 [2/23] i386 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 9:58 ` [PATCH] unify pfn_to_page take3 [3/23] x86_64 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:02 ` [PATCH] unify pfn_to_page take3 [4/23] powerpc pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:12 ` [PATCH] unify pfn_to_page take3 [5/23] alpha pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:19 ` [PATCH] unify pfn_to_page take3 [6/23] arm pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:21 ` [PATCH] unify pfn_to_page take3 [7/23] arm26 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:23 ` [PATCH] unify pfn_to_page take3 [8/23] cris pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:25 ` [PATCH] unify pfn_to_page take3 [9/23] frv pfn_tp_page KAMEZAWA Hiroyuki
2006-02-14 10:28 ` [PATCH] unify pfn_to_page take3 [10/23] h8300 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:33 ` [PATCH] unify pfn_to_page take3 [11/23] m32r pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:36 ` [PATCH] unify pfn_to_page take3 [12/23] mips pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:40 ` [PATCH] unify pfn_to_page take3 [13/23] parisc pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:43 ` [PATCH] unify pfn_to_page take3 [14/23] ppc pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:45 ` [PATCH] unify pfn_to_page take3 [15/23] s390 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:47 ` [PATCH] unify pfn_to_page take3 [16/23] sh pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:51 ` [PATCH] unify pfn_to_page take3 [17/23] sh64 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:54 ` [PATCH] unify pfn_to_page take3 [18/23] sparc pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:56 ` [PATCH] unify pfn_to_page take3 [19/23] sparc64 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:58 ` [PATCH] unify pfn_to_page take3 [20/23] UML pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 10:59 ` [PATCH] unify pfn_to_page take3 [21/23] v850 pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 11:01 ` [PATCH] unify pfn_to_page take3 [22/23] xtensa pfn_to_page KAMEZAWA Hiroyuki
2006-02-14 11:04 ` [PATCH] unify pfn_to_page take3 [23/23] ia64 pfn_to_page KAMEZAWA Hiroyuki
2006-02-23 11:09 ` KAMEZAWA Hiroyuki
2006-02-15 5:33 ` [PATCH] unify pfn_to_page take3 [0/23] Andrew Morton
2006-02-15 5:43 ` KAMEZAWA Hiroyuki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43F1A8EC.6000405@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=akpm@osdl.org \
--cc=kyle@mcmartin.ca \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox