Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3989258rdh; Fri, 29 Sep 2023 08:07:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeq5MhRdoE1irDFDsudcaMZWJoUFgH3aGGWhpiX7Dx4rQQh2BKNJAkwR0XZgZla9aLi8JE X-Received: by 2002:a17:902:e74a:b0:1c6:1902:a0fe with SMTP id p10-20020a170902e74a00b001c61902a0femr4692226plf.67.1696000072810; Fri, 29 Sep 2023 08:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696000072; cv=none; d=google.com; s=arc-20160816; b=hcebDy+TAQSz9rrHrEiPUf/q1VW5uDs7w8QHHC6ifHQeGlI6LRxu3CCVypzImM+6x2 7EcrMVWVJd7GVjTDiorHriHj0kzut4BCzHkJ6yB7i8eF5Eq1h5NJ+94x65t5mRs5+5xQ gjhCmRgmBG91mx40i3xRqj5ezJth7m+cQcK14K80GWzaW9bZr19qzZL5wXhIiqWl/MNn woSO7qmrpicbJ5pEWKjeIwCpiMRcYiGfgaWG+efDccvp7hEcREThi8DQoJF9rgNwLqs8 HfCtd4MS+P9iuAvnHyp4qfg+qfMfCtIGsqGlPh+HSyhdnBahyPaPMhOTIS+E9EFdm3Jf T2Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=uNqranZXziD//UJBRCCiwV5+pJ8TfgfqhYrdGwhSLh4=; fh=jAhIiO0jBB3ewcJywQudTibl99nku++NlFXo3Jxnd3E=; b=TxhRz+dcibZ/++qf3Jg6C4dp7Oi/SzS7eOBOxprlFeonGuURjbiBKw+6gyAJ5XVUsg 31TLIAah5YJyY1WbZRHtsJ3JithjDO1/MPWVaIsIXKzp2WCScTzCfxGxCRjkyl6ocIls 2SRiE5jS5Eqr3o3cNeddwKqt2wyEzAu3JGLLwcErvbFugmkHYzZvZ7RinwtTQy3eN4Qv Qx+bKt5PT4T3L1QhdoEayUnt2O6dZOpJaJvXRIWzcDh6kCUHQoPeZTxciBxUZ2PHqrdt lu4aX29O29HcTdd+8ADFDJIhluNM6KLixYYxplBy1ExZJVPxRuZDhJ5ShN4UUkG5mPkm nAYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ay6-20020a1709028b8600b001bbd81eaabasi20522144plb.57.2023.09.29.08.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 08:07:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 77DEA8032008; Fri, 29 Sep 2023 07:39:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233061AbjI2Oj4 (ORCPT + 99 others); Fri, 29 Sep 2023 10:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233068AbjI2Ojz (ORCPT ); Fri, 29 Sep 2023 10:39:55 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00BE31B8 for ; Fri, 29 Sep 2023 07:39:52 -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 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> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE 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: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 29 Sep 2023 07:39:58 -0700 (PDT) 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 >> >