All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Round up huge page count to avoid allocating too little memory when 'size' argument is not a multiple of the huge page size.
@ 2012-02-09 16:16 Steven Truelove
  2012-02-27  7:31 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Truelove @ 2012-02-09 16:16 UTC (permalink / raw)
  To: wli; +Cc: linux-kernel, Steven Truelove

Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>
---
 fs/hugetlbfs/inode.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 1e85a7a..fce2527 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,10 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
 	if (!inode)
 		goto out_dentry;
 
+	hstate = hstate_inode(inode);
+	num_pages = (size + huge_page_size(hstate) - 1) >> 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);
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Round up huge page count to avoid allocating too little memory when 'size' argument is not a multiple of the huge page size.
  2012-02-09 16:16 [PATCH] Round up huge page count to avoid allocating too little memory when 'size' argument is not a multiple of the huge page size Steven Truelove
@ 2012-02-27  7:31 ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2012-02-27  7:31 UTC (permalink / raw)
  To: Steven Truelove; +Cc: wli, linux-kernel

On Thu,  9 Feb 2012 11:16:03 -0500 Steven Truelove <steven.truelove@utoronto.ca> wrote:

> Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>

Please don't send unchangelogged patches.

What is missing here is any explanation of why we should make this
change.  Is there some kernel bug you have observed?  If so, please
describe it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Round up huge page count to avoid allocating too little memory when 'size' argument is not a multiple of the huge page size.
  2012-02-23 13:28 Steven Truelove
@ 2012-02-26 23:46 ` Steven Truelove
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Truelove @ 2012-02-26 23:46 UTC (permalink / raw)
  To: wli; +Cc: linux-kernel

Well, PAGE_ALIGN(addr) is already defined as  ALIGN(addr, PAGE_SIZE), so 
ALIGN can be used with the huge page size easily enough.

In this case however, the code is calculating a number of pages, not an 
address, so I feel my patch is appropriate.

FYI, I ran into this issue while allocating huge pages as shared memory 
in userspace.  shmget would always succeed, but shmat would fail unless 
the requested size mapped closely to the huge page size.  shmget would 
round up to the nearest PAGE_SIZE, but when allocating huge pages this 
obviously isn't enough.

On systems with multiple huge page sizes, it isn't obvious what the huge 
page size will be for a shmget request.  It only becomes obvious in 
hugetlbfs, so that is where I made the change.

Regards,

Steven Truelove

On 26/02/2012 4:24 PM, wli@holomorphy.com wrote:
>
> It might be a good idea to introduce a hugepage analogue of 
> PAGE_ALIGN() for this purpose.
>
> I'll try to get a more normal email setup at some point.
>
> -- wli
>
>
> On February 23, 2012 at 8:28 AM Steven Truelove 
> <steven.truelove@utoronto.ca> wrote:
>
> > Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>
> > ---
> >  fs/hugetlbfs/inode.c |    8 +++++---
> >  1 files changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> > index 1e85a7a..fce2527 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,10 @@ struct file *hugetlb_file_setup(const char 
> *name, size_t size,
> >          if (!inode)
> >                  goto out_dentry;
> >
> > +        hstate = hstate_inode(inode);
> > +        num_pages = (size + huge_page_size(hstate) - 1) >> 
> 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);
> > --
> > 1.7.3.4
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Round up huge page count to avoid allocating too little memory when 'size' argument is not a multiple of the huge page size.
@ 2012-02-23 13:28 Steven Truelove
  2012-02-26 23:46 ` Steven Truelove
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Truelove @ 2012-02-23 13:28 UTC (permalink / raw)
  To: wli; +Cc: steven.truelove, linux-kernel

Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca>
---
 fs/hugetlbfs/inode.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 1e85a7a..fce2527 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,10 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
 	if (!inode)
 		goto out_dentry;
 
+	hstate = hstate_inode(inode);
+	num_pages = (size + huge_page_size(hstate) - 1) >> 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);
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-27  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-09 16:16 [PATCH] Round up huge page count to avoid allocating too little memory when 'size' argument is not a multiple of the huge page size Steven Truelove
2012-02-27  7:31 ` Andrew Morton
2012-02-23 13:28 Steven Truelove
2012-02-26 23:46 ` Steven Truelove

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.