Skip to contentSkip to conversation

hugetlb: add resv argument to hugetlb_file_setup

PATCH In review Ken Chen 5 participants 6 messages Mar 23, 2007 – Mar 26, 2007

Subsystems (2)
lore
Share & tools
lore

Ken Chen

author
#0 lore raw

PATCH 1/2 hugetlb: add resv argument to hugetlb_file_setup

rename hugetlb_zero_setup() to hugetlb_file_setup() to better match function name convention like shmem implementation. Also add an argument to the function to indicate whether file setup should reserve hugetlb page upfront or not.

fs/hugetlbfs/inode.c +0 -0
index 8c718a3..981886f 100644
@@ -734,7 +734,7 @@ static int can_do_hugetlb_shm(void)
			can_do_mlock());
}

-struct file *hugetlb_zero_setup(size_t size) +struct file *hugetlb_file_setup(size_t size, int resv)

{
	int error = -ENOMEM;
	struct file *file;
@@ -771,7 +771,7 @@ struct file *hugetlb_zero_setup(size_t s
		goto out_file;

	error = -ENOMEM;
-	if (hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
+	if (resv && hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
		goto out_inode;

	d_instantiate(dentry, inode);
include/linux/hugetlb.h +0 -0
index 3f3e7a6..55cccd8 100644
@@ -163,7 +163,7 @@ static inline struct hugetlbfs_sb_info *
 

extern const struct file_operations hugetlbfs_file_operations; extern struct vm_operations_struct hugetlb_vm_ops; -struct file *hugetlb_zero_setup(size_t);
+struct file *hugetlb_file_setup(size_t, int);
int hugetlb_get_quota(struct address_space *mapping); void hugetlb_put_quota(struct address_space *mapping);

@@ -185,7 +185,7 @@ #else /* !CONFIG_HUGETLBFS */

#define is_file_hugepages(file) 0
#define set_file_hugepages(file) BUG()
-#define hugetlb_zero_setup(size) ERR_PTR(-ENOSYS)
+#define hugetlb_file_setup(size, resv) ERR_PTR(-ENOSYS)

#endif /* !CONFIG_HUGETLBFS */

ipc/shm.c +0 -0
index 4fefbad..c64643f 100644
@@ -366,7 +366,7 @@ static int newseg (struct ipc_namespace
 
	if (shmflg & SHM_HUGETLB) {
		/* hugetlb_zero_setup takes care of mlock user accounting */
-		file = hugetlb_zero_setup(size);
+		file = hugetlb_file_setup(size, 1);
		shp->mlock_user = current->user;
	} else {
		int acctflag = VM_ACCOUNT;

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

#1 lore raw
Quoted 57 lines · Ken Chen

rename hugetlb_zero_setup() to hugetlb_file_setup() to better match function name convention like shmem implementation. Also add an argument to the function to indicate whether file setup should reserve hugetlb page upfront or not.

fs/hugetlbfs/inode.c +2 -2
index 8c718a3..981886f 100644
@@ -734,7 +734,7 @@ static int can_do_hugetlb_shm(void)
                        can_do_mlock());
 }
 
-struct file *hugetlb_zero_setup(size_t size)
+struct file *hugetlb_file_setup(size_t size, int resv)
 {
        int error = -ENOMEM;
        struct file *file;
@@ -771,7 +771,7 @@ struct file *hugetlb_zero_setup(size_t s
                goto out_file;
 
        error = -ENOMEM;
-       if (hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
+       if (resv && hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
                goto out_inode;
 
        d_instantiate(dentry, inode);
include/linux/hugetlb.h +2 -2
index 3f3e7a6..55cccd8 100644
@@ -163,7 +163,7 @@ static inline struct hugetlbfs_sb_info *
 
 extern const struct file_operations hugetlbfs_file_operations;
 extern struct vm_operations_struct hugetlb_vm_ops;
-struct file *hugetlb_zero_setup(size_t);
+struct file *hugetlb_file_setup(size_t, int);
 int hugetlb_get_quota(struct address_space *mapping);
 void hugetlb_put_quota(struct address_space *mapping);
 
@@ -185,7 +185,7 @@ #else /* !CONFIG_HUGETLBFS */
 
 #define is_file_hugepages(file)                0
 #define set_file_hugepages(file)       BUG()
-#define hugetlb_zero_setup(size)       ERR_PTR(-ENOSYS)
+#define hugetlb_file_setup(size, resv) ERR_PTR(-ENOSYS)
 
 #endif /* !CONFIG_HUGETLBFS */
 
ipc/shm.c +0 -0
index 4fefbad..c64643f 100644

ipc/shm.c static int newseg (struct ipc_namespace · line 369

Quoted 5 lines
ipc/shm.c +1 -1
@@ -366,7 +366,7 @@ static int newseg (struct ipc_namespace
 
        if (shmflg & SHM_HUGETLB) {
                /* hugetlb_zero_setup takes care of mlock user accounting */
-               file = hugetlb_zero_setup(size);
+               file = hugetlb_file_setup(size, 1);

Comment needs updating too.

Thanks,
Nish

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

author
#2 lore raw
Quoted 1 line · Nish Aravamudan

Comment needs updating too.

Thanks. How could I miss that :-(

updated patch:

fs/hugetlbfs/inode.c +0 -0
index 8c718a3..981886f 100644
@@ -734,7 +734,7 @@ static int can_do_hugetlb_shm(void)
			can_do_mlock());
}

-struct file *hugetlb_zero_setup(size_t size) +struct file *hugetlb_file_setup(size_t size, int resv)

{
	int error = -ENOMEM;
	struct file *file;
@@ -771,7 +771,7 @@ struct file *hugetlb_zero_setup(size_t s
		goto out_file;

	error = -ENOMEM;
-	if (hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
+	if (resv && hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
		goto out_inode;

	d_instantiate(dentry, inode);
include/linux/hugetlb.h +0 -0
index 3f3e7a6..55cccd8 100644
@@ -163,7 +163,7 @@ static inline struct hugetlbfs_sb_info *
 

extern const struct file_operations hugetlbfs_file_operations; extern struct vm_operations_struct hugetlb_vm_ops; -struct file *hugetlb_zero_setup(size_t);
+struct file *hugetlb_file_setup(size_t, int);
int hugetlb_get_quota(struct address_space *mapping); void hugetlb_put_quota(struct address_space *mapping);

@@ -185,7 +185,7 @@ #else /* !CONFIG_HUGETLBFS */

#define is_file_hugepages(file) 0
#define set_file_hugepages(file) BUG()
-#define hugetlb_zero_setup(size) ERR_PTR(-ENOSYS)
+#define hugetlb_file_setup(size, resv) ERR_PTR(-ENOSYS)

#endif /* !CONFIG_HUGETLBFS */

ipc/shm.c +0 -0
index 4fefbad..81c8344 100644
@@ -365,8 +365,8 @@ static int newseg (struct ipc_namespace
	}

	if (shmflg & SHM_HUGETLB) {
-		/* hugetlb_zero_setup takes care of mlock user accounting */
-		file = hugetlb_zero_setup(size);
+		/* hugetlb_file_setup takes care of mlock user accounting */
+		file = hugetlb_file_setup(size, 1);
		shp->mlock_user = current->user;
	} else {
		int acctflag = VM_ACCOUNT;

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

#3 lore raw
Quoted 15 lines · Ken Chen
fs/hugetlbfs/inode.c +1 -1
index 8c718a3..981886f 100644
@@ -734,7 +734,7 @@ static int can_do_hugetlb_shm(void)
 			can_do_mlock());
 }
 
-struct file *hugetlb_zero_setup(size_t size)
+struct file *hugetlb_file_setup(size_t size, int resv)
 {
 int error = -ENOMEM;
 struct file *file;

fs/hugetlbfs/inode.c struct file *hugetlb_zero_setup(size_t s · line 777

Quoted 8 lines
fs/hugetlbfs/inode.c +1 -1
@@ -771,7 +771,7 @@ struct file *hugetlb_zero_setup(size_t s
 goto out_file;
 
 	error = -ENOMEM;
-	if (hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
+	if (resv && hugetlb_reserve_pages(inode, 0, size >> HPAGE_SHIFT))
 goto out_inode;
 
 	d_instantiate(dentry, inode);

Could not this be made a bool, then?

Jan

Signature · 5 lines
--
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>
#4 lore raw
In reply to Ken Chen
Quoted 4 lines · Ken Chen

rename hugetlb_zero_setup() to hugetlb_file_setup() to better match function name convention like shmem implementation. Also add an argument to the function to indicate whether file setup should reserve hugetlb page upfront or not.

I think the reservation call should be move out of this function entirely. We only return the file descriptors through the syscall we're in, and the dentries never appear in any namespace, so there is not reason to do the reservation early.

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

#5 lore raw
In reply to Ken Chen
Quoted 6 lines · Ken Chen

rename hugetlb_zero_setup() to hugetlb_file_setup() to better match function name convention like shmem implementation. Also add an argument to the function to indicate whether file setup should reserve hugetlb page upfront or not.

This patch doesn't really look bad at all, but...

I am worried that what might seem nice and clean right now will slowly get worse. This implements an interface on top of another interface (char device on top of a filesystem). What is the next hugetlbfs function that will need a boolean switch to handle a character device special case?

Am I just worrying too much here? Although my pagetable_operations patches aren't the most popular right now, they do have at least one advantage IMO: they enable side-by-side implementation of the interfaces as opposed to stacking them. Keeping them separate removes the need for if ((vm_flags & VM_HUGETLB) && (is_hugetlbfs_chardev())) checking.

Signature · 8 lines
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center

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