From: Anshuman Khandual <khandual@linux.vnet.ibm.com>
To: Anshuman Khandual <khandual@linux.vnet.ibm.com>,
Mike Kravetz <mike.kravetz@oracle.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-api@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Michal Nazarewicz <mina86@mina86.com>,
"Aneesh Kumar K . V" <aneesh.kumar@linux.vnet.ibm.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Guy Shattah <sguy@mellanox.com>, Christoph Lameter <cl@linux.com>,
Laura Abbott <labbott@redhat.com>,
Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [RFC PATCH 0/3] Add mmap(MAP_CONTIG) support
Date: Thu, 12 Oct 2017 19:55:54 +0530 [thread overview]
Message-ID: <5a4de449-69b0-a9a4-c0bb-27198f4793c7@linux.vnet.ibm.com> (raw)
In-Reply-To: <f1737666-b65e-38e2-94af-129e66031503@linux.vnet.ibm.com>
On 10/12/2017 04:06 PM, Anshuman Khandual wrote:
> On 10/12/2017 07:16 AM, Mike Kravetz wrote:
>> The following is a 'possible' way to add such functionality. I just
>> did what was easy and pre-allocated contiguous pages which are used
>> to populate the mapping. I did not use any of the higher order
>> allocators such as alloc_contig_range. Therefore, it is limited to
> Just tried with a small prototype with an implementation similar to that
> of alloc_gigantic_page() where we scan the zones (applicable zonelist)
> for contiguous valid PFN range and try allocating with alloc_contig_range.
> Will share it soon.
>
With this patch on top of the series can allocate little more than
twice of 1UL << (MAX_ORDER - 1) number of pages on POWER. But the
problem is it keeps on reducing every attempt till it reaches
1UL << (MAX_ORDER - 1). Will look into it.
diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h
index 03c06ba..ce13b36 100644
--- a/arch/powerpc/include/uapi/asm/mman.h
+++ b/arch/powerpc/include/uapi/asm/mman.h
@@ -28,5 +28,6 @@
#define MAP_NONBLOCK 0x10000 /* do not block on IO */
#define MAP_STACK 0x20000 /* give out an address that is best suited for process/thread stacks */
#define MAP_HUGETLB 0x40000 /* create a huge page mapping */
+#define MAP_CONTIG 0x80000 /* back with contiguous pages */
#endif /* _UAPI_ASM_POWERPC_MMAN_H */
diff --git a/mm/mmap.c b/mm/mmap.c
index aee7917..4e6588d 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1568,6 +1568,60 @@ struct mmap_arg_struct {
}
#endif /* __ARCH_WANT_SYS_OLD_MMAP */
+static bool is_pfn_range_valid(struct zone *z,
+ unsigned long start_pfn, unsigned long nr_pages)
+{
+ unsigned long i, end_pfn = start_pfn + nr_pages;
+ struct page *page;
+
+ for (i = start_pfn; i < end_pfn; i++) {
+ if (!pfn_valid(i))
+ return false;
+
+ page = pfn_to_page(i);
+ if (page_zone(page) != z)
+ return false;
+
+ if (PageReserved(page))
+ return false;
+
+ if (page_count(page) > 0)
+ return false;
+
+ if (PageHuge(page))
+ return false;
+ }
+ return true;
+}
+
+struct page *
+alloc_pages_vma_contig(gfp_t gfp, int order, struct vm_area_struct *vma,
+ unsigned long addr, int node, bool hugepage)
+{
+ struct zonelist *zonelist = node_zonelist(node, gfp);
+ struct zoneref *z;
+ struct zone *zone;
+ unsigned long pfn, nr_pages, flags, ret;
+
+ nr_pages = 1 << order;
+ for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(gfp), NULL) {
+ spin_lock_irqsave(&zone->lock, flags);
+ pfn = ALIGN(zone->zone_start_pfn, nr_pages);
+ while (zone_spans_pfn(zone, pfn + nr_pages - 1)) {
+ if (is_pfn_range_valid(zone, pfn, nr_pages)) {
+ spin_unlock_irqrestore(&zone->lock, flags);
+ ret = alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE, gfp);
+ if (!ret)
+ return pfn_to_page(pfn);
+ spin_lock_irqsave(&zone->lock, flags);
+ }
+ pfn += nr_pages;
+ }
+ spin_unlock_irqrestore(&zone->lock, flags);
+ }
+ return NULL;
+}
+
/*
* Attempt to allocate a contiguous range of pages to back the
* specified vma. vm_private_data is used as a 'pointer' to the
@@ -1588,11 +1642,19 @@ static long __alloc_vma_contig_range(struct vm_area_struct *vma)
* allocations < MAX_ORDER in size. However, this should really
* handle arbitrary size allocations.
*/
+
+ /*
if (order >= MAX_ORDER)
return -ENOMEM;
- vma->vm_private_data = alloc_pages_vma(gfp, order, vma, vma->vm_start,
- numa_node_id(), false);
+ */
+
+ if (order >= MAX_ORDER)
+ vma->vm_private_data = alloc_pages_vma_contig(gfp, order, vma,
+ vma->vm_start, numa_node_id(), false);
+ else
+ vma->vm_private_data = alloc_pages_vma(gfp, order, vma,
+ vma->vm_start, numa_node_id(), false);
if (!vma->vm_private_data)
return -ENOMEM;
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-10-12 14:25 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 23:56 [RFC] mmap(MAP_CONTIG) Mike Kravetz
2017-10-04 11:54 ` Michal Nazarewicz
2017-10-04 17:08 ` Mike Kravetz
2017-10-04 21:29 ` Laura Abbott
2017-10-04 13:49 ` Anshuman Khandual
2017-10-04 16:05 ` Christopher Lameter
2017-10-04 17:38 ` Mike Kravetz
2017-10-04 17:35 ` Mike Kravetz
2017-10-05 7:06 ` Vlastimil Babka
2017-10-05 8:58 ` Guy Shattah
2017-10-05 12:36 ` Guy Shattah
2017-10-05 14:30 ` Christopher Lameter
2017-10-12 1:46 ` [RFC PATCH 0/3] Add mmap(MAP_CONTIG) support Mike Kravetz
2017-10-12 1:46 ` [RFC PATCH 1/3] mm/map_contig: Add VM_CONTIG flag to vma struct Mike Kravetz
2017-10-12 1:46 ` [RFC PATCH 2/3] mm/map_contig: Use pre-allocated pages for VM_CONTIG mappings Mike Kravetz
2017-10-12 11:04 ` Anshuman Khandual
2017-10-12 1:46 ` [RFC PATCH 3/3] mm/map_contig: Add mmap(MAP_CONTIG) support Mike Kravetz
2017-10-12 11:22 ` Anshuman Khandual
2017-10-13 15:14 ` Christopher Lameter
2017-10-12 14:37 ` Michal Hocko
2017-10-12 17:19 ` Mike Kravetz
2017-10-13 8:40 ` Michal Hocko
2017-10-13 15:20 ` Christopher Lameter
2017-10-13 15:28 ` Michal Hocko
2017-10-13 15:42 ` Christopher Lameter
2017-10-13 15:47 ` Michal Hocko
[not found] ` <20171013154747.2jv7rtfqyyagiodn-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2017-10-13 15:56 ` Christopher Lameter
2017-10-13 16:17 ` Michal Hocko
2017-10-15 7:50 ` Guy Shattah
2017-10-16 8:24 ` Michal Hocko
[not found] ` <20171016082456.no6ux63uy2rmj4fe-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2017-10-16 9:11 ` Guy Shattah
2017-10-16 12:32 ` Michal Hocko
[not found] ` <20171016123248.csntl6luxgafst6q-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2017-10-16 16:00 ` Christopher Lameter
2017-10-16 17:42 ` Michal Hocko
[not found] ` <20171016174229.pz3o4uhzz3qbrp6n-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2017-10-16 17:56 ` Christopher Lameter
2017-10-16 18:17 ` Michal Hocko
2017-10-23 15:25 ` David Nellans
2017-10-17 10:50 ` Guy Shattah
[not found] ` <AM6PR0502MB378375AF8B569DBCCFE20D7DBD4C0-md96bDB8+JV1k1TWM4Wt8cDSnupUy6xnnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2017-10-17 10:59 ` Michal Hocko
2017-10-17 13:22 ` Michal Nazarewicz
2017-10-17 14:20 ` Guy Shattah
2017-10-17 17:44 ` Vlastimil Babka
2017-10-17 18:23 ` Mike Kravetz
2017-10-17 19:56 ` Vlastimil Babka
[not found] ` <752b49eb-55c6-5a34-ab41-6e91dd93ea70-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2017-10-16 10:33 ` Michal Nazarewicz
[not found] ` <xa1t60bfxtzw.fsf-deATy8a+UHjQT0dZR+AlfA@public.gmane.org>
2017-10-16 11:09 ` Guy Shattah
2017-10-16 17:43 ` Mike Kravetz
[not found] ` <aff6b405-6a06-f84d-c9b1-c6fb166dff81-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-10-16 18:07 ` Michal Hocko
2017-10-16 20:32 ` Mike Kravetz
2017-10-16 20:58 ` Michal Hocko
2017-10-16 21:03 ` Laura Abbott
2017-10-16 21:18 ` Mike Kravetz
[not found] ` <e8cf6227-003d-8a82-8b4d-07176b43810c-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-10-17 6:59 ` Vlastimil Babka
2017-10-15 6:58 ` Pavel Machek
2017-10-16 8:18 ` Michal Hocko
2017-10-16 9:54 ` Pavel Machek
2017-10-16 12:18 ` Michal Hocko
[not found] ` <20171016121808.m4sq3g5nxeyxoymc-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2017-10-16 16:02 ` Christopher Lameter
2017-10-16 17:33 ` Michal Hocko
2017-10-16 17:53 ` Christopher Lameter
2017-10-15 8:07 ` Guy Shattah
2017-10-12 10:36 ` [RFC PATCH 0/3] " Anshuman Khandual
2017-10-12 14:25 ` Anshuman Khandual [this message]
2017-10-23 22:10 ` [RFC] mmap(MAP_CONTIG) Dave Hansen
2017-10-24 22:49 ` 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=5a4de449-69b0-a9a4-c0bb-27198f4793c7@linux.vnet.ibm.com \
--to=khandual@linux.vnet.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=labbott@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=mike.kravetz@oracle.com \
--cc=mina86@mina86.com \
--cc=sguy@mellanox.com \
--cc=vbabka@suse.cz \
/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;
as well as URLs for NNTP newsgroup(s).