From: Andrew Morton <akpm@linux-foundation.org>
To: Steven Truelove <steven.truelove@utoronto.ca>
Cc: wli@holomorphy.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] Correct alignment of huge page requests.
Date: Tue, 28 Feb 2012 12:26:16 -0800 [thread overview]
Message-ID: <20120228122616.de510ae2.akpm@linux-foundation.org> (raw)
In-Reply-To: <1330401628-30818-1-git-send-email-steven.truelove@utoronto.ca>
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>
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: Steven Truelove <steven.truelove@utoronto.ca>
Cc: wli@holomorphy.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] Correct alignment of huge page requests.
Date: Tue, 28 Feb 2012 12:26:16 -0800 [thread overview]
Message-ID: <20120228122616.de510ae2.akpm@linux-foundation.org> (raw)
In-Reply-To: <1330401628-30818-1-git-send-email-steven.truelove@utoronto.ca>
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.
next prev parent reply other threads:[~2012-02-28 20:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-28 4:00 [PATCH] Correct alignment of huge page requests Steven Truelove
2012-02-28 4:00 ` Steven Truelove
2012-02-28 20:26 ` Andrew Morton [this message]
2012-02-28 20:26 ` Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2012-03-02 2:41 Steven Truelove
2012-03-02 2:41 ` Steven Truelove
2012-03-02 2:58 ` Steven Truelove
2012-03-02 2:58 ` Steven Truelove
2012-03-02 2:58 Steven Truelove
2012-03-02 2:58 ` Steven Truelove
2012-03-04 3:02 ` Naoya Horiguchi
2012-03-04 3:02 ` Naoya Horiguchi
2012-03-07 23:29 ` Steven Truelove
2012-03-07 23:29 ` Steven Truelove
2012-03-04 3:50 ` Hillf Danton
2012-03-04 3:50 ` Hillf Danton
2012-03-08 1:06 Steven Truelove
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120228122616.de510ae2.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=steven.truelove@utoronto.ca \
--cc=wli@holomorphy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.