From: Arjan van de Ven <arjanv@redhat.com>

Create /proc/sys/vm/legacy_va_layout.  If this is non-zero, the kernel will
use the old mmap layout for all tasks.  it presently defaults to zero (the new
layout).

Signed-off-by: Ingo Molnar <mingo@elte.hu>
DESC
legacy_va_layout docs
EDESC

- Add documentation.

- It's an x86-only feature, so don't offer the sysctl on other architectures.
DESC
legacy_va_layout-docs-fix
EDESC
DESC
legacy_va_layout compile error with SYSCTL=n
EDESC
From: William Lee Irwin III <wli@holomorphy.com>

hugetlb CONFIG_SYSCTL=n fix, take 2: the real thing.
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/Documentation/filesystems/proc.txt |    6 ++++++
 25-akpm/arch/i386/mm/mmap.c                |    3 ++-
 25-akpm/include/asm-i386/page.h            |    4 ++--
 25-akpm/include/linux/mm.h                 |    6 ++++++
 25-akpm/include/linux/sysctl.h             |    1 +
 25-akpm/kernel/sysctl.c                    |   17 +++++++++++++++++
 25-akpm/mm/hugetlb.c                       |    2 +-
 7 files changed, 35 insertions(+), 4 deletions(-)

diff -puN arch/i386/mm/mmap.c~sysctl-tunable-for-flexmmap arch/i386/mm/mmap.c
--- 25/arch/i386/mm/mmap.c~sysctl-tunable-for-flexmmap	2004-08-20 01:25:11.107792128 -0700
+++ 25-akpm/arch/i386/mm/mmap.c	2004-08-20 01:25:11.125789392 -0700
@@ -57,7 +57,8 @@ void arch_pick_mmap_layout(struct mm_str
 	 * Fall back to the standard layout if the personality
 	 * bit is set, or if the expected stack growth is unlimited:
 	 */
-	if ((current->personality & ADDR_COMPAT_LAYOUT) ||
+	if (sysctl_legacy_va_layout ||
+			(current->personality & ADDR_COMPAT_LAYOUT) ||
 			current->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY) {
 		mm->mmap_base = TASK_UNMAPPED_BASE;
 		mm->get_unmapped_area = arch_get_unmapped_area;
diff -puN include/linux/mm.h~sysctl-tunable-for-flexmmap include/linux/mm.h
--- 25/include/linux/mm.h~sysctl-tunable-for-flexmmap	2004-08-20 01:25:11.110791672 -0700
+++ 25-akpm/include/linux/mm.h	2004-08-20 01:25:11.127789088 -0700
@@ -26,6 +26,12 @@ extern void * high_memory;
 extern unsigned long vmalloc_earlyreserve;
 extern int page_cluster;
 
+#ifdef CONFIG_SYSCTL
+extern int sysctl_legacy_va_layout;
+#else
+#define sysctl_legacy_va_layout 0
+#endif
+
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include <asm/processor.h>
diff -puN include/linux/sysctl.h~sysctl-tunable-for-flexmmap include/linux/sysctl.h
--- 25/include/linux/sysctl.h~sysctl-tunable-for-flexmmap	2004-08-20 01:25:11.113791216 -0700
+++ 25-akpm/include/linux/sysctl.h	2004-08-20 01:25:11.128788936 -0700
@@ -167,6 +167,7 @@ enum
 	VM_BLOCK_DUMP=24,	/* block dump mode */
 	VM_HUGETLB_GROUP=25,	/* permitted hugetlb group */
 	VM_VFS_CACHE_PRESSURE=26, /* dcache/icache reclaim pressure */
+	VM_LEGACY_VA_LAYOUT=27, /* legacy/compatibility virtual address space layout */
 };
 
 
diff -puN kernel/sysctl.c~sysctl-tunable-for-flexmmap kernel/sysctl.c
--- 25/kernel/sysctl.c~sysctl-tunable-for-flexmmap	2004-08-20 01:25:11.116790760 -0700
+++ 25-akpm/kernel/sysctl.c	2004-08-20 01:25:11.131788480 -0700
@@ -42,6 +42,7 @@
 #include <linux/dcache.h>
 
 #include <asm/uaccess.h>
+#include <asm/processor.h>
 
 #ifdef CONFIG_ROOT_NFS
 #include <linux/nfs_fs.h>
@@ -152,6 +153,10 @@ extern ctl_table random_table[];
 extern ctl_table pty_table[];
 #endif
 
+#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
+int sysctl_legacy_va_layout;
+#endif
+
 /* /proc declarations: */
 
 #ifdef CONFIG_PROC_FS
@@ -820,6 +825,18 @@ static ctl_table vm_table[] = {
 		.strategy	= &sysctl_intvec,
 		.extra1		= &zero,
 	},
+#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
+	{
+		.ctl_name	= VM_LEGACY_VA_LAYOUT,
+		.procname	= "legacy_va_layout",
+		.data		= &sysctl_legacy_va_layout,
+		.maxlen		= sizeof(sysctl_legacy_va_layout),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+		.strategy	= &sysctl_intvec,
+		.extra1		= &zero,
+	},
+#endif
 	{ .ctl_name = 0 }
 };
 
diff -puN Documentation/filesystems/proc.txt~sysctl-tunable-for-flexmmap Documentation/filesystems/proc.txt
--- 25/Documentation/filesystems/proc.txt~sysctl-tunable-for-flexmmap	2004-08-20 01:25:11.118790456 -0700
+++ 25-akpm/Documentation/filesystems/proc.txt	2004-08-20 01:25:11.133788176 -0700
@@ -1174,6 +1174,12 @@ for writeout by the pdflush daemons.  It
 Data which has been dirty in-memory for longer than this interval will be
 written out next time a pdflush daemon wakes up.
 
+legacy_va_layout
+----------------
+
+If non-zero, this sysctl disables the new 32-bit mmap mmap layout - the kernel
+will use the legacy (2.4) layout for all processes.
+
 lower_zone_protection
 ---------------------
 
diff -puN include/asm-i386/page.h~sysctl-tunable-for-flexmmap include/asm-i386/page.h
--- 25/include/asm-i386/page.h~sysctl-tunable-for-flexmmap	2004-08-20 01:25:11.120790152 -0700
+++ 25-akpm/include/asm-i386/page.h	2004-08-20 01:25:11.134788024 -0700
@@ -118,6 +118,8 @@ static __inline__ int get_order(unsigned
 
 extern int devmem_is_allowed(unsigned long pagenr);
 
+extern int sysctl_legacy_va_layout;
+
 #endif /* __ASSEMBLY__ */
 
 #ifdef __ASSEMBLY__
@@ -147,8 +149,6 @@ extern int devmem_is_allowed(unsigned lo
 	((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
 		 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 
-
-
 #endif /* __KERNEL__ */
 
 #endif /* _I386_PAGE_H */
diff -puN mm/hugetlb.c~sysctl-tunable-for-flexmmap mm/hugetlb.c
--- 25/mm/hugetlb.c~sysctl-tunable-for-flexmmap	2004-08-20 01:25:11.122789848 -0700
+++ 25-akpm/mm/hugetlb.c	2004-08-20 01:25:11.135787872 -0700
@@ -123,6 +123,7 @@ static int __init hugetlb_setup(char *s)
 }
 __setup("hugepages=", hugetlb_setup);
 
+#ifdef CONFIG_SYSCTL
 static void update_and_free_page(struct page *page)
 {
 	int i;
@@ -188,7 +189,6 @@ static unsigned long set_max_huge_pages(
 	return nr_huge_pages;
 }
 
-#ifdef CONFIG_SYSCTL
 int hugetlb_sysctl_handler(struct ctl_table *table, int write,
 			   struct file *file, void __user *buffer,
 			   size_t *length, loff_t *ppos)
_