From patchwork Thu Dec 7 16:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13483617 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 B05F5C4167B for ; Thu, 7 Dec 2023 16:12:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 384FC6B009B; Thu, 7 Dec 2023 11:12:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 30CCB6B009D; Thu, 7 Dec 2023 11:12:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13C2F6B009E; Thu, 7 Dec 2023 11:12:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E9AAE6B009B for ; Thu, 7 Dec 2023 11:12:36 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 940F51C04F8 for ; Thu, 7 Dec 2023 16:12:36 +0000 (UTC) X-FDA: 81540515112.03.0028A19 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id D2D281A001B for ; Thu, 7 Dec 2023 16:12:34 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.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=1701965555; 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=A6Mx1me3lRifVAyarFo3UvYiHofeeRSOYcTp0JPrJtc=; b=SzPQB8OdPZ2lCCz6G74FtYsOiquPh9yt7VEwPrmu/OAfChdBMq7pLnV9Zwu6xgDwqt4ryH GJEuH4EqJ4NMoHZYy/8l/acWQ30IYyFYYStUEsgf0LKw9kz+ybz5HiJIWc8mOzIfJ7l9kY cPniMUtwFNSxT+Yzl973yTVVvaiym5c= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.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=1701965555; a=rsa-sha256; cv=none; b=xIho+28Bs6tr6VuD9RxOknXzD329d4eRJCYmHnZ1IGtHhKnK68lyRE0awtAgnFX9SSWEwk IqyJms3uKgFr42gpeLIhSfCq1ugZY4/9NFr3YU1+BRyhvlLxwdFyEzwTT9jc+lIke3+5Le ExXtrHqEKQqMlk61a7ahyibsc4rt1Wk= 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 CA1131576; Thu, 7 Dec 2023 08:13:19 -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 E834C3F762; Thu, 7 Dec 2023 08:12:30 -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 , Barry Song <21cnbao@gmail.com>, Alistair Popple Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Barry Song Subject: [PATCH v9 02/10] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Date: Thu, 7 Dec 2023 16:12:03 +0000 Message-Id: <20231207161211.2374093-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231207161211.2374093-1-ryan.roberts@arm.com> References: <20231207161211.2374093-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D2D281A001B X-Stat-Signature: heq8ycxf58xwsw6xj4bptdhpkstdwxsu X-HE-Tag: 1701965554-717539 X-HE-Meta: U2FsdGVkX19ZsIzXYH75sYym5AkRXH1cTmyhpqbjDfrWHsME4a8gtPFaGNx3CKve/kLm2nSOsOW+hCNdw/5CBuFbGsYFangOtCqz9PRvn1OjLAzKOKyyb4pWxcpuuGa+V4GquzqpwshBZtPXHcet9zyszO7StCR420wiLYSIy7aIFrtam8F+0JAJ/UKxDNr5QXyO8ol++JHWntKfDVQtTEltEzAzfac0WaaGNJ1PwAld+E1b/dCX68uA+5wkmwO0EvK1iZVIsOfrztWh2upDevfmTiVECLjKTkEAQyjMDpfBzjutfwTeq4pipvKyH22r02XW34PO4l866g+OILM/gfOv3uCBmqwaqnIM4eeQVKDulXGLL2BLGf5kzJNvukjHt/weXR2ue1AeixJJa7YJRKiYcZAoGJdaRcob9a90Y4SLs1ADc2+PLlfcoCgIw5py/pjENlp8tuaZVACCUVyF4UETPfTWseakGgA9VkSx0v3rgIOrqcrFZvYYEZocPS3Ux50skG/O5TKhkVIQuulKB8Pyls8f5chF5Of4EPbW24eEbFhvvPh9bFlYYwEDKPMO3Lei/7fMo9nhk67C/0b/2R1dGuOeJlD6CqxREdT8MB20RxzdMM81ffski19yQ/qUtFxZfoerBc5keZDKrilUxMaUhzzAAQUxLBoWhetvVUNG4gGD9dF6J0t31ZwMopuS+jwb1CbHhznpCZiYztWk1DKZSfgfKKsy0fUFoFYrXDPRq7otmH2cVY1QIFrdTtNzLo5TwMmSjFMmHqz4nji4bujNyfffkQIISS23JVJyCTylWU52yv4vxGFcBdyFjWnIoKk1CgkmLlwlstTIyI1CVVkLOjsFvOgVzSKG9zI7IsWMI54lTaq0B+UDuZAJFnoP9I2wYt6U8tY5LxVEhUanX6vnMAdM8ansXeRTc29y5VdqV9pv6s183xQ05IuqUxFiUFgNIBFN2Z1RQiSrgYp cVgAA9qT V0x2LF/1lNsC77krgv9aPkRoHfkwZScQBLBE8qdq/UF2FwJebvLwYKilHMOxOe3qZJCvk1y52LJmZ1roQIU1GASFtEMKqMqtHYV4qvaaWfL1tb2xbnMGHoYJjQcE3+LlmptFjm2k1NBqZ5ZIwsY6HVqxP61X65kPskCCCy1X6eTRTs0Mpe9D9oSiIlJauxyONEvgcYq0Ne2DDhYFel3BJhF0pNuAJ/vyb5/ZiJZyeGulfcl0JzvJLK9JAcaYfm3ZhnyKXRoJOyoBKBor26fDSW0v2QZM7bA50RpuC2srV+Lkqpjv4/llunQuGz77pv90ok/9ateo4C+cQeMhVIylrUJY30SErA6eRX9ZKFJgBy3kCEtugDLLVUx7jQaeYArOjlJ8E8JQG0+JYHB7hU//2bXFLvcvx2lIVgsGPAKhy0wQ5DDGECZIwo4WwuP5H7aqUSXJhR/mwcdHqMOo= 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: List-Subscribe: List-Unsubscribe: In preparation for supporting anonymous multi-size 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 Reviewed-by: David Hildenbrand Reviewed-by: Barry Song Tested-by: Kefeng Wang Tested-by: John Hubbard Signed-off-by: Ryan Roberts Signed-off-by: David Hildenbrand Tested-by: Jiri Olsa Reviewed-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 2a1e45e6419f..846fc79f3ca9 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1335,32 +1335,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); } /**