Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp27016rdd; Wed, 22 Nov 2023 08:32:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzBLPvDZEVdKhWdjMIO6P16YqLcVva+eBONK5aJ3iaqhbTJ1kZTBxpcDDJEFxliFmeAXBf X-Received: by 2002:a17:90b:380a:b0:285:3511:6269 with SMTP id mq10-20020a17090b380a00b0028535116269mr2982784pjb.38.1700670722275; Wed, 22 Nov 2023 08:32:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700670722; cv=none; d=google.com; s=arc-20160816; b=ChJrjoywV6jFT/X7PJKgTmVr1nSL014YOG8+BUD+iltxAJPzgqa3NZd+hur//WZTHY nBKI4sF57PeqHvmL6OHam8x7RJY6PcF5WKlUpZfISHzuUsnNnsQIRd9bA2+6Qz2eBGGK K3IvYKYH3Ri4/ppB7t30k2jpQv73YceLfUIHWtrrXYXpEBZ/jYhWUPOTsz6jfGPCFUb9 8VfJpC10VZluoYPMYXd9HzlIiNPsLqCJEv+ILmqVoReeIWLZiBpTzdIa1QOkU9BDwLF3 /Mn5kMMJtmaFInsW1lc9qCLah2IkkSIcV66ZQmX6rbEVHuFs7b7QRQwUuKpt9RHxNjQg hoyQ== 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=v5seL2le1Mw6GIfT/Jkn3HeHK2JNJN/qsVUzKZyoMG0=; fh=7axEUdnMUApK6aLYLrmxIYzEqwt8JUQTbtI9r8kD7PQ=; b=0N3HJ34K+JsH1kTx8OTwEIsP1CMnMg7ffYYLD8W3JvoHqbbzFS2TtsQ3lfA++U71c3 HXtkNsOprwUuJ3vaSi2GN9kmkoniW8a8bDeDNoPQ/YodWZz6sRQFLr/Zof/8ltdIrTgX IyvNVWnppeUW5Xw0xLYhsLry0JnVv9uRvCwYykk4Jtc9h/RrfWTQXa/I8Oc4i1mmjuN3 WcVN/RD5IYydak8AcPVT1K0oKoGkmZrscDRLNnnFGJuciYcYsA+XdurUD8DFQGurGzvd sggyZNUHWKFMA7XTnpdFloJuHUORRa+4Axhn67nfIi0lh44hgujakiBGeYD0QoUUiFuu 6k+w== 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:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id nn6-20020a17090b38c600b00283a0cb5b9bsi1774376pjb.58.2023.11.22.08.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 08:32:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id E2B22806BE15; Wed, 22 Nov 2023 08:31:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232348AbjKVQaV (ORCPT + 99 others); Wed, 22 Nov 2023 11:30:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbjKVQaP (ORCPT ); Wed, 22 Nov 2023 11:30:15 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AB2B6A2 for ; Wed, 22 Nov 2023 08:30:11 -0800 (PST) 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 47A561650; Wed, 22 Nov 2023 08:30:58 -0800 (PST) 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 CF0523F73F; Wed, 22 Nov 2023 08:30:08 -0800 (PST) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v7 02/10] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Date: Wed, 22 Nov 2023 16:29:42 +0000 Message-Id: <20231122162950.3854897-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231122162950.3854897-1-ryan.roberts@arm.com> References: <20231122162950.3854897-1-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Wed, 22 Nov 2023 08:31:24 -0800 (PST) In preparation for supporting anonymous small-sized THP, 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 | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 49e4d86a4f70..b086dc957b0c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1305,32 +1305,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); + __folio_set_anon(folio, vma, address, true); - 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; + SetPageAnonExclusive(&folio->page); + } 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); + SetPageAnonExclusive(page); + } + + atomic_set(&folio->_nr_pages_mapped, nr); } 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); + SetPageAnonExclusive(&folio->page); __lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr); } __lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr); - __folio_set_anon(folio, vma, address, true); - SetPageAnonExclusive(&folio->page); } /** -- 2.25.1