linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: 'James Bottomley' <James.Bottomley@HansenPartnership.com>,
	'Arnd Bergmann' <arnd@arndb.de>
Cc: 'Russell King - ARM Linux' <linux@arm.linux.org.uk>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org, linux-mm@kvack.org,
	linaro-mm-sig@lists.linaro.org,
	'Daniel Walker' <dwalker@codeaurora.org>,
	'Jonathan Corbet' <corbet@lwn.net>, 'Mel Gorman' <mel@csn.ul.ie>,
	'Chunsang Jeong' <chunsang.jeong@linaro.org>,
	'Michal Nazarewicz' <mina86@mina86.com>,
	'Jesse Barker' <jesse.barker@linaro.org>,
	'Kyungmin Park' <kyungmin.park@samsung.com>,
	'Ankita Garg' <ankita@in.ibm.com>,
	'Andrew Morton' <akpm@linux-foundation.org>,
	'KAMEZAWA Hiroyuki' <kamezawa.hiroyu@jp.fujitsu.com>,
	ksummit-2011-discuss@lists.linux-foundation.org
Subject: RE: [PATCH 6/8] drivers: add Contiguous Memory Allocator
Date: Mon, 26 Sep 2011 14:06:43 +0200	[thread overview]
Message-ID: <011c01cc7c44$c1aea3d0$450beb70$%szyprowski@samsung.com> (raw)
In-Reply-To: <1312393430.2855.51.camel@mulgrave>

Hello,

I'm sorry for the late reply. I must have missed this mail...

On Wednesday, August 03, 2011 7:44 PM James Bottomley wrote:

> [cc to ks-discuss added, since this may be a relevant topic]
> 
> On Tue, 2011-07-05 at 14:27 +0200, Arnd Bergmann wrote:
> > On Tuesday 05 July 2011, Russell King - ARM Linux wrote:
> > > On Tue, Jul 05, 2011 at 09:41:48AM +0200, Marek Szyprowski wrote:
> > > > The Contiguous Memory Allocator is a set of helper functions for DMA
> > > > mapping framework that improves allocations of contiguous memory chunks.
> > > >
> > > > CMA grabs memory on system boot, marks it with CMA_MIGRATE_TYPE and
> > > > gives back to the system. Kernel is allowed to allocate movable pages
> > > > within CMA's managed memory so that it can be used for example for page
> > > > cache when DMA mapping do not use it. On dma_alloc_from_contiguous()
> > > > request such pages are migrated out of CMA area to free required
> > > > contiguous block and fulfill the request. This allows to allocate large
> > > > contiguous chunks of memory at any time assuming that there is enough
> > > > free memory available in the system.
> > > >
> > > > This code is heavily based on earlier works by Michal Nazarewicz.
> > >
> > > And how are you addressing the technical concerns about aliasing of
> > > cache attributes which I keep bringing up with this and you keep
> > > ignoring and telling me that I'm standing in your way.
> 
> Just to chime in here, parisc has an identical issue.  If the CPU ever
> sees an alias with different attributes for the same page, it will HPMC
> the box (that's basically the bios will kill the system as being
> architecturally inconsistent), so an architecture neutral solution on
> this point is essential to us as well.
>
> > This is of course an important issue, and it's the one item listed as
> > TODO in the introductory mail that sent.
> >
> > It's also a preexisting problem as far as I can tell, and it needs
> > to be solved in __dma_alloc for both cases, dma_alloc_from_contiguous
> > and __alloc_system_pages as introduced in patch 7.
> >
> > We've discussed this back and forth, and it always comes down to
> > one of two ugly solutions:
> >
> > 1. Put all of the MIGRATE_CMA and pages into highmem and change
> > __alloc_system_pages so it also allocates only from highmem pages.
> > The consequences of this are that we always need to build kernels
> > with highmem enabled and that we have less lowmem on systems that
> > are already small, both of which can be fairly expensive unless
> > you have lots of highmem already.
> 
> So this would require that systems using the API have a highmem? (parisc
> doesn't today).

Yes, such solution will require highmem. It will introduce the highmem 
issues to systems that typically don't use highmem, that's why I searched
for other solutions.
 
> > 2. Add logic to unmap pages from the linear mapping, which is
> > very expensive because it forces the use of small pages in the
> > linear mapping (or in parts of it), and possibly means walking
> > all page tables to remove the PTEs on alloc and put them back
> > in on free.
> >
> > I believe that Chunsang Jeong from Linaro is planning to
> > implement both variants and post them for review, so we can
> > decide which one to merge, or even to merge both and make
> > it a configuration option. See also
> > https://blueprints.launchpad.net/linaro-mm-sig/+spec/engr-mm-dma-mapping-2011.07
> >
> > I don't think we need to make merging the CMA patches depending on
> > the other patches, it's clear that both need to be solved, and
> > they are independent enough.
> 
> I assume from the above that ARM has a hardware page walker?

Right.

> The way I'd fix this on parisc, because we have a software based TLB, is
> to rely on the fact that a page may only be used either for DMA or for
> Page Cache, so the aliases should never be interleaved.  Since you know
> the point at which the page flips from DMA to Cache (and vice versa),
> I'd purge the TLB entry and flush the page at that point and rely on the
> usage guarantees to ensure that the alias TLB entry doesn't reappear.
> This isn't inexpensive but the majority of the cost is the cache flush
> which is a requirement to clean the aliases anyway (a TLB entry purge is
> pretty cheap).
> 
> Would this work for the ARM hardware walker as well?  It would require
> you to have a TLB entry purge instruction as well as some architectural
> guarantees about not speculating the TLB.

The main problem with ARM linear mapping is the fact that it is created 
using 2MiB sections, so entries for kernel linear mapping fits entirely in
first lever of process page table. This implies that direct changing this
linear mapping is not easy task and must be performed for all tasks in the
system. In my CMA v12+ patches I decided to use simpler way of solving this
issue. I rely on the fact that DMA memory is allocated only from CMA regions,
so during early boot I change the kernel linear mappings for these regions.
Instead of 2MiB sections, I use regular 4KiB pages which create 2 level of
page tables. Second level of page table for these regions can be easily
shared for all processes in the system.

This way I can easily update cache attributes for any single 4KiB page that
is used for DMA and avoid any aliasing at all. The only drawback of this
method is larger TLB pressure what might result in some slowdown during
heavy IO if pages with 4KiB linear mapping are used. However with my 
hardware has only slow io (with eMMC I get only about 30MiB/s) so I cannot
notice any impact of the mapping method on the io speed.

Best regards
-- 
Marek Szyprowski
Samsung Poland R&D Center




  reply	other threads:[~2011-09-26 12:06 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05  7:41 [PATCHv11 0/8] Contiguous Memory Allocator Marek Szyprowski
2011-07-05  7:41 ` [PATCH 1/8] mm: move some functions from memory_hotplug.c to page_isolation.c Marek Szyprowski
2011-07-05 11:27   ` Arnd Bergmann
2011-07-05  7:41 ` [PATCH 2/8] mm: alloc_contig_freed_pages() added Marek Szyprowski
2011-07-05 11:30   ` Arnd Bergmann
2011-07-05  7:41 ` [PATCH 3/8] mm: alloc_contig_range() added Marek Szyprowski
2011-07-05 11:31   ` Arnd Bergmann
2011-07-05  7:41 ` [PATCH 4/8] mm: MIGRATE_CMA migration type added Marek Szyprowski
2011-07-05 11:44   ` Arnd Bergmann
2011-07-05 12:27     ` Russell King - ARM Linux
2011-07-05  7:41 ` [PATCH 5/8] mm: MIGRATE_CMA isolation functions added Marek Szyprowski
2011-07-05 11:45   ` Arnd Bergmann
2011-07-05  7:41 ` [PATCH 6/8] drivers: add Contiguous Memory Allocator Marek Szyprowski
2011-07-05 10:24   ` Marek Szyprowski
2011-07-05 11:02   ` [PATCH 6/8 RESEND] " Marek Szyprowski
2011-07-05 11:50     ` Arnd Bergmann
2011-07-05 11:33   ` [PATCH 6/8] " Russell King - ARM Linux
2011-07-05 12:27     ` Arnd Bergmann
2011-07-05 12:30       ` Russell King - ARM Linux
2011-07-05 13:58         ` Arnd Bergmann
2011-07-08 17:25           ` Russell King - ARM Linux
2011-07-12 13:39             ` Arnd Bergmann
2011-08-03 17:43       ` James Bottomley
2011-09-26 12:06         ` Marek Szyprowski [this message]
2011-09-26 13:00         ` Russell King - ARM Linux
2011-07-06 13:58     ` Marek Szyprowski
2011-07-06 14:09       ` Arnd Bergmann
2011-07-06 14:23         ` Russell King - ARM Linux
2011-07-06 14:37           ` [Linaro-mm-sig] " Nicolas Pitre
2011-07-06 14:59             ` Arnd Bergmann
2011-07-09 14:57               ` Janusz Krzysztofik
2011-07-11 13:47                 ` Marek Szyprowski
2011-07-11 19:01                   ` Janusz Krzysztofik
2011-07-12  5:34                     ` Marek Szyprowski
2011-07-06 14:51           ` Arnd Bergmann
2011-07-06 15:48             ` Russell King - ARM Linux
2011-07-06 16:05               ` Christoph Lameter
2011-07-06 16:09                 ` Michal Nazarewicz
2011-07-06 16:19                   ` Christoph Lameter
2011-07-06 17:15                     ` Russell King - ARM Linux
2011-07-06 19:03                       ` Christoph Lameter
2011-07-06 17:02                 ` Russell King - ARM Linux
2011-07-06 16:31               ` Arnd Bergmann
2011-07-06 19:10                 ` Nicolas Pitre
2011-07-06 20:23                   ` [Linaro-mm-sig] " Arnd Bergmann
2011-07-07  5:29                     ` Nicolas Pitre
2011-07-06 14:56         ` Marek Szyprowski
2011-07-06 15:37           ` Russell King - ARM Linux
2011-07-06 15:47             ` Marek Szyprowski
2011-07-14 12:29   ` Marek Szyprowski
2011-07-05  7:41 ` [PATCH 7/8] ARM: integrate CMA with dma-mapping subsystem Marek Szyprowski
2011-07-05 11:50   ` Arnd Bergmann
2011-07-05  7:41 ` [PATCH 8/8] ARM: S5PV210: example of CMA private area for FIMC device on Goni board Marek Szyprowski
2011-07-05 11:51   ` Arnd Bergmann
2011-07-05 12:07 ` [PATCHv11 0/8] Contiguous Memory Allocator Arnd Bergmann
2011-07-05 12:28   ` Russell King - ARM Linux
2011-07-06 22:11   ` Andrew Morton
2011-07-07  7:36     ` Arnd Bergmann
2011-07-11 13:24     ` Marek Szyprowski
2011-07-20  8:57 [PATCHv12 " Marek Szyprowski
2011-07-20  8:57 ` [PATCH 6/8] drivers: add " Marek Szyprowski
2011-08-19 14:27 [PATCHv15 0/8] " Marek Szyprowski
2011-08-19 14:27 ` [PATCH 6/8] drivers: add " Marek Szyprowski

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='011c01cc7c44$c1aea3d0$450beb70$%szyprowski@samsung.com' \
    --to=m.szyprowski@samsung.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=ankita@in.ibm.com \
    --cc=arnd@arndb.de \
    --cc=chunsang.jeong@linaro.org \
    --cc=corbet@lwn.net \
    --cc=dwalker@codeaurora.org \
    --cc=jesse.barker@linaro.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=ksummit-2011-discuss@lists.linux-foundation.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mel@csn.ul.ie \
    --cc=mina86@mina86.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;
as well as URLs for NNTP newsgroup(s).