From patchwork Fri Sep 29 11:44:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13404126 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29D67E810DF for ; Fri, 29 Sep 2023 11:44:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A41128D00EE; Fri, 29 Sep 2023 07:44:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F1358D0023; Fri, 29 Sep 2023 07:44:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E0BA8D00EE; Fri, 29 Sep 2023 07:44:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 80C3B8D0023 for ; Fri, 29 Sep 2023 07:44:41 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 57102B2E54 for ; Fri, 29 Sep 2023 11:44:41 +0000 (UTC) X-FDA: 81289452762.02.0C35522 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf23.hostedemail.com (Postfix) with ESMTP id A3314140012 for ; Fri, 29 Sep 2023 11:44:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf23.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695987879; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mr+mjEqwfDoSUXJ6kY2GFEcxLi6J7er8Wf2qGr66jIc=; b=7HS7SHCkLh79SJhTPC1ydB39O0qtVYUBRETgj38hxaSi3gFNM8Z4jtVs+kqnzxmPCvsSgo fl2EADtjIm6SgutRsaqI7eIfWLtEgrGCyPDI4PosduMLcX8R0bJuMxTOYIC78Cy3T0i/Qy lhy8Dakg80yWsOPiPFCgDiEte9SNhf8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf23.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695987879; a=rsa-sha256; cv=none; b=LQLhPW/b5R0SgPONiS1r/fDUHqu11nYuKjd26rZbr/AgvXQUzdLvJKi4yTvYmackmuHDLV bijNXR8do8NJn1zt4Uut98xqqClxAdOfjH/k9JsefwlIQcdh4wkwlOB2E88DyBm8jQIp1o VWjefw+ewU+/UD683/vh58q0HhzEwhM= 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 3537F1007; Fri, 29 Sep 2023 04:45:17 -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 527553F59C; Fri, 29 Sep 2023 04:44:36 -0700 (PDT) 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 Cc: Ryan Roberts , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 2/9] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Date: Fri, 29 Sep 2023 12:44:13 +0100 Message-Id: <20230929114421.3761121-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230929114421.3761121-1-ryan.roberts@arm.com> References: <20230929114421.3761121-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A3314140012 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: pcqhbx8y5h468x144g7djcf1n14jt4tj X-HE-Tag: 1695987879-709487 X-HE-Meta: U2FsdGVkX1+Z+IM7JEYTPckQQ0xRMQHxRlm4wuUGhoLNbMqU8FtkgFN/NSOIilkrlwgyn/5OxYJ9r37qu5FghWXZmb+zp26y5Nj/ANEVCFfrnSfsP+JIe7nbt+crHMkMpuUL1kjjohxBLPWKlFSJJXRXDbtPMAsRdi0FBzjady8jgdoSpTL3vNReTV5odxng5U1naQKzuNDa73VkHZMtKeqJ0dHLSkwTx8koFSTgOI32NwJZqway9IPXTd0NER1+x4kxUy5offQhpH+vQmX2IHcaHPicuyPeXP/bC1m1Ri8Hv3RqexK+lZz4vYkk5EGP3sJ7SJoRgoK7pBnWK75I7BUQYVX86i6mmIn7W9tCG+U7zhyeedqkUNer9YFHCwiGTKv5OzlZ54GcXp93icNKTiO9HufMxYmz+2Ng63Kn2O6ApgLm/qQhRK4S+yhP1x0UnsDxcAzvqvRkL4itgEeyVoNoqX9io9vzloheDmX/icOnaDhXNah2MJkDp6Kx3J9px5tiY4RVHJLSp9qNbFv4UOzocOvIKG8A80F+/0MpaD2fD9KJ1yj5cioFR0xd8S0E3gHBjpeqBZe+cOP5x1XMZ+LS+1W+XG2vH3NmFyoEpDn73YL20W4vuHt+E5nrVd/eeROJsqIo2TtDYJRjkaPLzWgtBIuVeZzhI8LJQ+ThN5cBZHkhsy4Q0qnhJaVj0IoXeKnjIV+HY5HBaoKpTlUoQ8x7zT5AiywinTl4N2dIaG0q4SgIUbpQlAM7HumUlZRFgQtKraUPcbjTjoUigB3cooeRKES3ifS66hWBueuLdPScF+sdVVYGHCzaaxnVB+vtavy4PsuQCRk6NoZGnapyGRrjnfulOfpz16RH5N+H1Wydu7Fivwhnrwav3kHVexHiy2BGMI8jKEFLJwf84RIITwfFdGuwDO+NlDGKWyH4IcDTI2QTHB0SK9f04xEEnO/yKDKRZsWj02jWF9cMZ7F IaGoYG1n PN6bHTRF1VxqVkL7LijKws6oVg1eavVeJErjpcR9h6f68bD+zdNcmj52Yo4G6FeGdqXdevuMxoC/3r9pmm38rataj/mUtw42pVb98BoebzWYoi4sfjCvCn4Z5bCm7rftoAMFrCLAvki3ljPl5mA/KkgoDiKs3PwjiyLgE/hMYjf8ML5gyWuvEGm2v0ikarXXabA7P9yW7j/HYfJGDDi1XnabrciHoYG6repN8h2lB9CroM6rIyf9NB8LHmVttkkto4aJ4IPtyCQcdG5nBme8p+anEokNwUD2AFZdTU4IMpaU+oAMKf8qH8YmcllpmjRFLoXs+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); } 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); } /**