Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752545AbbESDzw (ORCPT ); Mon, 18 May 2015 23:55:52 -0400 Received: from mta-out1.inet.fi ([62.71.2.227]:60870 "EHLO johanna1.rokki.sonera.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751592AbbESDzt (ORCPT ); Mon, 18 May 2015 23:55:49 -0400 RazorGate-KAS: Rate: 5 RazorGate-KAS: {RECEIVED: dynamic ip detected} RazorGate-KAS: Envelope from: RazorGate-KAS: Version: 5.5.3 RazorGate-KAS: LuaCore: 80 2014-11-10_18-01-23 260f8afb9361da3c7edfd3a8e3a4ca908191ad29 RazorGate-KAS: Method: none RazorGate-KAS: Lua profiles 69136 [Nov 12 2014] RazorGate-KAS: Status: not_detected Date: Tue, 19 May 2015 06:55:15 +0300 From: "Kirill A. Shutemov" To: Vlastimil Babka Cc: "Kirill A. Shutemov" , Andrew Morton , Andrea Arcangeli , Hugh Dickins , Dave Hansen , Mel Gorman , Rik van Riel , Christoph Lameter , Naoya Horiguchi , Steve Capper , "Aneesh Kumar K.V" , Johannes Weiner , Michal Hocko , Jerome Marchand , Sasha Levin , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCHv5 19/28] mm: store mapcount for compound page separately Message-ID: <20150519035515.GA5795@node.dhcp.inet.fi> References: <1429823043-157133-1-git-send-email-kirill.shutemov@linux.intel.com> <1429823043-157133-20-git-send-email-kirill.shutemov@linux.intel.com> <5559F7F6.7060801@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5559F7F6.7060801@suse.cz> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3618 Lines: 98 On Mon, May 18, 2015 at 04:32:22PM +0200, Vlastimil Babka wrote: > On 04/23/2015 11:03 PM, Kirill A. Shutemov wrote: > >We're going to allow mapping of individual 4k pages of THP compound and > >we need a cheap way to find out how many time the compound page is > >mapped with PMD -- compound_mapcount() does this. > > > >We use the same approach as with compound page destructor and compound > >order: use space in first tail page, ->mapping this time. > > > >page_mapcount() counts both: PTE and PMD mappings of the page. > > > >Signed-off-by: Kirill A. Shutemov > >Tested-by: Sasha Levin > >--- > > include/linux/mm.h | 25 ++++++++++++-- > > include/linux/mm_types.h | 1 + > > include/linux/rmap.h | 4 +-- > > mm/debug.c | 5 ++- > > mm/huge_memory.c | 2 +- > > mm/hugetlb.c | 4 +-- > > mm/memory.c | 2 +- > > mm/migrate.c | 2 +- > > mm/page_alloc.c | 14 ++++++-- > > mm/rmap.c | 87 +++++++++++++++++++++++++++++++++++++----------- > > 10 files changed, 114 insertions(+), 32 deletions(-) > > > >diff --git a/include/linux/mm.h b/include/linux/mm.h > >index dad667d99304..33cb3aa647a6 100644 > >--- a/include/linux/mm.h > >+++ b/include/linux/mm.h > >@@ -393,6 +393,19 @@ static inline int is_vmalloc_or_module_addr(const void *x) > > > > extern void kvfree(const void *addr); > > > >+static inline atomic_t *compound_mapcount_ptr(struct page *page) > >+{ > >+ return &page[1].compound_mapcount; > >+} > >+ > >+static inline int compound_mapcount(struct page *page) > >+{ > >+ if (!PageCompound(page)) > >+ return 0; > >+ page = compound_head(page); > >+ return atomic_read(compound_mapcount_ptr(page)) + 1; > >+} > >+ > > /* > > * The atomic page->_mapcount, starts from -1: so that transitions > > * both from it and to it can be tracked, using atomic_inc_and_test > > What's not shown here is the implementation of page_mapcount_reset() that's > unchanged... is that correct from all callers? Looks like page_mapcount_reset() is mostly use to deal with PageBuddy() and such. We don't have this kind of tricks for compound_mapcount. > >@@ -405,8 +418,16 @@ static inline void page_mapcount_reset(struct page *page) > > > > static inline int page_mapcount(struct page *page) > > { > >+ int ret; > > VM_BUG_ON_PAGE(PageSlab(page), page); > >- return atomic_read(&page->_mapcount) + 1; > >+ ret = atomic_read(&page->_mapcount) + 1; > >+ /* > >+ * Positive compound_mapcount() offsets ->_mapcount in every page by > >+ * one. Let's substract it here. > >+ */ > > This could use some more detailed explanation, or at least pointers to the > relevant rmap functions. Also in commit message. Okay. Will do. > > >+ if (compound_mapcount(page)) > >+ ret += compound_mapcount(page) - 1; > > This looks like it could uselessly duplicate-inline the code for > compound_mapcount(). It has atomics and smp_rmb() so I'm not sure if the > compiler can just "squash it". Good point. I'll rework this. > > On the other hand, a simple atomic read that was page_mapcount() has turned > into multiple atomic reads and flag checks. What about the stability of the > whole result? Are all callers ok? (maybe a later page deals with it). Urghh.. I'll look into this. -- Kirill A. Shutemov -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/