Skip to contentSkip to conversation

More convenient way to grab hugepage memory

PATCH David Gibson 6 participants 14 messages May 13, 2004

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

Andrew, please apply:

At present, getting a block of (quasi-) anonymous memory mapping with hugepages is a slightly convoluted process, involving creating a dummy file in a hugetlbfs filesystem. In particular that means finding where such a filesystem is mounted, for which there is no standard mechanism. Getting hugepage SysV shm segments is easier, just requing the SHM_HUGETLB flag. This patch adds an analagous MAP_HUGETLB mmap() flag to easily request that a block of anonymous memory come from hugepages.

[The MAP_HUGETLB flag has the side effect that MAP_SHARED semantics will apply, even if MAP_PRIVATE is specific - but that's no different to explicitly mapping hugetlbfs].

include/asm-i386/mman.h +1 -0
Index: working-2.6/include/asm-i386/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed by hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-ppc64/mman.h +1 -0
Index: working-2.6/include/asm-ppc64/mman.h
===================================================================
@@ -26,6 +26,7 @@
 #define MAP_LOCKED	0x80
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 
include/linux/mman.h +3 -0
Index: working-2.6/include/linux/mman.h
===================================================================
@@ -58,6 +58,9 @@
 	return _calc_vm_trans(flags, MAP_GROWSDOWN,  VM_GROWSDOWN ) |
 	       _calc_vm_trans(flags, MAP_DENYWRITE,  VM_DENYWRITE ) |
 	       _calc_vm_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE) |
+#ifdef CONFIG_HUGETLB_PAGE
+               _calc_vm_trans(flags, MAP_HUGETLB,    VM_HUGETLB   ) |
+#endif
 	       _calc_vm_trans(flags, MAP_LOCKED,     VM_LOCKED    );
 }
 
include/asm-sh/mman.h +1 -0
Index: working-2.6/include/asm-sh/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-ia64/mman.h +1 -0
Index: working-2.6/include/asm-ia64/mman.h
===================================================================
@@ -24,6 +24,7 @@
 
 #define MAP_GROWSDOWN	0x00100		/* stack-like segment */
 #define MAP_GROWSUP	0x00200		/* register stack-like segment */
+#define MAP_HUGETLB	0x00400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x00800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x01000		/* mark it as an executable */
 #define MAP_LOCKED	0x02000		/* pages are locked */
include/asm-sparc64/mman.h +1 -0
Index: working-2.6/include/asm-sparc64/mman.h
===================================================================
@@ -24,6 +24,7 @@
 #define _MAP_NEW        0x80000000      /* Binary compatibility is fun... */
 
 #define MAP_GROWSDOWN	0x0200		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 
include/asm-x86_64/mman.h +1 -0
Index: working-2.6/include/asm-x86_64/mman.h
===================================================================
@@ -17,6 +17,7 @@
 #define MAP_32BIT	0x40		/* only give out 32bit addresses */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-ppc/mman.h +1 -0
Index: working-2.6/include/asm-ppc/mman.h
===================================================================
@@ -19,6 +19,7 @@
 #define MAP_LOCKED	0x80
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
include/asm-alpha/mman.h +1 -0
Index: working-2.6/include/asm-alpha/mman.h
===================================================================
@@ -28,6 +28,7 @@
 #define MAP_NORESERVE	0x10000		/* don't check for reservations */
 #define MAP_POPULATE	0x20000		/* populate (prefault) pagetables */
 #define MAP_NONBLOCK	0x40000		/* do not block on IO */
+#define MAP_HUGETLB	0x80000		/* Backed with hugetlb pages */
 
 #define MS_ASYNC	1		/* sync memory asynchronously */
 #define MS_SYNC		2		/* synchronous memory sync */
include/asm-arm/mman.h +1 -0
Index: working-2.6/include/asm-arm/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-arm26/mman.h +1 -0
Index: working-2.6/include/asm-arm26/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-cris/mman.h +1 -0
Index: working-2.6/include/asm-cris/mman.h
===================================================================
@@ -18,6 +18,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-h8300/mman.h +1 -0
Index: working-2.6/include/asm-h8300/mman.h
===================================================================
@@ -15,6 +15,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-m68k/mman.h +1 -0
Index: working-2.6/include/asm-m68k/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-mips/mman.h +1 -0
Index: working-2.6/include/asm-mips/mman.h
===================================================================
@@ -38,6 +38,7 @@
 #define MAP_AUTORSRV	0x100		/* Logical swap reserved on demand */
 
 /* These are linux-specific */
+#define MAP_HUGETLB	0x0200		/* Backed with hugetlb pages */
 #define MAP_NORESERVE	0x0400		/* don't check for reservations */
 #define MAP_ANONYMOUS	0x0800		/* don't use a file */
 #define MAP_GROWSDOWN	0x1000		/* stack-like segment */
include/asm-parisc/mman.h +1 -0
Index: working-2.6/include/asm-parisc/mman.h
===================================================================
@@ -15,6 +15,7 @@
 #define MAP_FIXED	0x04		/* Interpret addr exactly */
 #define MAP_ANONYMOUS	0x10		/* don't use a file */
 
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-s390/mman.h +1 -0
Index: working-2.6/include/asm-s390/mman.h
===================================================================
@@ -24,6 +24,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-sparc/mman.h +1 -0
Index: working-2.6/include/asm-sparc/mman.h
===================================================================
@@ -24,6 +24,7 @@
 #define _MAP_NEW        0x80000000      /* Binary compatibility is fun... */
 
 #define MAP_GROWSDOWN	0x0200		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 
include/asm-v850/mman.h +1 -0
Index: working-2.6/include/asm-v850/mman.h
===================================================================
@@ -15,6 +15,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
mm/mmap.c +80 -39

162 lines not on this page · raw message

Signature · 4 lines
David Gibson			| For every complex problem there is a
david AT gibson.dropbear.id.au	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson
#1 lore raw

mm/mmap.c line 67

Quoted 2 lines · David Gibson
mm/mmap.c +2 -0
+int mmap_use_hugepages = 0;
+int mmap_hugepages_map_sz = 256;

These aren't used anywhere else in your patch; any chance you could nuke them?

Thanks.

-- wli

#2 lore raw
Quoted 3 lines · William Lee Irwin III

These aren't used anywhere else in your patch; any chance you could nuke them?
Thanks.

Here is a rediff vs. 2.6.6-mm1 (1 reject resolved) with the removal of the global variables included:

-- wli

At present, getting a block of (quasi-) anonymous memory mapping with hugepages is a slightly convoluted process, involving creating a dummy file in a hugetlbfs filesystem. In particular that means finding where such a filesystem is mounted, for which there is no standard mechanism. Getting hugepage SysV shm segments is easier, just requing the SHM_HUGETLB flag. This patch adds an analagous MAP_HUGETLB mmap() flag to easily request that a block of anonymous memory come from hugepages.

[The MAP_HUGETLB flag has the side effect that MAP_SHARED semantics will apply, even if MAP_PRIVATE is specific - but that's no different to explicitly mapping hugetlbfs].

mm/mmap.c +77 -39
diff -u wli-2.6.6-mm1/mm/mmap.c wli-2.6.6-mm1/mm/mmap.c
@@ -22,6 +22,7 @@
 #include <linux/module.h>
 #include <linux/mount.h>
 #include <linux/mempolicy.h>
+#include <linux/err.h>
 
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
@@ -528,13 +529,9 @@
 	return NULL;
 }
 
-/*
- * The caller must hold down_write(current->mm->mmap_sem).
- */
-
-unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
-			unsigned long len, unsigned long prot,
-			unsigned long flags, unsigned long pgoff)
+static inline unsigned long __do_mmap_pgoff(struct file * file, unsigned long addr,
+					    unsigned long len, unsigned long prot,
+					    unsigned long flags, unsigned long pgoff)
 {
 	struct mm_struct * mm = current->mm;
 	struct vm_area_struct * vma, * prev;
@@ -546,40 +543,19 @@
 	int accountable = 1;
 	unsigned long charged = 0;
 
-	if (file) {
-		if (is_file_hugepages(file))
-			accountable = 0;
-
-		if (!file->f_op || !file->f_op->mmap)
-			return -ENODEV;
-
-		if ((prot & PROT_EXEC) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
-			return -EPERM;
-	}
-
-	if (!len)
-		return addr;
-
-	/* Careful about overflows.. */
-	len = PAGE_ALIGN(len);
-	if (!len || len > TASK_SIZE)
-		return -EINVAL;
-
-	/* offset overflow? */
-	if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
-		return -EINVAL;
-
-	/* Too many mappings? */
-	if (mm->map_count > sysctl_max_map_count)
-		return -ENOMEM;
-
-	/* Obtain the address to map to. we verify (or select) it and ensure
-	 * that it represents a valid section of the address space.
+	/* Obtain the address to map to. we verify (or select) it and
+	 * ensure that it represents a valid section of the address
+	 * space.  VM_HUGETLB will never appear in vm_flags when
+	 * CONFIG_HUGETLB is unset.
 	 */
 	addr = get_unmapped_area(file, addr, len, pgoff, flags);
 	if (addr & ~PAGE_MASK)
 		return addr;
 
+	/* Huge pages aren't accounted for here */
+	if (file && is_file_hugepages(file))
+		accountable = 0;
+
 	/* Do simple checking here so the lower-level routines won't have
 	 * to. we assume access permissions have been handled by the open
 	 * of the memory object, so we don't do any here.
@@ -776,11 +752,17 @@
 unmap_and_free_vma:
 	if (correct_wcount)
 		atomic_inc(&inode->i_writecount);
-	vma->vm_file = NULL;
-	fput(file);
 
-	/* Undo any partial mapping done by a device driver. */
+	/*
+	 * Undo any partial mapping done by a device driver.  
+	 * hugetlb wants to know the vma's file etc. so nuke  
+	 * the file afterward.                                
+	 */                                                   
 	zap_page_range(vma, vma->vm_start, vma->vm_end - vma->vm_start, NULL);
+
+	if (file)
+		fput(vma->vm_file); 
+
 free_vma:
 	kmem_cache_free(vm_area_cachep, vma);
 unacct_error:
@@ -789,6 +771,62 @@
 	return error;
 }
 
+/*
+ * The caller must hold down_write(current->mm->mmap_sem).
+ */
+
+unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
+			unsigned long len, unsigned long prot,
+			unsigned long flags, unsigned long pgoff)
+{
+	struct file *hugetlb_file = NULL;
+	unsigned long result;
+
+	if (file) {
+		if ((flags & MAP_HUGETLB) && !is_file_hugepages(file))
+			return -EINVAL;
+
+		if (!file->f_op || !file->f_op->mmap)
+			return -ENODEV;
+
+		if ((prot & PROT_EXEC) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
+			return -EPERM;
+	}
+
+	if (!len)
+		return addr;
+
+	/* Careful about overflows.. */
+	len = PAGE_ALIGN(len);
+	if (!len || len > TASK_SIZE)
+		return -EINVAL;
+
+	/* offset overflow? */
+	if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
+		return -EINVAL;
+
+	/* Too many mappings? */
+	if (current->mm->map_count > sysctl_max_map_count)
+		return -ENOMEM;
+
+	/* Create an implicit hugetlb file if necessary */
+	if (!file && (flags & MAP_HUGETLB)) {
+		file = hugetlb_file = hugetlb_zero_setup(len);
+		if (IS_ERR(file))
+			return PTR_ERR(file);
+	}
+
+	result = __do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+
+	/* Drop reference to implicit hugetlb file, it's already been
+	 * "gotten" in __do_mmap_pgoff in case of success
+	 */
+	if (hugetlb_file)
+		fput(hugetlb_file);
+
+	return result;
+}
+
 EXPORT_SYMBOL(do_mmap_pgoff);
 
 /* Get an address range which is currently unmapped.

unchanged:

include/asm-i386/mman.h +1 -0
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed by hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-ppc64/mman.h +1 -0
@@ -26,6 +26,7 @@
 #define MAP_LOCKED	0x80
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 

unchanged:

include/linux/mman.h +3 -0
@@ -58,6 +58,9 @@
 	return _calc_vm_trans(flags, MAP_GROWSDOWN,  VM_GROWSDOWN ) |
 	       _calc_vm_trans(flags, MAP_DENYWRITE,  VM_DENYWRITE ) |
 	       _calc_vm_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE) |
+#ifdef CONFIG_HUGETLB_PAGE
+               _calc_vm_trans(flags, MAP_HUGETLB,    VM_HUGETLB   ) |
+#endif
 	       _calc_vm_trans(flags, MAP_LOCKED,     VM_LOCKED    );
 }
 

unchanged:

include/asm-sh/mman.h +1 -0
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-ia64/mman.h +1 -0
@@ -24,6 +24,7 @@
 
 #define MAP_GROWSDOWN	0x00100		/* stack-like segment */
 #define MAP_GROWSUP	0x00200		/* register stack-like segment */
+#define MAP_HUGETLB	0x00400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x00800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x01000		/* mark it as an executable */
 #define MAP_LOCKED	0x02000		/* pages are locked */

unchanged:

include/asm-sparc64/mman.h +1 -0
@@ -24,6 +24,7 @@
 #define _MAP_NEW        0x80000000      /* Binary compatibility is fun... */
 
 #define MAP_GROWSDOWN	0x0200		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 

unchanged:

include/asm-x86_64/mman.h +1 -0
@@ -17,6 +17,7 @@
 #define MAP_32BIT	0x40		/* only give out 32bit addresses */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-ppc/mman.h +1 -0
@@ -19,6 +19,7 @@
 #define MAP_LOCKED	0x80
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_POPULATE	0x8000		/* populate (prefault) pagetables */

unchanged:

include/asm-alpha/mman.h +1 -0
@@ -28,6 +28,7 @@
 #define MAP_NORESERVE	0x10000		/* don't check for reservations */
 #define MAP_POPULATE	0x20000		/* populate (prefault) pagetables */
 #define MAP_NONBLOCK	0x40000		/* do not block on IO */
+#define MAP_HUGETLB	0x80000		/* Backed with hugetlb pages */
 
 #define MS_ASYNC	1		/* sync memory asynchronously */
 #define MS_SYNC		2		/* synchronous memory sync */

unchanged:

include/asm-arm/mman.h +1 -0
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-arm26/mman.h +1 -0
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-cris/mman.h +1 -0
@@ -18,6 +18,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-h8300/mman.h +1 -0
@@ -15,6 +15,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-m68k/mman.h +1 -0
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-mips/mman.h +1 -0
@@ -38,6 +38,7 @@
 #define MAP_AUTORSRV	0x100		/* Logical swap reserved on demand */
 
 /* These are linux-specific */
+#define MAP_HUGETLB	0x0200		/* Backed with hugetlb pages */
 #define MAP_NORESERVE	0x0400		/* don't check for reservations */
 #define MAP_ANONYMOUS	0x0800		/* don't use a file */
 #define MAP_GROWSDOWN	0x1000		/* stack-like segment */

unchanged:

include/asm-parisc/mman.h +1 -0
@@ -15,6 +15,7 @@
 #define MAP_FIXED	0x04		/* Interpret addr exactly */
 #define MAP_ANONYMOUS	0x10		/* don't use a file */
 
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-s390/mman.h +1 -0
@@ -24,6 +24,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */

unchanged:

include/asm-sparc/mman.h +1 -0
@@ -24,6 +24,7 @@
 #define _MAP_NEW        0x80000000      /* Binary compatibility is fun... */
 
 #define MAP_GROWSDOWN	0x0200		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 

unchanged:

include/asm-v850/mman.h +1 -0
@@ -15,6 +15,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
#3 lore raw
In reply to David Gibson
Quoted 11 lines · David Gibson
mm/mmap.c +1 -0
@@ -21,6 +21,7 @@
 #include <linux/profile.h>
 #include <linux/module.h>
 #include <linux/mount.h>
+#include <linux/err.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>

mm/mmap.c line 67

Quoted 5 lines
mm/mmap.c +2 -0
@@ -62,6 +63,9 @@
 EXPORT_SYMBOL(sysctl_max_map_count);
 EXPORT_SYMBOL(vm_committed_space);
 
+int mmap_use_hugepages = 0;
+int mmap_hugepages_map_sz = 256;

These two global variables do not appear to be used anywhere in this patch?

mm/mmap.c line 483

Quoted 1 line
mm/mmap.c +1 -0
+static inline unsigned long __do_mmap_pgoff(struct file * file, unsigned long addr,

__do_mmap_pgoff seems rather long to be inline?

Cheers,
Muli

Signature · 2 lines
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/
#4 lore raw
Quoted 15 lines · Muli Ben-Yehuda
Quoted 13 lines · David Gibson

+++ working-2.6/mm/mmap.c 2004-04-27 13:40:01.062285976 +1000

(quoted diff) +1 -0
@@ -21,6 +21,7 @@
 #include <linux/profile.h>
 #include <linux/module.h>
 #include <linux/mount.h>
+#include <linux/err.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
@@ -62,6 +63,9 @@
 EXPORT_SYMBOL(sysctl_max_map_count);
 EXPORT_SYMBOL(vm_committed_space);
 
Quoted 5 lines

Review line 67

Quoted 2 lines
(quoted diff) +2 -0
+int mmap_use_hugepages = 0;
+int mmap_hugepages_map_sz = 256;

These two global variables do not appear to be used anywhere in this patch?

Bother, they leaked in there from the other patch I had on top of this. Revised version below.

Quoted 3 lines

Review line 68

Quoted 1 line
(quoted diff) +1 -0
+static inline unsigned long __do_mmap_pgoff(struct file * file, unsigned long addr,

__do_mmap_pgoff seems rather long to be inline?

Well, it's only called in one place - it's really the one function, just split up to let us put the wrapper creating the hugetlb file in the right place without excessive indentation. I guess it doesn't really matter, with -funit-at-a-time it will end up the same anyway.

Add a new MAP_HUGETLB mmap() flag to easily request that a block of anonymous memory come from hugepages.

include/asm-i386/mman.h +1 -0
Index: working-2.6/include/asm-i386/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed by hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-ppc64/mman.h +1 -0
Index: working-2.6/include/asm-ppc64/mman.h
===================================================================
@@ -26,6 +26,7 @@
 #define MAP_LOCKED	0x80
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 
include/linux/mman.h +3 -0
Index: working-2.6/include/linux/mman.h
===================================================================
@@ -58,6 +58,9 @@
 	return _calc_vm_trans(flags, MAP_GROWSDOWN,  VM_GROWSDOWN ) |
 	       _calc_vm_trans(flags, MAP_DENYWRITE,  VM_DENYWRITE ) |
 	       _calc_vm_trans(flags, MAP_EXECUTABLE, VM_EXECUTABLE) |
+#ifdef CONFIG_HUGETLB_PAGE
+               _calc_vm_trans(flags, MAP_HUGETLB,    VM_HUGETLB   ) |
+#endif
 	       _calc_vm_trans(flags, MAP_LOCKED,     VM_LOCKED    );
 }
 
include/asm-sh/mman.h +1 -0
Index: working-2.6/include/asm-sh/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-ia64/mman.h +1 -0
Index: working-2.6/include/asm-ia64/mman.h
===================================================================
@@ -24,6 +24,7 @@
 
 #define MAP_GROWSDOWN	0x00100		/* stack-like segment */
 #define MAP_GROWSUP	0x00200		/* register stack-like segment */
+#define MAP_HUGETLB	0x00400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x00800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x01000		/* mark it as an executable */
 #define MAP_LOCKED	0x02000		/* pages are locked */
include/asm-sparc64/mman.h +1 -0
Index: working-2.6/include/asm-sparc64/mman.h
===================================================================
@@ -24,6 +24,7 @@
 #define _MAP_NEW        0x80000000      /* Binary compatibility is fun... */
 
 #define MAP_GROWSDOWN	0x0200		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 
include/asm-x86_64/mman.h +1 -0
Index: working-2.6/include/asm-x86_64/mman.h
===================================================================
@@ -17,6 +17,7 @@
 #define MAP_32BIT	0x40		/* only give out 32bit addresses */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-ppc/mman.h +1 -0
Index: working-2.6/include/asm-ppc/mman.h
===================================================================
@@ -19,6 +19,7 @@
 #define MAP_LOCKED	0x80
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
include/asm-alpha/mman.h +1 -0
Index: working-2.6/include/asm-alpha/mman.h
===================================================================
@@ -28,6 +28,7 @@
 #define MAP_NORESERVE	0x10000		/* don't check for reservations */
 #define MAP_POPULATE	0x20000		/* populate (prefault) pagetables */
 #define MAP_NONBLOCK	0x40000		/* do not block on IO */
+#define MAP_HUGETLB	0x80000		/* Backed with hugetlb pages */
 
 #define MS_ASYNC	1		/* sync memory asynchronously */
 #define MS_SYNC		2		/* synchronous memory sync */
include/asm-arm/mman.h +1 -0
Index: working-2.6/include/asm-arm/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-arm26/mman.h +1 -0
Index: working-2.6/include/asm-arm26/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-cris/mman.h +1 -0
Index: working-2.6/include/asm-cris/mman.h
===================================================================
@@ -18,6 +18,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-h8300/mman.h +1 -0
Index: working-2.6/include/asm-h8300/mman.h
===================================================================
@@ -15,6 +15,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-m68k/mman.h +1 -0
Index: working-2.6/include/asm-m68k/mman.h
===================================================================
@@ -16,6 +16,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-mips/mman.h +1 -0
Index: working-2.6/include/asm-mips/mman.h
===================================================================
@@ -38,6 +38,7 @@
 #define MAP_AUTORSRV	0x100		/* Logical swap reserved on demand */
 
 /* These are linux-specific */
+#define MAP_HUGETLB	0x0200		/* Backed with hugetlb pages */
 #define MAP_NORESERVE	0x0400		/* don't check for reservations */
 #define MAP_ANONYMOUS	0x0800		/* don't use a file */
 #define MAP_GROWSDOWN	0x1000		/* stack-like segment */
include/asm-parisc/mman.h +1 -0
Index: working-2.6/include/asm-parisc/mman.h
===================================================================
@@ -15,6 +15,7 @@
 #define MAP_FIXED	0x04		/* Interpret addr exactly */
 #define MAP_ANONYMOUS	0x10		/* don't use a file */
 
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-s390/mman.h +1 -0
Index: working-2.6/include/asm-s390/mman.h
===================================================================
@@ -24,6 +24,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
include/asm-sparc/mman.h +1 -0
Index: working-2.6/include/asm-sparc/mman.h
===================================================================
@@ -24,6 +24,7 @@
 #define _MAP_NEW        0x80000000      /* Binary compatibility is fun... */
 
 #define MAP_GROWSDOWN	0x0200		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 
include/asm-v850/mman.h +1 -0
Index: working-2.6/include/asm-v850/mman.h
===================================================================
@@ -15,6 +15,7 @@
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
 #define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_HUGETLB	0x0400		/* Backed with hugetlb pages */
 #define MAP_DENYWRITE	0x0800		/* ETXTBSY */
 #define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
 #define MAP_LOCKED	0x2000		/* pages are locked */
mm/mmap.c +77 -39

153 lines not on this page · raw message

Signature · 4 lines
David Gibson			| For every complex problem there is a
david AT gibson.dropbear.id.au	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson
#5 lore raw

David> Well, it's only called in one place - it's really the one David> function, just split up to let us put the wrapper creating David> the hugetlb file in the right place without excessive David> indentation. I guess it doesn't really matter, with David> -funit-at-a-time it will end up the same anyway.

We seem to be in a strange situation with respect to -funit-at-a-time:

arch/i386/Makefile:
# Disable unit-at-a-time mode, it makes gcc use a lot more stack # due to the lack of sharing of stacklots.
CFLAGS += $(call check_gcc,-fno-unit-at-a-time,)

arch/x86_64/Makefile:
# -funit-at-a-time shrinks the kernel .text considerably # unfortunately it makes reading oopses harder. CFLAGS += $(call check_gcc,-funit-at-a-time,)

arch/ppc64/Makefile:
# Enable unit-at-a-time mode when possible. It shrinks the # kernel considerably.
CFLAGS += $(call check_gcc,-funit-at-a-time,)

It looks like i386/x86_64 led the way to -funit-at-a-time, ppc64 followed, and then i386 had second thoughts because of increased stack usage around the time of 4K stacks.

No other archs have a position one way or another.

- Roland

#6 lore raw
In reply to Muli Ben-Yehuda
Quoted 4 lines · Muli Ben-Yehuda

These two global variables do not appear to be used anywhere in this patch?

Quoted 1 line

+static inline unsigned long __do_mmap_pgoff(struct file * file, unsigned long addr,

__do_mmap_pgoff seems rather long to be inline?

Atop my other patch to nuke the unused global variables, here is a patch to manually inline __do_mmap_pgoff(), removing the inline usage. Untested. Are you sure you want this? #ifdef'ing out the hugetlb case is somewhat more digestible with the inline in place, e.g.:

mm/mmap.c +23 -8
Index: wli-2.6.6-mm1/mm/mmap.c
===================================================================
@@ -771,6 +771,25 @@
 	return error;
 }
 
+#ifdef CONFIG_HUGETLB_PAGE
+static inline int create_hugetlb_file(struct file **file, unsigned long flags)
+{
+	/* Create an implicit hugetlb file if necessary */
+	if (*file || !(flags & MAP_HUGETLB))
+		return 0;
+	*file = hugetlb_zero_setup(len);
+	if (!IS_ERR(*file))
+		return 0;
+	else
+		return PTR_ERR(*file);
+}
+#else
+static inline int create_hugetlb_file(struct file **file, unsigned long flags)
+{
+	return 0;
+}
+#endif
+
 /*
  * The caller must hold down_write(current->mm->mmap_sem).
  */
@@ -809,14 +828,10 @@
 	if (current->mm->map_count > sysctl_max_map_count)
 		return -ENOMEM;
 
-	/* Create an implicit hugetlb file if necessary */
-	if (!file && (flags & MAP_HUGETLB)) {
-		file = hugetlb_file = hugetlb_zero_setup(len);
-		if (IS_ERR(file))
-			return PTR_ERR(file);
-	}
-
-	result = __do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	if (!(result = create_hugetlb_file(&hugetlb_file, flags)))
+		result = __do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	else
+		return result;
 
 	/* Drop reference to implicit hugetlb file, it's already been
 	 * "gotten" in __do_mmap_pgoff in case of success

though I suppose it's possible in principle to combine things.

-- wli

Remove __do_mmap_pgoff() in favor of direct case analysis within do_mmap_pgoff() proper.

mm/mmap.c +100 -82

275 lines not on this page · raw message

#7 lore raw

Review

Quoted 2 lines · William Lee Irwin III
(quoted diff) +2 -0
+#ifdef CONFIG_HUGETLB_PAGE
+static inline int create_hugetlb_file(struct file **file, unsigned long flags)

That would be:

mm/mmap.c +24 -8
Index: wli-2.6.6-mm1/mm/mmap.c
===================================================================
@@ -771,6 +771,26 @@
 	return error;
 }
 
+#ifdef CONFIG_HUGETLB_PAGE
+static inline int create_hugetlb_file(struct file **file, unsigned long flags,
+							unsigned long len)
+{
+	/* Create an implicit hugetlb file if necessary */
+	if (*file || !(flags & MAP_HUGETLB))
+		return 0;
+	else if (!IS_ERR(*file = hugetlb_zero_setup(len)))
+		return 0;
+	else
+		return PTR_ERR(*file);
+}
+#else
+static inline int create_hugetlb_file(struct file **file, unsigned long flags,
+							unsigned long len)
+{
+	return 0;
+}
+#endif
+
 /*
  * The caller must hold down_write(current->mm->mmap_sem).
  */
@@ -809,14 +829,10 @@
 	if (current->mm->map_count > sysctl_max_map_count)
 		return -ENOMEM;
 
-	/* Create an implicit hugetlb file if necessary */
-	if (!file && (flags & MAP_HUGETLB)) {
-		file = hugetlb_file = hugetlb_zero_setup(len);
-		if (IS_ERR(file))
-			return PTR_ERR(file);
-	}
-
-	result = __do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	if (!(result = create_hugetlb_file(&hugetlb_file, flags, len)))
+		result = __do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	else
+		return result;
 
 	/* Drop reference to implicit hugetlb file, it's already been
 	 * "gotten" in __do_mmap_pgoff in case of success
#8 lore raw
Quoted 1 line · William Lee Irwin III

That would be:

At some point while I wasn't looking hugetlb_zero_setup() got an ERR_PTR(-ENOSYS) implementation for #ifndef CONFIG_HUGETLB_PAGE so the whole create_hugetlb_file() bit is unnecessary.

-- wli

#9 lore raw
In reply to William Lee Irwin III
Quoted 10 lines · William Lee Irwin III
Quoted 4 lines · Muli Ben-Yehuda

These two global variables do not appear to be used anywhere in this patch?

Quoted 1 line

+static inline unsigned long __do_mmap_pgoff(struct file * file, unsigned long addr,

__do_mmap_pgoff seems rather long to be inline?

Atop my other patch to nuke the unused global variables, here is a patch to manually inline __do_mmap_pgoff(), removing the inline usage. Untested. Are you sure you want this? #ifdef'ing out the hugetlb case is somewhat more digestible with the inline in place, e.g.:

Well, I did the breakup in 2 pieces in the first place for 2 reasons:

- the original patch had some subtle issues with accounting
- do_mmap_pgoff is already such a mess, let's not make it worse

I mean, it's awful to get anything right in this function, especially the cleanup/exit path, which is why I think it's more maintainable cut in 2.

Ben.

#10 lore raw
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

Atop my other patch to nuke the unused global variables, here is a patch to manually inline __do_mmap_pgoff(), removing the inline usage. Untested. Are you sure you want this? #ifdef'ing out the hugetlb case is somewhat more digestible with the inline in place, e.g.:

Quoted 6 lines · Benjamin Herrenschmidt

Well, I did the breakup in 2 pieces in the first place for 2 reasons:
- the original patch had some subtle issues with accounting
- do_mmap_pgoff is already such a mess, let's not make it worse
I mean, it's awful to get anything right in this function, especially the cleanup/exit path, which is why I think it's more maintainable cut in 2.

Well, writing it vaguely convinced me that it wasn't a great idea; I suppose now that Muli can look at the result he'll be convinced likewise.

-- wli

#11 lore raw
Quoted 14 lines · William Lee Irwin III
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines

Atop my other patch to nuke the unused global variables, here is a patch to manually inline __do_mmap_pgoff(), removing the inline usage. Untested. Are you sure you want this? #ifdef'ing out the hugetlb case is somewhat more digestible with the inline in place, e.g.:

Quoted 6 lines · Benjamin Herrenschmidt

Well, I did the breakup in 2 pieces in the first place for 2 reasons:
- the original patch had some subtle issues with accounting
- do_mmap_pgoff is already such a mess, let's not make it worse
I mean, it's awful to get anything right in this function, especially the cleanup/exit path, which is why I think it's more maintainable cut in 2.

Quoted 3 lines

Well, writing it vaguely convinced me that it wasn't a great idea; I suppose now that Muli can look at the result he'll be convinced likewise.

No need to convince me; my comment was strictly with regards to inlining the function (as opposed to just leaving it static), not with regards to splitting up the messy horror that is do_mmap_pgoff, which I am very much in favor of.

Cheers,
Muli

Signature · 2 lines
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/
#12 lore raw
In reply to David Gibson
Quoted 11 lines · David Gibson

Andrew, please apply:

At present, getting a block of (quasi-) anonymous memory mapping with hugepages is a slightly convoluted process, involving creating a dummy file in a hugetlbfs filesystem. In particular that means finding where such a filesystem is mounted, for which there is no standard mechanism. Getting hugepage SysV shm segments is easier, just requing the SHM_HUGETLB flag. This patch adds an analagous MAP_HUGETLB mmap() flag to easily request that a block of anonymous memory come from hugepages.

Quoted 3 lines

[The MAP_HUGETLB flag has the side effect that MAP_SHARED semantics will apply, even if MAP_PRIVATE is specific - but that's no different to explicitly mapping hugetlbfs].

Please don't do this. It's messing all over sensitive codepathes in the kernel, creating special cases and bloat of what you could with simple a simpe hugetlb_mmap() wrapper ala (pseudocode)

hugetlb_mmap()

{
	fd = open(file in hugetlbfs)

	mmap(.., fd, ...)
	close(fd)
}

in some library. The hugetlbfs implementation was chosen exactly because if kept the impact of hugetlb pages down to normal kernel codepathes.

#13 lore raw
Quoted 3 lines · Christoph Hellwig

Please don't do this. It's messing all over sensitive codepathes in the kernel, creating special cases and bloat of what you could with simple a simpe hugetlb_mmap() wrapper ala (pseudocode)

another thing is that you could also simply override the mmap symbol from glibc do transparently use hugetlb pages.

Another problem with this interface is that hugetlb_zero_setup bypassed directory based permissions, aka it's has the same design bug as the broken sysv shm extension for hugetlb pages and thus needs privilegues or one of the horrible hacks discussed on lkml the last days.