From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965251AbbFJOef (ORCPT ); Wed, 10 Jun 2015 10:34:35 -0400 Received: from cantor2.suse.de ([195.135.220.15]:50764 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965133AbbFJOe3 (ORCPT ); Wed, 10 Jun 2015 10:34:29 -0400 Message-ID: <55784AF2.2030602@suse.cz> Date: Wed, 10 Jun 2015 16:34:26 +0200 From: Vlastimil Babka User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "Kirill A. Shutemov" , Andrew Morton , Andrea Arcangeli , Hugh Dickins CC: 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: [PATCHv6 27/36] mm: differentiate page_mapped() from page_mapcount() for compound pages References: <1433351167-125878-1-git-send-email-kirill.shutemov@linux.intel.com> <1433351167-125878-28-git-send-email-kirill.shutemov@linux.intel.com> In-Reply-To: <1433351167-125878-28-git-send-email-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/03/2015 07:05 PM, Kirill A. Shutemov wrote: > Let's define page_mapped() to be true for compound pages if any > sub-pages of the compound page is mapped (with PMD or PTE). > > On other hand page_mapcount() return mapcount for this particular small > page. > > This will make cases like page_get_anon_vma() behave correctly once we > allow huge pages to be mapped with PTE. > > Most users outside core-mm should use page_mapcount() instead of > page_mapped(). > > Signed-off-by: Kirill A. Shutemov > Tested-by: Sasha Levin [...] > @@ -917,10 +917,21 @@ static inline pgoff_t page_file_index(struct page *page) > > /* > * Return true if this page is mapped into pagetables. > + * For compound page it returns true if any subpage of compound page is mapped. > */ > -static inline int page_mapped(struct page *page) > +static inline bool page_mapped(struct page *page) > { > - return atomic_read(&(page)->_mapcount) + compound_mapcount(page) >= 0; > + int i; > + if (likely(!PageCompound(page))) > + return atomic_read(&page->_mapcount) >= 0; > + page = compound_head(page); > + if (compound_mapcount(page)) Same optimization opportunity as I pointed out in previous patch for page_mapcount(). > + return true; > + for (i = 0; i < hpage_nr_pages(page); i++) { > + if (atomic_read(&page[i]._mapcount) >= 0) > + return true; > + } > + return true; > } > > /* > diff --git a/mm/filemap.c b/mm/filemap.c > index cb41cf3069d2..c6cf03303ded 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -202,7 +202,7 @@ void __delete_from_page_cache(struct page *page, void *shadow) > __dec_zone_page_state(page, NR_FILE_PAGES); > if (PageSwapBacked(page)) > __dec_zone_page_state(page, NR_SHMEM); > - BUG_ON(page_mapped(page)); > + VM_BUG_ON_PAGE(page_mapped(page), page); > > /* > * At this point page must be either written or cleaned by truncate. > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by kanga.kvack.org (Postfix) with ESMTP id 1A7AB6B0038 for ; Wed, 10 Jun 2015 10:34:31 -0400 (EDT) Received: by wigg3 with SMTP id g3so50689966wig.1 for ; Wed, 10 Jun 2015 07:34:30 -0700 (PDT) Received: from mx2.suse.de (cantor2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id gb5si18423993wjb.21.2015.06.10.07.34.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 10 Jun 2015 07:34:29 -0700 (PDT) Message-ID: <55784AF2.2030602@suse.cz> Date: Wed, 10 Jun 2015 16:34:26 +0200 From: Vlastimil Babka MIME-Version: 1.0 Subject: Re: [PATCHv6 27/36] mm: differentiate page_mapped() from page_mapcount() for compound pages References: <1433351167-125878-1-git-send-email-kirill.shutemov@linux.intel.com> <1433351167-125878-28-git-send-email-kirill.shutemov@linux.intel.com> In-Reply-To: <1433351167-125878-28-git-send-email-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: "Kirill A. Shutemov" , Andrew Morton , Andrea Arcangeli , Hugh Dickins Cc: 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 On 06/03/2015 07:05 PM, Kirill A. Shutemov wrote: > Let's define page_mapped() to be true for compound pages if any > sub-pages of the compound page is mapped (with PMD or PTE). > > On other hand page_mapcount() return mapcount for this particular small > page. > > This will make cases like page_get_anon_vma() behave correctly once we > allow huge pages to be mapped with PTE. > > Most users outside core-mm should use page_mapcount() instead of > page_mapped(). > > Signed-off-by: Kirill A. Shutemov > Tested-by: Sasha Levin [...] > @@ -917,10 +917,21 @@ static inline pgoff_t page_file_index(struct page *page) > > /* > * Return true if this page is mapped into pagetables. > + * For compound page it returns true if any subpage of compound page is mapped. > */ > -static inline int page_mapped(struct page *page) > +static inline bool page_mapped(struct page *page) > { > - return atomic_read(&(page)->_mapcount) + compound_mapcount(page) >= 0; > + int i; > + if (likely(!PageCompound(page))) > + return atomic_read(&page->_mapcount) >= 0; > + page = compound_head(page); > + if (compound_mapcount(page)) Same optimization opportunity as I pointed out in previous patch for page_mapcount(). > + return true; > + for (i = 0; i < hpage_nr_pages(page); i++) { > + if (atomic_read(&page[i]._mapcount) >= 0) > + return true; > + } > + return true; > } > > /* > diff --git a/mm/filemap.c b/mm/filemap.c > index cb41cf3069d2..c6cf03303ded 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -202,7 +202,7 @@ void __delete_from_page_cache(struct page *page, void *shadow) > __dec_zone_page_state(page, NR_FILE_PAGES); > if (PageSwapBacked(page)) > __dec_zone_page_state(page, NR_SHMEM); > - BUG_ON(page_mapped(page)); > + VM_BUG_ON_PAGE(page_mapped(page), page); > > /* > * At this point page must be either written or cleaned by truncate. > -- 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: email@kvack.org