From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 788D2E71D3D for ; Fri, 29 Sep 2023 14:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GsPD1GmJnxC3SAV6u5oKskVEvC/nZLlEYg+EbtcF14s=; b=uku0d0+TTSCOsU mjiEQUvyBouao2azwk5EbNzNaF0V6a7WLyUg+qA2CWiIYBS7x97+ks3dg8tSDIkFqOUMIwrxjZFjA /dQCZ9vzcqlGNbnrTjca88DRrWmX7/KhX6I9ju1FVU0IdiAu+loaziFS1BVoYJPdXgLf2WQMIYTzM tNJgV3sSUT66uk09cVAocaJB1fsIm1lqdbbcRmXe/4fP/d4XrziHHqD4761gpMXR6cV4EMj5s5k66 /3/ddbUGvX8HWy6+sMt+u6f0q5dHpjJPpf0swHhGs4+djgBbcrkSbrCT+BMO0HPwVLBemUdnpM+QI ienqDbf2AZ+E8T+UP9SQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmEf4-0085YR-12; Fri, 29 Sep 2023 14:40:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmEep-0085Ug-0Y for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 14:39:57 +0000 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 C7A631FB; Fri, 29 Sep 2023 07:40:30 -0700 (PDT) Received: from [10.57.66.194] (unknown [10.57.66.194]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DD23F3F5A1; Fri, 29 Sep 2023 07:39:49 -0700 (PDT) Message-ID: <188646a6-c854-4fbe-96ff-ddf3ffc5ec77@arm.com> Date: Fri, 29 Sep 2023 15:39:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 2/9] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Content-Language: en-GB To: "Kirill A. Shutemov" Cc: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20230929114421.3761121-1-ryan.roberts@arm.com> <20230929114421.3761121-3-ryan.roberts@arm.com> <20230929134524.wwyykrxfikhle54k@box.shutemov.name> From: Ryan Roberts In-Reply-To: <20230929134524.wwyykrxfikhle54k@box.shutemov.name> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_073955_309915_A8B3C9EE X-CRM114-Status: GOOD ( 23.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 29/09/2023 14:45, Kirill A. Shutemov wrote: > On Fri, Sep 29, 2023 at 12:44:13PM +0100, Ryan Roberts wrote: >> In preparation for anonymous large folio support, improve >> folio_add_new_anon_rmap() to allow a non-pmd-mappable, large folio to be >> passed to it. In this case, all contained pages are accounted using the >> order-0 folio (or base page) scheme. >> >> Reviewed-by: Yu Zhao >> Reviewed-by: Yin Fengwei >> Signed-off-by: Ryan Roberts >> --- >> mm/rmap.c | 27 ++++++++++++++++++++------- >> 1 file changed, 20 insertions(+), 7 deletions(-) >> >> diff --git a/mm/rmap.c b/mm/rmap.c >> index 8600bd029acf..106149690366 100644 >> --- a/mm/rmap.c >> +++ b/mm/rmap.c >> @@ -1266,31 +1266,44 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma, >> * This means the inc-and-test can be bypassed. >> * The folio does not have to be locked. >> * >> - * If the folio is large, it is accounted as a THP. As the folio >> + * If the folio is pmd-mappable, it is accounted as a THP. As the folio >> * is new, it's assumed to be mapped exclusively by a single process. >> */ >> void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, >> unsigned long address) >> { >> - int nr; >> + int nr = folio_nr_pages(folio); >> >> - VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma); >> + VM_BUG_ON_VMA(address < vma->vm_start || >> + address + (nr << PAGE_SHIFT) > vma->vm_end, vma); >> __folio_set_swapbacked(folio); >> >> - if (likely(!folio_test_pmd_mappable(folio))) { >> + if (likely(!folio_test_large(folio))) { >> /* increment count (starts at -1) */ >> atomic_set(&folio->_mapcount, 0); >> - nr = 1; >> + __page_set_anon_rmap(folio, &folio->page, vma, address, 1); >> + } else if (!folio_test_pmd_mappable(folio)) { >> + int i; >> + >> + for (i = 0; i < nr; i++) { >> + struct page *page = folio_page(folio, i); >> + >> + /* increment count (starts at -1) */ >> + atomic_set(&page->_mapcount, 0); >> + __page_set_anon_rmap(folio, page, vma, >> + address + (i << PAGE_SHIFT), 1); >> + } >> + >> + atomic_set(&folio->_nr_pages_mapped, nr); > > This code should work for !folio_test_large() case too, no? Not quite; for !folio_test_large() we don't set _nr_pages_mapped - that's a compound-only field in the second struct page. So I could make most of this common but would still have a conditional around that last line, and at that point I thought it was better to split it the way I've done it to avoid the loop overhead for the !large case. > >> } else { >> /* increment count (starts at -1) */ >> atomic_set(&folio->_entire_mapcount, 0); >> atomic_set(&folio->_nr_pages_mapped, COMPOUND_MAPPED); >> - nr = folio_nr_pages(folio); >> + __page_set_anon_rmap(folio, &folio->page, vma, address, 1); >> __lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr); >> } >> >> __lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr); >> - __page_set_anon_rmap(folio, &folio->page, vma, address, 1); >> } >> >> /** >> -- >> 2.25.1 >> > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel