Message ID | 20230717143110.260162-2-ryan.roberts@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1181653vqt; Mon, 17 Jul 2023 08:28:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlGodZccFiOW1UXsOu1PdTFPKxp3iWyCZGvbQtxLVLQxB/eLUMzHWEMwGrGcfi7zbj50VQ9P X-Received: by 2002:a05:6a21:585:b0:135:26ad:132 with SMTP id lw5-20020a056a21058500b0013526ad0132mr1221077pzb.7.1689607731472; Mon, 17 Jul 2023 08:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689607731; cv=none; d=google.com; s=arc-20160816; b=QJHW4KHG6cVDnz5onsIqjZj74ZoQPvzptiyoBqxmEZa/BpvFq458GaYRdMFYuLfRzz 0MXiEBb9HF7j3BzkALKl7TcZSVbkA6yFAHKGXrIx89tcriMso6Jd9o5XOQIXn6oSg25u W3SwdE9dKWsqgJWeEQyiwOINYxWbsY4BhDjftXOPlSXL5sUwcZ8DBNS7FC4E8dNFQGFH Nas5NxMz0rrjfs3qxcUjP/LxyjXkWnxOE528oPuCdJA82lWH0gm1cNplqPX7hODIRzKx LkRlsoKRF2QlN3I8oWfWaCZ4GmDewTdtF1UwRdDg+3d7RPRmar+3+GSyjYTqzdx4COSO K6Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BP+7rStUqlpLuRykLENwCQmjiIT3a8ADMh8sshpsKms=; fh=THi7eKCjaWcVibUnyL3CTjC3PwRMYqk9JChFkSe1vn0=; b=KyKXKN2hTfcFhQavargdESexq08tbthOljt5wpegU2usmYnwcZkwYxxGaaX0+W5jWg Iy2VpiwkhoGk4K2w3UVBOWyV54yH6rSfR6hXuDhVy4l0V/PvcEHy2dFUbE2bSyDLzMY5 j4ILYfDHmVhAw+oA+t2mTkUeRnZeIZxPMtwNHgS8qyoIuljxqWCWGMtngHmisBuJjJhs 8vCkUG3YLB9Gm1YLC3L2lglPaVzUh146d0QZUg3KkOTZpw1St1ZiTus4LJycVcRhP3lj D8M2pj5GBcUo355kXclHw8riuPtGZ0LrlCvH5Ew+E77FAfsNMnPmuAgw6U3S+k6joBpQ W4sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s28-20020a63525c000000b0055bc97cc885si11482406pgl.614.2023.07.17.08.28.37; Mon, 17 Jul 2023 08:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231410AbjGQObd (ORCPT <rfc822;hadasmailinglist@gmail.com> + 99 others); Mon, 17 Jul 2023 10:31:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231343AbjGQOb2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 17 Jul 2023 10:31:28 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C3CAFE55 for <linux-kernel@vger.kernel.org>; Mon, 17 Jul 2023 07:31:23 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8D926D75; Mon, 17 Jul 2023 07:32:06 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9E0313F738; Mon, 17 Jul 2023 07:31:21 -0700 (PDT) From: Ryan Roberts <ryan.roberts@arm.com> To: Andrew Morton <akpm@linux-foundation.org>, Matthew Wilcox <willy@infradead.org>, Yin Fengwei <fengwei.yin@intel.com>, David Hildenbrand <david@redhat.com>, Yu Zhao <yuzhao@google.com>, Yang Shi <shy828301@gmail.com>, "Huang, Ying" <ying.huang@intel.com>, Zi Yan <ziy@nvidia.com> Cc: Ryan Roberts <ryan.roberts@arm.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 1/3] mm: Allow deferred splitting of arbitrary large anon folios Date: Mon, 17 Jul 2023 15:31:08 +0100 Message-Id: <20230717143110.260162-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230717143110.260162-1-ryan.roberts@arm.com> References: <20230717143110.260162-1-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771682116517418783 X-GMAIL-MSGID: 1771682116517418783 |
Series |
Optimize large folio interaction with deferred split
|
|
Commit Message
Ryan Roberts
July 17, 2023, 2:31 p.m. UTC
In preparation for the introduction of large folios for anonymous memory, we would like to be able to split them when they have unmapped subpages, in order to free those unused pages under memory pressure. So remove the artificial requirement that the large folio needed to be at least PMD-sized. Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: Yu Zhao <yuzhao@google.com> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> --- mm/rmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mon, Jul 17, 2023 at 03:31:08PM +0100, Ryan Roberts wrote: > In preparation for the introduction of large folios for anonymous > memory, we would like to be able to split them when they have unmapped > subpages, in order to free those unused pages under memory pressure. So > remove the artificial requirement that the large folio needed to be at > least PMD-sized. > > Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> > Reviewed-by: Yu Zhao <yuzhao@google.com> > Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> > */ > - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) > + if (folio_test_large(folio) && folio_test_anon(folio)) > if (!compound || nr < nr_pmdmapped) > deferred_split_folio(folio); I wonder if it's worth introducing a folio_test_deferred_split() (better naming appreciated ...) to allow us to allocate order-1 folios and not do horrible things. Maybe it's not worth supporting order-1 folios; we're always better off going to order-2 immediately. Just thinking.
On 17/07/2023 16:30, Matthew Wilcox wrote: > On Mon, Jul 17, 2023 at 03:31:08PM +0100, Ryan Roberts wrote: >> In preparation for the introduction of large folios for anonymous >> memory, we would like to be able to split them when they have unmapped >> subpages, in order to free those unused pages under memory pressure. So >> remove the artificial requirement that the large folio needed to be at >> least PMD-sized. >> >> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >> Reviewed-by: Yu Zhao <yuzhao@google.com> >> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> > > Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> Thanks! > >> */ >> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >> + if (folio_test_large(folio) && folio_test_anon(folio)) >> if (!compound || nr < nr_pmdmapped) >> deferred_split_folio(folio); > > I wonder if it's worth introducing a folio_test_deferred_split() (better > naming appreciated ...) to allow us to allocate order-1 folios and not > do horrible things. Maybe it's not worth supporting order-1 folios; > we're always better off going to order-2 immediately. Just thinking. There is more than just _deferred_list in the 3rd page; you also have _flags_2a and _head_2a. I guess you know much better than me what they store. But I'm guessing its harder than jsut not splitting an order-1 page? With the direction of large anon folios (_not_ retrying with every order down to 0), I'm not sure what the use case would be for order-1 anyway?
On 17.07.23 16:31, Ryan Roberts wrote: > In preparation for the introduction of large folios for anonymous > memory, we would like to be able to split them when they have unmapped > subpages, in order to free those unused pages under memory pressure. So > remove the artificial requirement that the large folio needed to be at > least PMD-sized. > > Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> > Reviewed-by: Yu Zhao <yuzhao@google.com> > Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> > --- > mm/rmap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/rmap.c b/mm/rmap.c > index 0c0d8857dfce..2baf57d65c23 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1430,7 +1430,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, > * page of the folio is unmapped and at least one page > * is still mapped. > */ > - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) > + if (folio_test_large(folio) && folio_test_anon(folio)) > if (!compound || nr < nr_pmdmapped) > deferred_split_folio(folio); !compound will always be true I guess, so nr_pmdmapped == 0 (which will always be the case) will be ignored. Reviewed-by: David Hildenbrand <david@redhat.com>
On 17.07.23 17:41, Ryan Roberts wrote: > On 17/07/2023 16:30, Matthew Wilcox wrote: >> On Mon, Jul 17, 2023 at 03:31:08PM +0100, Ryan Roberts wrote: >>> In preparation for the introduction of large folios for anonymous >>> memory, we would like to be able to split them when they have unmapped >>> subpages, in order to free those unused pages under memory pressure. So >>> remove the artificial requirement that the large folio needed to be at >>> least PMD-sized. >>> >>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >>> Reviewed-by: Yu Zhao <yuzhao@google.com> >>> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> >> >> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> > > Thanks! > >> >>> */ >>> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >>> + if (folio_test_large(folio) && folio_test_anon(folio)) >>> if (!compound || nr < nr_pmdmapped) >>> deferred_split_folio(folio); >> >> I wonder if it's worth introducing a folio_test_deferred_split() (better >> naming appreciated ...) to allow us to allocate order-1 folios and not >> do horrible things. Maybe it's not worth supporting order-1 folios; >> we're always better off going to order-2 immediately. Just thinking. > > There is more than just _deferred_list in the 3rd page; you also have _flags_2a > and _head_2a. I guess you know much better than me what they store. But I'm > guessing its harder than jsut not splitting an order-1 page? > > With the direction of large anon folios (_not_ retrying with every order down to > 0), I'm not sure what the use case would be for order-1 anyway? Just noting that we might need some struct-page space for better mapcount/shared tracking, which might get hard for order-1 pages.
On Mon, Jul 17, 2023 at 05:43:40PM +0200, David Hildenbrand wrote: > On 17.07.23 17:41, Ryan Roberts wrote: > > On 17/07/2023 16:30, Matthew Wilcox wrote: > > > On Mon, Jul 17, 2023 at 03:31:08PM +0100, Ryan Roberts wrote: > > > > In preparation for the introduction of large folios for anonymous > > > > memory, we would like to be able to split them when they have unmapped > > > > subpages, in order to free those unused pages under memory pressure. So > > > > remove the artificial requirement that the large folio needed to be at > > > > least PMD-sized. > > > > > > > > Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> > > > > Reviewed-by: Yu Zhao <yuzhao@google.com> > > > > Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> > > > > > > Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> > > > > Thanks! > > > > > > > > > */ > > > > - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) > > > > + if (folio_test_large(folio) && folio_test_anon(folio)) > > > > if (!compound || nr < nr_pmdmapped) > > > > deferred_split_folio(folio); > > > > > > I wonder if it's worth introducing a folio_test_deferred_split() (better > > > naming appreciated ...) to allow us to allocate order-1 folios and not > > > do horrible things. Maybe it's not worth supporting order-1 folios; > > > we're always better off going to order-2 immediately. Just thinking. > > > > There is more than just _deferred_list in the 3rd page; you also have _flags_2a > > and _head_2a. I guess you know much better than me what they store. But I'm > > guessing its harder than jsut not splitting an order-1 page? Those are page->flags and page->compound_head for the third page in the folio. They don't really need a name; nothing refers to them, but it's important that space not be reused ;-) This is slightly different from _flags_1; we do have some flags which reuse the bits (they're labelled as PF_SECOND). Right now, it's only PF_has_hwpoisoned, but we used to have PF_double_map. Others may arise. > > With the direction of large anon folios (_not_ retrying with every order down to > > 0), I'm not sure what the use case would be for order-1 anyway? > > Just noting that we might need some struct-page space for better > mapcount/shared tracking, which might get hard for order-1 pages. My assumption had been that we'd be able to reuse the _entire_mapcount and _nr_pages_mapped fields and not spill into the third page, but the third page is definitely available today if we want it. I'm fine with disallowing order-1 anon/file folios forever.
On 17/07/2023 16:42, David Hildenbrand wrote: > On 17.07.23 16:31, Ryan Roberts wrote: >> In preparation for the introduction of large folios for anonymous >> memory, we would like to be able to split them when they have unmapped >> subpages, in order to free those unused pages under memory pressure. So >> remove the artificial requirement that the large folio needed to be at >> least PMD-sized. >> >> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >> Reviewed-by: Yu Zhao <yuzhao@google.com> >> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> >> --- >> mm/rmap.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/mm/rmap.c b/mm/rmap.c >> index 0c0d8857dfce..2baf57d65c23 100644 >> --- a/mm/rmap.c >> +++ b/mm/rmap.c >> @@ -1430,7 +1430,7 @@ void page_remove_rmap(struct page *page, struct >> vm_area_struct *vma, >> * page of the folio is unmapped and at least one page >> * is still mapped. >> */ >> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >> + if (folio_test_large(folio) && folio_test_anon(folio)) >> if (!compound || nr < nr_pmdmapped) >> deferred_split_folio(folio); > > !compound will always be true I guess, so nr_pmdmapped == 0 (which will always > be the case) will be ignored. I don't follow why !compound will always be true. This function is page_remove_rmap() (not folio_remove_rmap_range() which I add in a later patch). page_remove_rmap() can work on pmd-mapped pages where compound=true is passed in. > > Reviewed-by: David Hildenbrand <david@redhat.com> >
On Mon, Jul 17, 2023 at 04:54:58PM +0100, Matthew Wilcox wrote: > Those are page->flags and page->compound_head for the third page in > the folio. They don't really need a name; nothing refers to them, > but it's important that space not be reused ;-) > > This is slightly different from _flags_1; we do have some flags which > reuse the bits (they're labelled as PF_SECOND). Right now, it's only > PG_has_hwpoisoned, but we used to have PG_double_map. Others may arise. Sorry, this was incomplete. We do still have per-page flags! HWPoison is the obvious one, but PG_head is per-page (... think about it ...) PG_anon_exclusive is actually per-page. Most of the flags labelled as PF_ANY are mislabelled. PG_private and PG_private2 are never set/cleared/tested on tail pages. PG_young and PG_idle are only ever tested on the head page, but some code incorrectly sets them on tail pages, where those bits are ignored. I tried to fix that a while ago, but the patch was overlooked and I couldn't be bothered to try all that hard. I have no clue about PG_vmemmap_self_hosted. I think PG_isolated is probably never set on compound pages. PG_owner_priv_1 is a disaster, as you might expect.
On 17.07.23 18:01, Ryan Roberts wrote: > On 17/07/2023 16:42, David Hildenbrand wrote: >> On 17.07.23 16:31, Ryan Roberts wrote: >>> In preparation for the introduction of large folios for anonymous >>> memory, we would like to be able to split them when they have unmapped >>> subpages, in order to free those unused pages under memory pressure. So >>> remove the artificial requirement that the large folio needed to be at >>> least PMD-sized. >>> >>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >>> Reviewed-by: Yu Zhao <yuzhao@google.com> >>> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> >>> --- >>> mm/rmap.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/mm/rmap.c b/mm/rmap.c >>> index 0c0d8857dfce..2baf57d65c23 100644 >>> --- a/mm/rmap.c >>> +++ b/mm/rmap.c >>> @@ -1430,7 +1430,7 @@ void page_remove_rmap(struct page *page, struct >>> vm_area_struct *vma, >>> * page of the folio is unmapped and at least one page >>> * is still mapped. >>> */ >>> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >>> + if (folio_test_large(folio) && folio_test_anon(folio)) >>> if (!compound || nr < nr_pmdmapped) >>> deferred_split_folio(folio); >> >> !compound will always be true I guess, so nr_pmdmapped == 0 (which will always >> be the case) will be ignored. > > I don't follow why !compound will always be true. This function is > page_remove_rmap() (not folio_remove_rmap_range() which I add in a later patch). > page_remove_rmap() can work on pmd-mapped pages where compound=true is passed in. I was talking about the folio_test_pmd_mappable() -> folio_test_large() change. For folio_test_large() && !folio_test_pmd_mappable() I expect that we'll never pass in "compound=true".
On 17.07.23 17:54, Matthew Wilcox wrote: > On Mon, Jul 17, 2023 at 05:43:40PM +0200, David Hildenbrand wrote: >> On 17.07.23 17:41, Ryan Roberts wrote: >>> On 17/07/2023 16:30, Matthew Wilcox wrote: >>>> On Mon, Jul 17, 2023 at 03:31:08PM +0100, Ryan Roberts wrote: >>>>> In preparation for the introduction of large folios for anonymous >>>>> memory, we would like to be able to split them when they have unmapped >>>>> subpages, in order to free those unused pages under memory pressure. So >>>>> remove the artificial requirement that the large folio needed to be at >>>>> least PMD-sized. >>>>> >>>>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >>>>> Reviewed-by: Yu Zhao <yuzhao@google.com> >>>>> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> >>>> >>>> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> >>> >>> Thanks! >>> >>>> >>>>> */ >>>>> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >>>>> + if (folio_test_large(folio) && folio_test_anon(folio)) >>>>> if (!compound || nr < nr_pmdmapped) >>>>> deferred_split_folio(folio); >>>> >>>> I wonder if it's worth introducing a folio_test_deferred_split() (better >>>> naming appreciated ...) to allow us to allocate order-1 folios and not >>>> do horrible things. Maybe it's not worth supporting order-1 folios; >>>> we're always better off going to order-2 immediately. Just thinking. >>> >>> There is more than just _deferred_list in the 3rd page; you also have _flags_2a >>> and _head_2a. I guess you know much better than me what they store. But I'm >>> guessing its harder than jsut not splitting an order-1 page? > > Those are page->flags and page->compound_head for the third page in > the folio. They don't really need a name; nothing refers to them, > but it's important that space not be reused ;-) > > This is slightly different from _flags_1; we do have some flags which > reuse the bits (they're labelled as PF_SECOND). Right now, it's only > PF_has_hwpoisoned, but we used to have PF_double_map. Others may arise. > >>> With the direction of large anon folios (_not_ retrying with every order down to >>> 0), I'm not sure what the use case would be for order-1 anyway? >> >> Just noting that we might need some struct-page space for better >> mapcount/shared tracking, which might get hard for order-1 pages. > > My assumption had been that we'd be able to reuse the _entire_mapcount > and _nr_pages_mapped fields and not spill into the third page, but the We most likely have to keep _entire_mapcount to keep "PMD mapped" working (I don't think we can not account that, some user space relies on that). Reusing _nr_pages_mapped for _total_mapcount would work until we need more bits. But once we want to sort out some other questions like "is this folio mapped shared or mapped exclusive" we might need more space. What I am playing with right now to tackle that would most probably not fit in there (but I'll keep trying ;) ). > third page is definitely available today if we want it. I'm fine with > disallowing order-1 anon/file folios forever. Yes, let's first sort out the open issues before going down that path (might not really be worth it after all).
On 17/07/2023 17:48, David Hildenbrand wrote: > On 17.07.23 18:01, Ryan Roberts wrote: >> On 17/07/2023 16:42, David Hildenbrand wrote: >>> On 17.07.23 16:31, Ryan Roberts wrote: >>>> In preparation for the introduction of large folios for anonymous >>>> memory, we would like to be able to split them when they have unmapped >>>> subpages, in order to free those unused pages under memory pressure. So >>>> remove the artificial requirement that the large folio needed to be at >>>> least PMD-sized. >>>> >>>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >>>> Reviewed-by: Yu Zhao <yuzhao@google.com> >>>> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> >>>> --- >>>> mm/rmap.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/mm/rmap.c b/mm/rmap.c >>>> index 0c0d8857dfce..2baf57d65c23 100644 >>>> --- a/mm/rmap.c >>>> +++ b/mm/rmap.c >>>> @@ -1430,7 +1430,7 @@ void page_remove_rmap(struct page *page, struct >>>> vm_area_struct *vma, >>>> * page of the folio is unmapped and at least one page >>>> * is still mapped. >>>> */ >>>> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >>>> + if (folio_test_large(folio) && folio_test_anon(folio)) >>>> if (!compound || nr < nr_pmdmapped) >>>> deferred_split_folio(folio); >>> >>> !compound will always be true I guess, so nr_pmdmapped == 0 (which will always >>> be the case) will be ignored. >> >> I don't follow why !compound will always be true. This function is >> page_remove_rmap() (not folio_remove_rmap_range() which I add in a later patch). >> page_remove_rmap() can work on pmd-mapped pages where compound=true is passed in. > > I was talking about the folio_test_pmd_mappable() -> folio_test_large() change. > For folio_test_large() && !folio_test_pmd_mappable() I expect that we'll never > pass in "compound=true". > Sorry David, I've been staring at the code and your comment, and I still don't understand your point. I assumed you were trying to say that compound is always false and therefore "if (!compound || nr < nr_pmdmapped)" can be removed? But its not the case that compound is always false; it will be true when called to remove a pmd-mapped compound page. What change are you suggesting, exactly?
On 18.07.23 10:58, Ryan Roberts wrote: > On 17/07/2023 17:48, David Hildenbrand wrote: >> On 17.07.23 18:01, Ryan Roberts wrote: >>> On 17/07/2023 16:42, David Hildenbrand wrote: >>>> On 17.07.23 16:31, Ryan Roberts wrote: >>>>> In preparation for the introduction of large folios for anonymous >>>>> memory, we would like to be able to split them when they have unmapped >>>>> subpages, in order to free those unused pages under memory pressure. So >>>>> remove the artificial requirement that the large folio needed to be at >>>>> least PMD-sized. >>>>> >>>>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >>>>> Reviewed-by: Yu Zhao <yuzhao@google.com> >>>>> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> >>>>> --- >>>>> mm/rmap.c | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>> >>>>> diff --git a/mm/rmap.c b/mm/rmap.c >>>>> index 0c0d8857dfce..2baf57d65c23 100644 >>>>> --- a/mm/rmap.c >>>>> +++ b/mm/rmap.c >>>>> @@ -1430,7 +1430,7 @@ void page_remove_rmap(struct page *page, struct >>>>> vm_area_struct *vma, >>>>> * page of the folio is unmapped and at least one page >>>>> * is still mapped. >>>>> */ >>>>> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >>>>> + if (folio_test_large(folio) && folio_test_anon(folio)) >>>>> if (!compound || nr < nr_pmdmapped) >>>>> deferred_split_folio(folio); >>>> >>>> !compound will always be true I guess, so nr_pmdmapped == 0 (which will always >>>> be the case) will be ignored. >>> >>> I don't follow why !compound will always be true. This function is >>> page_remove_rmap() (not folio_remove_rmap_range() which I add in a later patch). >>> page_remove_rmap() can work on pmd-mapped pages where compound=true is passed in. >> >> I was talking about the folio_test_pmd_mappable() -> folio_test_large() change. >> For folio_test_large() && !folio_test_pmd_mappable() I expect that we'll never >> pass in "compound=true". >> > > Sorry David, I've been staring at the code and your comment, and I still don't > understand your point. I assumed you were trying to say that compound is always > false and therefore "if (!compound || nr < nr_pmdmapped)" can be removed? But > its not the case that compound is always false; it will be true when called to > remove a pmd-mapped compound page. Let me try again: Assume, as I wrote, that we are given a folio that is "folio_test_large() && !folio_test_pmd_mappable()". That is, a folio that is *not* pmd mappable. If it's not pmd-mappable, certainly, nr_pmdmapped == 0, and therefore, "nr < nr_pmdmapped" will never ever trigger. The only way to have it added to the deferred split queue is, therefore "if (!compound)". So *for these folios*, we will always pass "compound == false" to make that "if (!compound)" succeed. Does that make sense? > What change are you suggesting, exactly? Oh, I never suggested a change (I even gave you my RB). I was just thinking out loud.
On 18/07/2023 10:08, David Hildenbrand wrote: > On 18.07.23 10:58, Ryan Roberts wrote: >> On 17/07/2023 17:48, David Hildenbrand wrote: >>> On 17.07.23 18:01, Ryan Roberts wrote: >>>> On 17/07/2023 16:42, David Hildenbrand wrote: >>>>> On 17.07.23 16:31, Ryan Roberts wrote: >>>>>> In preparation for the introduction of large folios for anonymous >>>>>> memory, we would like to be able to split them when they have unmapped >>>>>> subpages, in order to free those unused pages under memory pressure. So >>>>>> remove the artificial requirement that the large folio needed to be at >>>>>> least PMD-sized. >>>>>> >>>>>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> >>>>>> Reviewed-by: Yu Zhao <yuzhao@google.com> >>>>>> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> >>>>>> --- >>>>>> mm/rmap.c | 2 +- >>>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>>> >>>>>> diff --git a/mm/rmap.c b/mm/rmap.c >>>>>> index 0c0d8857dfce..2baf57d65c23 100644 >>>>>> --- a/mm/rmap.c >>>>>> +++ b/mm/rmap.c >>>>>> @@ -1430,7 +1430,7 @@ void page_remove_rmap(struct page *page, struct >>>>>> vm_area_struct *vma, >>>>>> * page of the folio is unmapped and at least one page >>>>>> * is still mapped. >>>>>> */ >>>>>> - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) >>>>>> + if (folio_test_large(folio) && folio_test_anon(folio)) >>>>>> if (!compound || nr < nr_pmdmapped) >>>>>> deferred_split_folio(folio); >>>>> >>>>> !compound will always be true I guess, so nr_pmdmapped == 0 (which will always >>>>> be the case) will be ignored. >>>> >>>> I don't follow why !compound will always be true. This function is >>>> page_remove_rmap() (not folio_remove_rmap_range() which I add in a later >>>> patch). >>>> page_remove_rmap() can work on pmd-mapped pages where compound=true is >>>> passed in. >>> >>> I was talking about the folio_test_pmd_mappable() -> folio_test_large() change. >>> For folio_test_large() && !folio_test_pmd_mappable() I expect that we'll never >>> pass in "compound=true". >>> >> >> Sorry David, I've been staring at the code and your comment, and I still don't >> understand your point. I assumed you were trying to say that compound is always >> false and therefore "if (!compound || nr < nr_pmdmapped)" can be removed? But >> its not the case that compound is always false; it will be true when called to >> remove a pmd-mapped compound page. > > Let me try again: > > Assume, as I wrote, that we are given a folio that is "folio_test_large() && > !folio_test_pmd_mappable()". That is, a folio that is *not* pmd mappable. > > If it's not pmd-mappable, certainly, nr_pmdmapped == 0, and therefore, "nr < > nr_pmdmapped" will never ever trigger. > > The only way to have it added to the deferred split queue is, therefore "if > (!compound)". > > So *for these folios*, we will always pass "compound == false" to make that "if > (!compound)" succeed. > > > Does that make sense? Yes I agree with all of this. I thought you were pointing out an issue or proposing a change to the logic. Hence my confusion. > >> What change are you suggesting, exactly? > > Oh, I never suggested a change (I even gave you my RB). I was just thinking out > loud. >
diff --git a/mm/rmap.c b/mm/rmap.c index 0c0d8857dfce..2baf57d65c23 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1430,7 +1430,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, * page of the folio is unmapped and at least one page * is still mapped. */ - if (folio_test_pmd_mappable(folio) && folio_test_anon(folio)) + if (folio_test_large(folio) && folio_test_anon(folio)) if (!compound || nr < nr_pmdmapped) deferred_split_folio(folio); }