Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752996AbbHCKnc (ORCPT ); Mon, 3 Aug 2015 06:43:32 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:36441 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751773AbbHCKnb (ORCPT ); Mon, 3 Aug 2015 06:43:31 -0400 Date: Mon, 3 Aug 2015 13:43:28 +0300 From: "Kirill A. Shutemov" To: Jerome Marchand Cc: "Kirill A. Shutemov" , Andrew Morton , Andrea Arcangeli , Hugh Dickins , Dave Hansen , Mel Gorman , Rik van Riel , Vlastimil Babka , Christoph Lameter , Naoya Horiguchi , Steve Capper , "Aneesh Kumar K.V" , Johannes Weiner , Michal Hocko , Sasha Levin , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCHv9 26/36] mm: rework mapcount accounting to enable 4k mapping of THPs Message-ID: <20150803104328.GB25034@node.dhcp.inet.fi> References: <1437402069-105900-1-git-send-email-kirill.shutemov@linux.intel.com> <1437402069-105900-27-git-send-email-kirill.shutemov@linux.intel.com> <55BB8E72.3070101@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55BB8E72.3070101@redhat.com> 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: 2177 Lines: 47 On Fri, Jul 31, 2015 at 05:04:18PM +0200, Jerome Marchand wrote: > On 07/20/2015 04:20 PM, Kirill A. Shutemov wrote: > > We're going to allow mapping of individual 4k pages of THP compound. > > It means we need to track mapcount on per small page basis. > > > > Straight-forward approach is to use ->_mapcount in all subpages to track > > how many time this subpage is mapped with PMDs or PTEs combined. But > > this is rather expensive: mapping or unmapping of a THP page with PMD > > would require HPAGE_PMD_NR atomic operations instead of single we have > > now. > > > > The idea is to store separately how many times the page was mapped as > > whole -- compound_mapcount. This frees up ->_mapcount in subpages to > > track PTE mapcount. > > > > We use the same approach as with compound page destructor and compound > > order to store compound_mapcount: use space in first tail page, > > ->mapping this time. > > > > Any time we map/unmap whole compound page (THP or hugetlb) -- we > > increment/decrement compound_mapcount. When we map part of compound page > > with PTE we operate on ->_mapcount of the subpage. > > > > page_mapcount() counts both: PTE and PMD mappings of the page. > > > > Basically, we have mapcount for a subpage spread over two counters. > > It makes tricky to detect when last mapcount for a page goes away. > > > > We introduced PageDoubleMap() for this. When we split THP PMD for the > > first time and there's other PMD mapping left we offset up ->_mapcount > > in all subpages by one and set PG_double_map on the compound page. > > These additional references go away with last compound_mapcount. > > So this stays even if all PTE mappings goes and the page is again mapped > only with PMD. I'm not sure how often that happen and if it's an issue > worth caring about. We don't have a cheap way to detect this situation and it shouldn't happen often enough to care. -- 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/