linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Shijie Hu <hushijie3@huawei.com>
To: <mike.kravetz@oracle.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	<nixiaoming@huawei.com>, <wangxu72@huawei.com>,
	<wangkefeng.wang@huawei.com>, <yangerkun@huawei.com>,
	<wangle6@huawei.com>, <cg.chen@huawei.com>
Subject: [PATCH] [RFC]hugetlbfs: Get unmapped area below TASK_UNMAPPED_BASE for hugetlbfs
Date: Mon, 27 Apr 2020 19:10:36 +0800	[thread overview]
Message-ID: <20200427111036.74983-1-hushijie3@huawei.com> (raw)

In 32-bit programs, the address space is limited. When the normal mmap
consumes the space above TASK_UNMAPPED_BASE on legacy mode, it can still
successfully obtain unmapped area below TASK_UNMAPPED_BASE, but mmap or
shmat for huge pages will fail. This seems "not fair".

When the request for huge pages fails, fall back to reuse mmap_min_addr
~ TASK_UNMAPPED_BASE for hugetlbfs.

Signed-off-by: Shijie Hu <hushijie3@huawei.com>
---
 fs/hugetlbfs/inode.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index aff8642f0c2e..0f5997394aaa 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -224,7 +224,21 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
 	info.high_limit = TASK_SIZE;
 	info.align_mask = PAGE_MASK & ~huge_page_mask(h);
 	info.align_offset = 0;
-	return vm_unmapped_area(&info);
+	addr = vm_unmapped_area(&info);
+
+	/*
+	 * A failed request for huge pages very likely causes application
+	 * failure, so fall back to the top-down function here.
+	 */
+	if (unlikely(offset_in_page(addr))) {
+		VM_BUG_ON(addr != -ENOMEM);
+		info.flags = VM_UNMAPPED_AREA_TOPDOWN;
+		info.low_limit = max(PAGE_SIZE, mmap_min_addr);
+		info.high_limit = TASK_UNMAPPED_BASE;
+		addr = vm_unmapped_area(&info);
+	}
+
+	return addr;
 }
 #endif
 
-- 
2.12.3



             reply	other threads:[~2020-04-27 11:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27 11:10 Shijie Hu [this message]
2020-04-27 22:46 ` Mike Kravetz

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=20200427111036.74983-1-hushijie3@huawei.com \
    --to=hushijie3@huawei.com \
    --cc=cg.chen@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=nixiaoming@huawei.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=wangle6@huawei.com \
    --cc=wangxu72@huawei.com \
    --cc=yangerkun@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox