From: Mike Kravetz <mike.kravetz@oracle.com>
To: Anshuman Khandual <khandual@linux.vnet.ibm.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>
Subject: Re: [RFC] mmap(MAP_CONTIG)
Date: Wed, 4 Oct 2017 10:35:52 -0700 [thread overview]
Message-ID: <c0f5808f-3ba7-4737-b0e1-b2bfddf9384c@oracle.com> (raw)
In-Reply-To: <97c81533-5206-b130-1aeb-c5b9bfd93287@linux.vnet.ibm.com>
On 10/04/2017 06:49 AM, Anshuman Khandual wrote:
> On 10/04/2017 05:26 AM, Mike Kravetz wrote:
>> At Plumbers this year, Guy Shattah and Christoph Lameter gave a presentation
>> titled 'User space contiguous memory allocation for DMA' [1]. The slides
>> point out the performance benefits of devices that can take advantage of
>> larger physically contiguous areas.
>>
>> When such physically contiguous allocations are done today, they are done
>> within drivers themselves in an ad-hoc manner. In addition to allocations
>> for DMA, allocations of this type are also performed for buffers used by
>> coprocessors and other acceleration engines.
>
> Right.
>
>>
>> As mentioned in the presentation, posix specifies an interface to obtain
>> physically contiguous memory. This is via typed memory objects as described
>> in the posix_typed_mem_open() man page. Since Linux today does not follow
>> the posix typed memory object model, adding infrastructure for contiguous
>> memory allocations seems to be overkill. Instead, a proposal was suggested
>> to add support via a mmap flag: MAP_CONTIG.
>
> Right.
>
>>
>> mmap(MAP_CONTIG) would have the following semantics:
>> - The entire mapping (length size) would be backed by physically contiguous
>> pages.
>> - If 'length' physically contiguous pages can not be allocated, then mmap
>> will fail.
>> - MAP_CONTIG only works with MAP_ANONYMOUS mappings.
>> - MAP_CONTIG will lock the associated pages in memory. As such, the same
>> privileges and limits that apply to mlock will also apply to MAP_CONTIG.
>> - A MAP_CONTIG mapping can not be expanded.
>
> Why ? May be we have memory around the edge of the existing mapping. Why
> give up before trying ?
Just a simplification. If not to complicated, we could add support for
expansion. But, it may not be worth the cost and I do not know if there
would be any real use cases.
>> - At fork time, private MAP_CONTIG mappings will be converted to regular
>> (non-MAP_CONTIG) mapping in the child. As such a COW fault in the child
>> will not require a contiguous allocation.
>
> Makes sense but need to be documented as the child still knows that the buffer
> came from a mmap(MAP_CONTIG) call in the parent.
>
>>
>> Some implementation considerations:
>> - alloc_contig_range() or similar will be used for allocations larger
>> than MAX_ORDER.
>
> As I had also mentioned during the presentation at Plumbers, there should be
> a fallback approach while attempting to allocate the contiguous memory.
>
> - If order < MAX_ORDER -> alloc_pages()
> - If order > MAX_ORDER -> alloc_contig_range()
> - If alloc_contig_range() fails attempt a CMA based allocation scheme
> The CMA area should have been initialized at the boot exclusively for
> this purpose (may be with a CONFIG option if some one wants to go for
> this fallback at all) and use cma_alloc() on that area when we need
> to service MAP_CONTIG requests.
I am not sure about the use of CMA and requiring admin setup. It is
something that can be considered. However, I suspect people would want
to avoid admin interaction/requirements if possible.
>> - MAP_CONTIG should imply MAP_POPULATE. At mmap time, all pages for the
>> mapping must be 'pre-allocated', and they can only be used for the mapping,
>> so it makes sense to 'fault in' all pages.
>
>
>> - Using 'pre-allocated' pages in the fault paths may be intrusive.
>
> But we have already faulted in all of them for the mapping and they
> are also locked. Hence there should not be any page faults any more
> for the VMA. Am I missing something here ?
I was referring to the action of pre-populating the mapping. Today that
is done via the normal fault paths. So, if we use this same scheme for
MAP_CONTIG, the fault paths would need to know about pre-allocated pages.
Sorry for not being more clear as that may have been a source of confusion.
>> - We need to keep keep track of those pre-allocated pages until the vma is
>> tore down, especially if free_contig_range() must be called
>
> Right, probably tracking them as part of the vm_area_struct itself.
>
>>
>> Thoughts?
>> - Is such an interface useful?
>> - Any other ideas on how to achieve the same functionality?
>> - Any thoughts on implementation?
>>
>> I have started down the path of pre-allocating contiguous pages at mmap
>> time and hanging those off the vma(vm_private_data) with some kludges to
>> use the pages at fault time. It is really ugly, which is why I am not
>> sharing the code. Hoping for some comments/suggestions.
>
> I am still wondering why wait till fault time not pre fault all of them
> and populate the page tables.
Yes, that is the idea. I just did not state clearly above.
--
Mike Kravetz
--
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-04 17:36 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 23:56 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 [this message]
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
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
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
2017-10-16 10:33 ` Michal Nazarewicz
2017-10-16 11:09 ` Guy Shattah
2017-10-16 17:43 ` Mike Kravetz
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
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
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=c0f5808f-3ba7-4737-b0e1-b2bfddf9384c@oracle.com \
--to=mike.kravetz@oracle.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=khandual@linux.vnet.ibm.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=mina86@mina86.com \
--cc=sguy@mellanox.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