From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754409Ab2BCL1K (ORCPT ); Fri, 3 Feb 2012 06:27:10 -0500 Received: from gir.skynet.ie ([193.1.99.77]:55119 "EHLO gir.skynet.ie" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753069Ab2BCL1I (ORCPT ); Fri, 3 Feb 2012 06:27:08 -0500 Date: Fri, 3 Feb 2012 11:27:03 +0000 From: Mel Gorman To: Michal Nazarewicz Cc: Marek Szyprowski , 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, "'Kyungmin Park'" , "'Russell King'" , "'Andrew Morton'" , "'KAMEZAWA Hiroyuki'" , "'Daniel Walker'" , "'Arnd Bergmann'" , "'Jesse Barker'" , "'Jonathan Corbet'" , "'Shariq Hasnain'" , "'Chunsang Jeong'" , "'Dave Hansen'" , "'Benjamin Gaignard'" Subject: Re: [PATCH 02/15] mm: page_alloc: update migrate type of pages on pcp when isolating Message-ID: <20120203112703.GB5796@csn.ul.ie> References: <1327568457-27734-1-git-send-email-m.szyprowski@samsung.com> <1327568457-27734-3-git-send-email-m.szyprowski@samsung.com> <20120130111522.GE25268@csn.ul.ie> <20120130161447.GU25268@csn.ul.ie> <022e01cce034$bc6cf440$3546dcc0$%szyprowski@samsung.com> <20120202124729.GA5796@csn.ul.ie> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 02, 2012 at 08:53:25PM +0100, Michal Nazarewicz wrote: > >On Tue, Jan 31, 2012 at 05:23:59PM +0100, Marek Szyprowski wrote: > >>Pages, which have incorrect migrate type on free finally > >>causes pageblock migration type change from MIGRATE_CMA to MIGRATE_MOVABLE. > > On Thu, 02 Feb 2012 13:47:29 +0100, Mel Gorman wrote: > >I'm not quite seeing this. In free_hot_cold_page(), the pageblock > >type is checked so the page private should be set to MIGRATE_CMA or > >MIGRATE_ISOLATE for the CMA area. It's not clear how this can change a > >pageblock to MIGRATE_MOVABLE in error. > > Here's what I think may happen: > > When drain_all_pages() is called, __free_one_page() is called for each page on > pcp list with migrate type deducted from page_private() which is MIGRATE_CMA. > This result in the page being put on MIGRATE_CMA freelist even though its > pageblock's migrate type is MIGRATE_ISOLATE. > Ok, although it will only be allocated for MIGRATE_CMA-compatible requests so it is not a disaster. > When allocation happens and pcp list is empty, rmqueue_bulk() will get executed > with migratetype argument set to MIGRATE_MOVABLE. It calls __rmqueue() to grab > some pages and because the page described above is on MIGRATE_CMA freelist it > may be returned back to rmqueue_bulk(). > This will allocate the page from a pageblock we are trying to isolate pages from, but only for a movable page that can still be migrated. It does mean that CMA is doing more work than it should of course and the problem also impacts memory hot-remove. It's worse for memory hot-remove because potentially an UNMOVABLE page was allocated from a MIGRATE_ISOLATE pageblock. > But, pageblock's migrate type is not MIGRATE_CMA but MIGRATE_ISOLATE, so the > following code: > > #ifdef CONFIG_CMA > if (is_pageblock_cma(page)) > set_page_private(page, MIGRATE_CMA); > else > #endif > set_page_private(page, migratetype); > > will set it's private to MIGRATE_MOVABLE and in the end the page lands back > on MIGRATE_MOVABLE pcp list but this time with page_private == MIGRATE_MOVABLE > and not MIGRATE_CMA. > > One more drain_all_pages() (which may happen since alloc_contig_range() calls > set_migratetype_isolate() for each block) and next __rmqueue_fallback() may > convert the whole pageblock to MIGRATE_MOVABLE. > > I know, this sounds crazy and improbable, but I couldn't find an easier path > to destruction. As you pointed, once the page is allocated, free_hot_cold_page() > will do the right thing by reading pageblock's migrate type. > Ok, it's crazy but the problem is there. > Marek is currently experimenting with various patches including the following > change: > > #ifdef CONFIG_CMA > int mt = get_pageblock_migratetype(page); > if (is_migrate_cma(mt) || mt == MIGRATE_ISOLATE) > set_page_private(page, mt); > else > #endif > set_page_private(page, migratetype); > > As a matter of fact, if __rmqueue() was changed to return migrate type of the > freelist it took page from, we could avoid this get_pageblock_migratetype() all > together. For now, however, I'd rather not go that way just yet -- I'll be happy > to dig into it once CMA gets merged. > Ok, thanks for persisting with this. -- Mel Gorman SUSE Labs