linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
To: Minchan Kim <minchan@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Rik van Riel <riel@redhat.com>,
	Laura Abbott <lauraa@codeaurora.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Michal Nazarewicz <mina86@mina86.com>,
	Heesub Shin <heesub.shin@samsung.com>,
	Mel Gorman <mgorman@suse.de>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: Re: [RFC PATCH 2/3] CMA: aggressively allocate the pages on cma reserved memory when not used
Date: Tue, 20 May 2014 15:33:42 +0900	[thread overview]
Message-ID: <20140520063342.GA8315@js1304-P5Q-DELUXE> (raw)
In-Reply-To: <20140519231859.GA21636@bbox>

On Tue, May 20, 2014 at 08:18:59AM +0900, Minchan Kim wrote:
> On Mon, May 19, 2014 at 01:50:01PM +0900, Joonsoo Kim wrote:
> > On Mon, May 19, 2014 at 11:53:05AM +0900, Minchan Kim wrote:
> > > On Mon, May 19, 2014 at 11:11:21AM +0900, Joonsoo Kim wrote:
> > > > On Thu, May 15, 2014 at 11:43:53AM +0900, Minchan Kim wrote:
> > > > > On Thu, May 15, 2014 at 10:53:01AM +0900, Joonsoo Kim wrote:
> > > > > > On Tue, May 13, 2014 at 12:00:57PM +0900, Minchan Kim wrote:
> > > > > > > Hey Joonsoo,
> > > > > > > 
> > > > > > > On Thu, May 08, 2014 at 09:32:23AM +0900, Joonsoo Kim wrote:
> > > > > > > > CMA is introduced to provide physically contiguous pages at runtime.
> > > > > > > > For this purpose, it reserves memory at boot time. Although it reserve
> > > > > > > > memory, this reserved memory can be used for movable memory allocation
> > > > > > > > request. This usecase is beneficial to the system that needs this CMA
> > > > > > > > reserved memory infrequently and it is one of main purpose of
> > > > > > > > introducing CMA.
> > > > > > > > 
> > > > > > > > But, there is a problem in current implementation. The problem is that
> > > > > > > > it works like as just reserved memory approach. The pages on cma reserved
> > > > > > > > memory are hardly used for movable memory allocation. This is caused by
> > > > > > > > combination of allocation and reclaim policy.
> > > > > > > > 
> > > > > > > > The pages on cma reserved memory are allocated if there is no movable
> > > > > > > > memory, that is, as fallback allocation. So the time this fallback
> > > > > > > > allocation is started is under heavy memory pressure. Although it is under
> > > > > > > > memory pressure, movable allocation easily succeed, since there would be
> > > > > > > > many pages on cma reserved memory. But this is not the case for unmovable
> > > > > > > > and reclaimable allocation, because they can't use the pages on cma
> > > > > > > > reserved memory. These allocations regard system's free memory as
> > > > > > > > (free pages - free cma pages) on watermark checking, that is, free
> > > > > > > > unmovable pages + free reclaimable pages + free movable pages. Because
> > > > > > > > we already exhausted movable pages, only free pages we have are unmovable
> > > > > > > > and reclaimable types and this would be really small amount. So watermark
> > > > > > > > checking would be failed. It will wake up kswapd to make enough free
> > > > > > > > memory for unmovable and reclaimable allocation and kswapd will do.
> > > > > > > > So before we fully utilize pages on cma reserved memory, kswapd start to
> > > > > > > > reclaim memory and try to make free memory over the high watermark. This
> > > > > > > > watermark checking by kswapd doesn't take care free cma pages so many
> > > > > > > > movable pages would be reclaimed. After then, we have a lot of movable
> > > > > > > > pages again, so fallback allocation doesn't happen again. To conclude,
> > > > > > > > amount of free memory on meminfo which includes free CMA pages is moving
> > > > > > > > around 512 MB if I reserve 512 MB memory for CMA.
> > > > > > > > 
> > > > > > > > I found this problem on following experiment.
> > > > > > > > 
> > > > > > > > 4 CPUs, 1024 MB, VIRTUAL MACHINE
> > > > > > > > make -j24
> > > > > > > > 
> > > > > > > > CMA reserve:		0 MB		512 MB
> > > > > > > > Elapsed-time:		234.8		361.8
> > > > > > > > Average-MemFree:	283880 KB	530851 KB
> > > > > > > > 
> > > > > > > > To solve this problem, I can think following 2 possible solutions.
> > > > > > > > 1. allocate the pages on cma reserved memory first, and if they are
> > > > > > > >    exhausted, allocate movable pages.
> > > > > > > > 2. interleaved allocation: try to allocate specific amounts of memory
> > > > > > > >    from cma reserved memory and then allocate from free movable memory.
> > > > > > > 
> > > > > > > I love this idea but when I see the code, I don't like that.
> > > > > > > In allocation path, just try to allocate pages by round-robin so it's role
> > > > > > > of allocator. If one of migratetype is full, just pass mission to reclaimer
> > > > > > > with hint(ie, Hey reclaimer, it's non-movable allocation fail
> > > > > > > so there is pointless if you reclaim MIGRATE_CMA pages) so that
> > > > > > > reclaimer can filter it out during page scanning.
> > > > > > > We already have an tool to achieve it(ie, isolate_mode_t).
> > > > > > 
> > > > > > Hello,
> > > > > > 
> > > > > > I agree with leaving fast allocation path as simple as possible.
> > > > > > I will remove runtime computation for determining ratio in
> > > > > > __rmqueue_cma() and, instead, will use pre-computed value calculated
> > > > > > on the other path.
> > > > > 
> > > > > Sounds good.
> > > > > 
> > > > > > 
> > > > > > I am not sure that whether your second suggestion(Hey relaimer part)
> > > > > > is good or not. In my quick thought, that could be helpful in the
> > > > > > situation that many free cma pages remained. But, it would be not helpful
> > > > > > when there are neither free movable and cma pages. In generally, most
> > > > > > workloads mainly uses movable pages for page cache or anonymous mapping.
> > > > > > Although reclaim is triggered by non-movable allocation failure, reclaimed
> > > > > > pages are used mostly by movable allocation. We can handle these allocation
> > > > > > request even if we reclaim the pages just in lru order. If we rotate
> > > > > > the lru list for finding movable pages, it could cause more useful
> > > > > > pages to be evicted.
> > > > > > 
> > > > > > This is just my quick thought, so please let me correct if I am wrong.
> > > > > 
> > > > > Why should reclaimer reclaim unnecessary pages?
> > > > > So, your answer is that it would be better because upcoming newly allocated
> > > > > pages would be allocated easily without interrupt. But it could reclaim
> > > > > too much pages until watermark for unmovable allocation is okay.
> > > > > Even, sometime, you might see OOM.
> > > > > 
> > > > > Moreover, how could you handle current trobule?
> > > > > For example, there is atomic allocation and the only thing to save the world
> > > > > is kswapd because it's one of kswapd role but kswapd is spending many time to
> > > > > reclaim CMA pages, which is pointless so the allocation would be easily failed.
> > > > 
> > > > Hello,
> > > > 
> > > > I guess that it isn't the problem. In lru, movable pages and cma pages
> > > > would be interleaved. So it doesn't takes too long time to get the
> > > > page for non-movable allocation.
> > > 
> > > Please, don't assume there are ideal LRU ordering.
> > > Newly allocated page by fairness allocation is located by head of LRU
> > > while old pages are approaching the tail so there is huge time gab.
> > > During the time, old pages could be dropped/promoting so one of side
> > > could be filled with one type rather than interleaving both types pages
> > > you expected.
> > 
> > I assumed general case, not ideal case.
> > Your example can be possible, but would be corner case.
> 
> I talked with Joonsoo yesterday and should post our conclusion
> for other reviewers/maintainers.
> 
> It's not a corner case and it could happen depending on zone and CMA
> configuration. For example, there is 330M high zone and CMA consumes
> 300M in the space while normal movable area consumes just 30M.
> In the case, unmovable allocation could make too many unnecessary
> reclaiming of the zone so the conclusion we reached is to need target
> reclaiming(ex, isolate_mode_t).
> 
> But not sure it should be part of this patchset because this patchset
> is surely enhance(ie, before, it was hard to allocate page from CMA area
> but this patchset makes it works) but this patchset could make mentioned
> problem as side-effect so I think we could solve the issue(ie, too many
> reclaiming in unbalanced zone) in another patchset.
> 
> Joonsoo, please mention this problem in the description when you respin
> so other MM guys can notice that and give ideas, which would be helpful
> a lot.

Okay. Will do :)

Thanks.

  reply	other threads:[~2014-05-20  6:31 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-08  0:32 [RFC PATCH 0/3] Aggressively allocate the pages on cma reserved memory Joonsoo Kim
2014-05-08  0:32 ` [RFC PATCH 1/3] CMA: remove redundant retrying code in __alloc_contig_migrate_range Joonsoo Kim
2014-05-09 15:44   ` Michal Nazarewicz
2014-05-08  0:32 ` [RFC PATCH 2/3] CMA: aggressively allocate the pages on cma reserved memory when not used Joonsoo Kim
2014-05-09 15:45   ` Michal Nazarewicz
2014-05-12 17:04   ` Laura Abbott
2014-05-13  1:14     ` Joonsoo Kim
2014-05-13  3:05     ` Minchan Kim
2014-05-24  0:57     ` Laura Abbott
2014-05-26  2:44       ` Joonsoo Kim
2014-05-13  3:00   ` Minchan Kim
2014-05-15  1:53     ` Joonsoo Kim
2014-05-15  2:43       ` Minchan Kim
2014-05-19  2:11         ` Joonsoo Kim
2014-05-19  2:53           ` Minchan Kim
2014-05-19  4:50             ` Joonsoo Kim
2014-05-19 23:18               ` Minchan Kim
2014-05-20  6:33                 ` Joonsoo Kim [this message]
2014-05-15  2:45       ` Heesub Shin
2014-05-15  5:06         ` Minchan Kim
2014-05-19 23:22         ` Minchan Kim
2014-05-16  8:02       ` [RFC][PATCH] CMA: drivers/base/Kconfig: restrict CMA size to non-zero value Gioh Kim
2014-05-16 17:45         ` Michal Nazarewicz
2014-05-19  1:47           ` Gioh Kim
2014-05-19  5:55             ` Joonsoo Kim
2014-05-19  9:14               ` Gioh Kim
2014-05-19 19:59               ` Michal Nazarewicz
2014-05-20  0:50                 ` Gioh Kim
2014-05-20  1:28                   ` Michal Nazarewicz
2014-05-20  2:26                     ` Gioh Kim
2014-05-20 18:15                       ` Michal Nazarewicz
2014-05-20 11:38                   ` Marek Szyprowski
2014-05-21  0:15                     ` Gioh Kim
2014-05-14  8:42   ` [RFC PATCH 2/3] CMA: aggressively allocate the pages on cma reserved memory when not used Aneesh Kumar K.V
2014-05-15  1:58     ` Joonsoo Kim
2014-05-18 17:36       ` Aneesh Kumar K.V
2014-05-19  2:29         ` Joonsoo Kim
2014-05-08  0:32 ` [RFC PATCH 3/3] CMA: always treat free cma pages as non-free on watermark checking Joonsoo Kim
2014-05-09 15:46   ` Michal Nazarewicz
2014-05-09 12:39 ` [RFC PATCH 0/3] Aggressively allocate the pages on cma reserved memory Marek Szyprowski
2014-05-13  2:26   ` Joonsoo Kim
2014-05-14  9:44     ` Aneesh Kumar K.V
2014-05-15  2:10       ` Joonsoo Kim
2014-05-15  9:47         ` Mel Gorman
2014-05-19  2:12           ` Joonsoo Kim

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=20140520063342.GA8315@js1304-P5Q-DELUXE \
    --to=iamjoonsoo.kim@lge.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=heesub.shin@samsung.com \
    --cc=lauraa@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mgorman@suse.de \
    --cc=mina86@mina86.com \
    --cc=minchan@kernel.org \
    --cc=riel@redhat.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).