* [PATCH] Correct alignment of huge page requests.
@ 2012-02-28 4:00 Steven Truelove
2012-02-28 20:26 ` Andrew Morton
0 siblings, 1 reply; 8+ messages in thread
From: Steven Truelove @ 2012-02-28 4:00 UTC (permalink / raw)
To: wli, akpm; +Cc: linux-kernel, linux-mm, Steven Truelove
When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size. Also modified mmap_pgoff() to avoid duplicating this check and to align against the start address.
Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>
---
fs/hugetlbfs/inode.c | 9 ++++++---
mm/mmap.c | 6 +++++-
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 1e85a7a..b4bed46 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
struct path path;
struct dentry *root;
struct qstr quick_string;
+ struct hstate *hstate;
+ int num_pages;
*user = NULL;
if (!hugetlbfs_vfsmount)
@@ -967,10 +969,11 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
if (!inode)
goto out_dentry;
+ hstate = hstate_inode(inode);
+ num_pages = ALIGN(size, huge_page_size(hstate)) >>
+ huge_page_shift(hstate);
error = -ENOMEM;
- if (hugetlb_reserve_pages(inode, 0,
- size >> huge_page_shift(hstate_inode(inode)), NULL,
- acctflag))
+ if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
goto out_inode;
d_instantiate(path.dentry, inode);
diff --git a/mm/mmap.c b/mm/mmap.c
index 3f758c7..1f44ccf 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1098,8 +1098,12 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
* taken when vm_ops->mmap() is called
* A dummy user value is used because we are not locking
* memory so no accounting is necessary
+ * Length is increased by the amount necessary to align
+ * the base address to the huge page size.
+ * hugetlb_file_setup() aligns the end of the buffer to
+ * the huge page size.
*/
- len = ALIGN(len, huge_page_size(&default_hstate));
+ len += ALIGN(addr, huge_page_size(&default_hstate)) - addr;
file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
&user, HUGETLB_ANONHUGE_INODE);
if (IS_ERR(file))
--
1.7.3.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Correct alignment of huge page requests.
2012-02-28 4:00 Steven Truelove
@ 2012-02-28 20:26 ` Andrew Morton
0 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2012-02-28 20:26 UTC (permalink / raw)
To: Steven Truelove; +Cc: wli, linux-kernel, linux-mm
On Mon, 27 Feb 2012 23:00:28 -0500
Steven Truelove <steven.truelove@utoronto.ca> wrote:
> When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size. Also modified mmap_pgoff() to avoid duplicating this check and to align against the start address.
>
I don't think this is quite right.
Suppose huge_page_size is 4096, addr=4095, len=4098. So we're mapping
three pages: the last byte of the first page, all of the second page
and the first byte of the third page.
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> struct path path;
> struct dentry *root;
> struct qstr quick_string;
> + struct hstate *hstate;
> + int num_pages;
>
> *user = NULL;
> if (!hugetlbfs_vfsmount)
> @@ -967,10 +969,11 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> if (!inode)
> goto out_dentry;
>
> + hstate = hstate_inode(inode);
> + num_pages = ALIGN(size, huge_page_size(hstate)) >>
> + huge_page_shift(hstate);
> error = -ENOMEM;
> - if (hugetlb_reserve_pages(inode, 0,
> - size >> huge_page_shift(hstate_inode(inode)), NULL,
> - acctflag))
> + if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
> goto out_inode;
>
> d_instantiate(path.dentry, inode);
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 3f758c7..1f44ccf 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1098,8 +1098,12 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
> * taken when vm_ops->mmap() is called
> * A dummy user value is used because we are not locking
> * memory so no accounting is necessary
> + * Length is increased by the amount necessary to align
> + * the base address to the huge page size.
> + * hugetlb_file_setup() aligns the end of the buffer to
> + * the huge page size.
> */
> - len = ALIGN(len, huge_page_size(&default_hstate));
> + len += ALIGN(addr, huge_page_size(&default_hstate)) - addr;
> file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
> &user, HUGETLB_ANONHUGE_INODE);
mmap_pgoff() will change `len' from 4098 to 4099. hugetlb_file_setup()
will round that up to 8192 and will decide to reserve two pages, not
three.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] Correct alignment of huge page requests.
@ 2012-03-02 2:41 Steven Truelove
2012-03-02 2:58 ` Steven Truelove
0 siblings, 1 reply; 8+ messages in thread
From: Steven Truelove @ 2012-03-02 2:41 UTC (permalink / raw)
To: wli, akpm; +Cc: linux-kernel, linux-mm, Steven Truelove
When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. Changed newseg and mmap_pgoff to match new prototype and eliminated a now redundant alignment check.
---
fs/hugetlbfs/inode.c | 12 ++++++++----
include/linux/hugetlb.h | 3 ++-
ipc/shm.c | 2 +-
mm/mmap.c | 6 +++---
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 1e85a7a..a97b7cc 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -928,7 +928,7 @@ static int can_do_hugetlb_shm(void)
return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
}
-struct file *hugetlb_file_setup(const char *name, size_t size,
+struct file *hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
vm_flags_t acctflag,
struct user_struct **user, int creat_flags)
{
@@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
struct path path;
struct dentry *root;
struct qstr quick_string;
+ struct hstate *hstate;
+ int num_pages;
*user = NULL;
if (!hugetlbfs_vfsmount)
@@ -967,10 +969,12 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
if (!inode)
goto out_dentry;
+ hstate = hstate_inode(inode);
+ size += addr & ~huge_page_mask(hstate);
+ num_pages = ALIGN(size, huge_page_size(hstate)) >>
+ huge_page_shift(hstate);
error = -ENOMEM;
- if (hugetlb_reserve_pages(inode, 0,
- size >> huge_page_shift(hstate_inode(inode)), NULL,
- acctflag))
+ if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
goto out_inode;
d_instantiate(path.dentry, inode);
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index d9d6c86..4b9e59d 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -164,7 +164,8 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
extern const struct file_operations hugetlbfs_file_operations;
extern const struct vm_operations_struct hugetlb_vm_ops;
-struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
+struct file *hugetlb_file_setup(const char *name, unsigned long addr,
+ size_t size, vm_flags_t acct,
struct user_struct **user, int creat_flags);
int hugetlb_get_quota(struct address_space *mapping, long delta);
void hugetlb_put_quota(struct address_space *mapping, long delta);
diff --git a/ipc/shm.c b/ipc/shm.c
index b76be5b..406c5b2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -482,7 +482,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
/* hugetlb_file_setup applies strict accounting */
if (shmflg & SHM_NORESERVE)
acctflag = VM_NORESERVE;
- file = hugetlb_file_setup(name, size, acctflag,
+ file = hugetlb_file_setup(name, 0, size, acctflag,
&shp->mlock_user, HUGETLB_SHMFS_INODE);
} else {
/*
diff --git a/mm/mmap.c b/mm/mmap.c
index 3f758c7..4bf211a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1099,9 +1099,9 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
* A dummy user value is used because we are not locking
* memory so no accounting is necessary
*/
- len = ALIGN(len, huge_page_size(&default_hstate));
- file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
- &user, HUGETLB_ANONHUGE_INODE);
+ file = hugetlb_file_setup(HUGETLB_ANON_FILE, addr, len,
+ VM_NORESERVE, &user,
+ HUGETLB_ANONHUGE_INODE);
if (IS_ERR(file))
return PTR_ERR(file);
}
--
1.7.3.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Correct alignment of huge page requests.
2012-03-02 2:41 Steven Truelove
@ 2012-03-02 2:58 ` Steven Truelove
0 siblings, 0 replies; 8+ messages in thread
From: Steven Truelove @ 2012-03-02 2:58 UTC (permalink / raw)
To: Steven Truelove; +Cc: wli, akpm, linux-kernel, linux-mm
Sorry, I just realized I forgot to sign off the patch. Will resend now.
On 01/03/2012 9:41 PM, Steven Truelove wrote:
> When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. Changed newseg and mmap_pgoff to match new prototype and eliminated a now redundant alignment check.
> ---
> fs/hugetlbfs/inode.c | 12 ++++++++----
> include/linux/hugetlb.h | 3 ++-
> ipc/shm.c | 2 +-
> mm/mmap.c | 6 +++---
> 4 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 1e85a7a..a97b7cc 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -928,7 +928,7 @@ static int can_do_hugetlb_shm(void)
> return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
> }
>
> -struct file *hugetlb_file_setup(const char *name, size_t size,
> +struct file *hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
> vm_flags_t acctflag,
> struct user_struct **user, int creat_flags)
> {
> @@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> struct path path;
> struct dentry *root;
> struct qstr quick_string;
> + struct hstate *hstate;
> + int num_pages;
>
> *user = NULL;
> if (!hugetlbfs_vfsmount)
> @@ -967,10 +969,12 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> if (!inode)
> goto out_dentry;
>
> + hstate = hstate_inode(inode);
> + size += addr& ~huge_page_mask(hstate);
> + num_pages = ALIGN(size, huge_page_size(hstate))>>
> + huge_page_shift(hstate);
> error = -ENOMEM;
> - if (hugetlb_reserve_pages(inode, 0,
> - size>> huge_page_shift(hstate_inode(inode)), NULL,
> - acctflag))
> + if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
> goto out_inode;
>
> d_instantiate(path.dentry, inode);
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index d9d6c86..4b9e59d 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -164,7 +164,8 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
>
> extern const struct file_operations hugetlbfs_file_operations;
> extern const struct vm_operations_struct hugetlb_vm_ops;
> -struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
> +struct file *hugetlb_file_setup(const char *name, unsigned long addr,
> + size_t size, vm_flags_t acct,
> struct user_struct **user, int creat_flags);
> int hugetlb_get_quota(struct address_space *mapping, long delta);
> void hugetlb_put_quota(struct address_space *mapping, long delta);
> diff --git a/ipc/shm.c b/ipc/shm.c
> index b76be5b..406c5b2 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -482,7 +482,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
> /* hugetlb_file_setup applies strict accounting */
> if (shmflg& SHM_NORESERVE)
> acctflag = VM_NORESERVE;
> - file = hugetlb_file_setup(name, size, acctflag,
> + file = hugetlb_file_setup(name, 0, size, acctflag,
> &shp->mlock_user, HUGETLB_SHMFS_INODE);
> } else {
> /*
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 3f758c7..4bf211a 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1099,9 +1099,9 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
> * A dummy user value is used because we are not locking
> * memory so no accounting is necessary
> */
> - len = ALIGN(len, huge_page_size(&default_hstate));
> - file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
> - &user, HUGETLB_ANONHUGE_INODE);
> + file = hugetlb_file_setup(HUGETLB_ANON_FILE, addr, len,
> + VM_NORESERVE,&user,
> + HUGETLB_ANONHUGE_INODE);
> if (IS_ERR(file))
> return PTR_ERR(file);
> }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] Correct alignment of huge page requests.
@ 2012-03-02 2:58 Steven Truelove
2012-03-04 3:02 ` Naoya Horiguchi
2012-03-04 3:50 ` Hillf Danton
0 siblings, 2 replies; 8+ messages in thread
From: Steven Truelove @ 2012-03-02 2:58 UTC (permalink / raw)
To: wli, akpm; +Cc: linux-kernel, linux-mm, Steven Truelove
When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. Changed newseg and mmap_pgoff to match new prototype and eliminated a now redundant alignment check.
Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>
---
fs/hugetlbfs/inode.c | 12 ++++++++----
include/linux/hugetlb.h | 3 ++-
ipc/shm.c | 2 +-
mm/mmap.c | 6 +++---
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 1e85a7a..a97b7cc 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -928,7 +928,7 @@ static int can_do_hugetlb_shm(void)
return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
}
-struct file *hugetlb_file_setup(const char *name, size_t size,
+struct file *hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
vm_flags_t acctflag,
struct user_struct **user, int creat_flags)
{
@@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
struct path path;
struct dentry *root;
struct qstr quick_string;
+ struct hstate *hstate;
+ int num_pages;
*user = NULL;
if (!hugetlbfs_vfsmount)
@@ -967,10 +969,12 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
if (!inode)
goto out_dentry;
+ hstate = hstate_inode(inode);
+ size += addr & ~huge_page_mask(hstate);
+ num_pages = ALIGN(size, huge_page_size(hstate)) >>
+ huge_page_shift(hstate);
error = -ENOMEM;
- if (hugetlb_reserve_pages(inode, 0,
- size >> huge_page_shift(hstate_inode(inode)), NULL,
- acctflag))
+ if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
goto out_inode;
d_instantiate(path.dentry, inode);
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index d9d6c86..4b9e59d 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -164,7 +164,8 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
extern const struct file_operations hugetlbfs_file_operations;
extern const struct vm_operations_struct hugetlb_vm_ops;
-struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
+struct file *hugetlb_file_setup(const char *name, unsigned long addr,
+ size_t size, vm_flags_t acct,
struct user_struct **user, int creat_flags);
int hugetlb_get_quota(struct address_space *mapping, long delta);
void hugetlb_put_quota(struct address_space *mapping, long delta);
diff --git a/ipc/shm.c b/ipc/shm.c
index b76be5b..406c5b2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -482,7 +482,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
/* hugetlb_file_setup applies strict accounting */
if (shmflg & SHM_NORESERVE)
acctflag = VM_NORESERVE;
- file = hugetlb_file_setup(name, size, acctflag,
+ file = hugetlb_file_setup(name, 0, size, acctflag,
&shp->mlock_user, HUGETLB_SHMFS_INODE);
} else {
/*
diff --git a/mm/mmap.c b/mm/mmap.c
index 3f758c7..4bf211a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1099,9 +1099,9 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
* A dummy user value is used because we are not locking
* memory so no accounting is necessary
*/
- len = ALIGN(len, huge_page_size(&default_hstate));
- file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
- &user, HUGETLB_ANONHUGE_INODE);
+ file = hugetlb_file_setup(HUGETLB_ANON_FILE, addr, len,
+ VM_NORESERVE, &user,
+ HUGETLB_ANONHUGE_INODE);
if (IS_ERR(file))
return PTR_ERR(file);
}
--
1.7.3.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Correct alignment of huge page requests.
2012-03-02 2:58 [PATCH] Correct alignment of huge page requests Steven Truelove
@ 2012-03-04 3:02 ` Naoya Horiguchi
2012-03-07 23:29 ` Steven Truelove
2012-03-04 3:50 ` Hillf Danton
1 sibling, 1 reply; 8+ messages in thread
From: Naoya Horiguchi @ 2012-03-04 3:02 UTC (permalink / raw)
To: Steven Truelove; +Cc: wli, akpm, linux-kernel, linux-mm
On Thu, Mar 01, 2012 at 09:58:41PM -0500, Steven Truelove wrote:
> When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. Changed newseg and mmap_pgoff to match new prototype and eliminated a now redundant alignment check.
I think only rounding up request size in shmget() is not sufficient,
because later shmat() also have alignment check and fails to mmap()
to unaligned address.
Maybe file->f_op->get_unmapped_area() (or hugetlb_get_unmapped_area())
should have round up code, I think.
Could you try it?
And a few comments below,
> Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>
> ---
> fs/hugetlbfs/inode.c | 12 ++++++++----
> include/linux/hugetlb.h | 3 ++-
> ipc/shm.c | 2 +-
> mm/mmap.c | 6 +++---
> 4 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 1e85a7a..a97b7cc 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -928,7 +928,7 @@ static int can_do_hugetlb_shm(void)
> return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
> }
>
> -struct file *hugetlb_file_setup(const char *name, size_t size,
> +struct file *hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
Just a nitpick, this line is over 80 characters.
checkpatch.pl should warn.
> vm_flags_t acctflag,
> struct user_struct **user, int creat_flags)
> {
> @@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> struct path path;
> struct dentry *root;
> struct qstr quick_string;
> + struct hstate *hstate;
> + int num_pages;
Is unsigned long better?
Thanks,
Naoya
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Correct alignment of huge page requests.
2012-03-02 2:58 [PATCH] Correct alignment of huge page requests Steven Truelove
2012-03-04 3:02 ` Naoya Horiguchi
@ 2012-03-04 3:50 ` Hillf Danton
1 sibling, 0 replies; 8+ messages in thread
From: Hillf Danton @ 2012-03-04 3:50 UTC (permalink / raw)
To: Steven Truelove; +Cc: wli, akpm, linux-kernel, linux-mm
On Fri, Mar 2, 2012 at 10:58 AM, Steven Truelove
<steven.truelove@utoronto.ca> wrote:
> When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. Changed newseg and mmap_pgoff to match new prototype and eliminated a now redundant alignment check.
>
> Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>
Acked-by: Hillf Danton <dhillf@gmail.com>
> ---
> fs/hugetlbfs/inode.c | 12 ++++++++----
> include/linux/hugetlb.h | 3 ++-
> ipc/shm.c | 2 +-
> mm/mmap.c | 6 +++---
> 4 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 1e85a7a..a97b7cc 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -928,7 +928,7 @@ static int can_do_hugetlb_shm(void)
> return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
> }
>
> -struct file *hugetlb_file_setup(const char *name, size_t size,
> +struct file *hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
> vm_flags_t acctflag,
> struct user_struct **user, int creat_flags)
> {
> @@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> struct path path;
> struct dentry *root;
> struct qstr quick_string;
> + struct hstate *hstate;
> + int num_pages;
>
> *user = NULL;
> if (!hugetlbfs_vfsmount)
> @@ -967,10 +969,12 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
> if (!inode)
> goto out_dentry;
>
> + hstate = hstate_inode(inode);
> + size += addr & ~huge_page_mask(hstate);
> + num_pages = ALIGN(size, huge_page_size(hstate)) >>
> + huge_page_shift(hstate);
> error = -ENOMEM;
> - if (hugetlb_reserve_pages(inode, 0,
> - size >> huge_page_shift(hstate_inode(inode)), NULL,
> - acctflag))
> + if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
> goto out_inode;
>
> d_instantiate(path.dentry, inode);
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index d9d6c86..4b9e59d 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -164,7 +164,8 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
>
> extern const struct file_operations hugetlbfs_file_operations;
> extern const struct vm_operations_struct hugetlb_vm_ops;
> -struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
> +struct file *hugetlb_file_setup(const char *name, unsigned long addr,
> + size_t size, vm_flags_t acct,
> struct user_struct **user, int creat_flags);
> int hugetlb_get_quota(struct address_space *mapping, long delta);
> void hugetlb_put_quota(struct address_space *mapping, long delta);
> diff --git a/ipc/shm.c b/ipc/shm.c
> index b76be5b..406c5b2 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -482,7 +482,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
> /* hugetlb_file_setup applies strict accounting */
> if (shmflg & SHM_NORESERVE)
> acctflag = VM_NORESERVE;
> - file = hugetlb_file_setup(name, size, acctflag,
> + file = hugetlb_file_setup(name, 0, size, acctflag,
> &shp->mlock_user, HUGETLB_SHMFS_INODE);
> } else {
> /*
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 3f758c7..4bf211a 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1099,9 +1099,9 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
> * A dummy user value is used because we are not locking
> * memory so no accounting is necessary
> */
> - len = ALIGN(len, huge_page_size(&default_hstate));
> - file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE,
> - &user, HUGETLB_ANONHUGE_INODE);
> + file = hugetlb_file_setup(HUGETLB_ANON_FILE, addr, len,
> + VM_NORESERVE, &user,
> + HUGETLB_ANONHUGE_INODE);
> if (IS_ERR(file))
> return PTR_ERR(file);
> }
> --
> 1.7.3.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Correct alignment of huge page requests.
2012-03-04 3:02 ` Naoya Horiguchi
@ 2012-03-07 23:29 ` Steven Truelove
0 siblings, 0 replies; 8+ messages in thread
From: Steven Truelove @ 2012-03-07 23:29 UTC (permalink / raw)
To: Naoya Horiguchi; +Cc: wli, akpm, linux-kernel, linux-mm
On 03/03/2012 10:02 PM, Naoya Horiguchi wrote:
> On Thu, Mar 01, 2012 at 09:58:41PM -0500, Steven Truelove wrote:
>> When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modified hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. Changed newseg and mmap_pgoff to match new prototype and eliminated a now redundant alignment check.
> I think only rounding up request size in shmget() is not sufficient,
> because later shmat() also have alignment check and fails to mmap()
> to unaligned address.
> Maybe file->f_op->get_unmapped_area() (or hugetlb_get_unmapped_area())
> should have round up code, I think.
> Could you try it?
Because the allocation is done in shmget() and the the address is not
provided until shmat(), I don't see a way to make this work reasonably.
I would argue that only allowing aligned addresses, or allowing the
kernel to choose the address, is a reasonable restriction on SHM_HUGETLB
usage.
Regarding your other comments, I will submit a revised patch.
Thanks,
Steven Truelove
> And a few comments below,
>
>> Signed-off-by: Steven Truelove<steven.truelove@utoronto.ca>
>> ---
>> fs/hugetlbfs/inode.c | 12 ++++++++----
>> include/linux/hugetlb.h | 3 ++-
>> ipc/shm.c | 2 +-
>> mm/mmap.c | 6 +++---
>> 4 files changed, 14 insertions(+), 9 deletions(-)
>>
>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
>> index 1e85a7a..a97b7cc 100644
>> --- a/fs/hugetlbfs/inode.c
>> +++ b/fs/hugetlbfs/inode.c
>> @@ -928,7 +928,7 @@ static int can_do_hugetlb_shm(void)
>> return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
>> }
>>
>> -struct file *hugetlb_file_setup(const char *name, size_t size,
>> +struct file *hugetlb_file_setup(const char *name, unsigned long addr, size_t size,
> Just a nitpick, this line is over 80 characters.
> checkpatch.pl should warn.
>
>> vm_flags_t acctflag,
>> struct user_struct **user, int creat_flags)
>> {
>> @@ -938,6 +938,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
>> struct path path;
>> struct dentry *root;
>> struct qstr quick_string;
>> + struct hstate *hstate;
>> + int num_pages;
> Is unsigned long better?
>
> Thanks,
> Naoya
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-03-07 23:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-02 2:58 [PATCH] Correct alignment of huge page requests Steven Truelove
2012-03-04 3:02 ` Naoya Horiguchi
2012-03-07 23:29 ` Steven Truelove
2012-03-04 3:50 ` Hillf Danton
-- strict thread matches above, loose matches on Subject: below --
2012-03-02 2:41 Steven Truelove
2012-03-02 2:58 ` Steven Truelove
2012-02-28 4:00 Steven Truelove
2012-02-28 20:26 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).