From patchwork Wed Jul 26 09:51:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13327781 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 BD215C001E0 for ; Wed, 26 Jul 2023 09:52:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 224446B0074; Wed, 26 Jul 2023 05:52:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AC906B0075; Wed, 26 Jul 2023 05:52:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04E868D0001; Wed, 26 Jul 2023 05:52:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E7F6D6B0074 for ; Wed, 26 Jul 2023 05:52:04 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B6100B254E for ; Wed, 26 Jul 2023 09:52:04 +0000 (UTC) X-FDA: 81053296968.18.85E1A0A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP id 10A261C0002 for ; Wed, 26 Jul 2023 09:52:02 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf20.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=1690365123; 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=P8ft9n3i6LFq7DQLCMNj+awnrZC8BqgiGOJGw+Gf8+8=; b=1q/Uhw4wFC7N/9JDmHSJXvP51oZWx98/JVkd+vvkUd5FNnVUws0dLjR9gdMM14vzqAw78S e8zrEUGMZNYOlEpOLF575RYsw0tOs+MQIMWvPFWYqfLKhl1dMapUd8Z0VMBoZDMatpATRC kv0cTK8vJrDg32CFoP1EdsQkf4INJas= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf20.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=1690365123; a=rsa-sha256; cv=none; b=yhuPwlxy5TSFEUjoKF3NaGbPbEKcA+OdYzf/yI+08BxF+xIO3bDpbo6s2tpO7iNv7X0DFY SVnp1Qn8RfOg34Bgex+dPtppF3DFA2WpB46ZUR/qZWf9YaGaUDtBnoSsnoqeKmVOpDVR02 Trrwm4iSu7TPRNhwu383Om+PJoWoKWw= 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 31F81169C; Wed, 26 Jul 2023 02:52:45 -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 EAB913F67D; Wed, 26 Jul 2023 02:51:59 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama Cc: Ryan Roberts , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/5] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Date: Wed, 26 Jul 2023 10:51:42 +0100 Message-Id: <20230726095146.2826796-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230726095146.2826796-1-ryan.roberts@arm.com> References: <20230726095146.2826796-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 10A261C0002 X-Stat-Signature: xx4xa8rxcyacf9swg55jwbenesu6die6 X-Rspam-User: X-HE-Tag: 1690365122-763068 X-HE-Meta: U2FsdGVkX1/NWOY0s9Z5nAPcN2W3M6n0bNw7mFG0KiqF6y7r23Kz9LxLnfD5S+4mDx1G+ecmsrp8V4ccpg36tljalvPZXhwjf3hKL9AuGXzm25LWviPQVrZevrsCbMZdsXzNZ67BwJ7spTlZBlZD7gbGqypOSPIBZ/4bP3921iRoAJ+NO2GTinp8dxGqm/Og/RlT34feARCiR81Ngj+K+AJvnn3GSiArRuAC2JdlwvNwpszdbYVZWrWiNvCI/WhAZWJpODtgipok+TJ19RicV3U9jfN/GrvOPpCmQLXgtVW1TVgpqSnYkYTHy7CMocmjN0kM8dLuDygCuNuYZU83fRSCPSUgTo/XzQN4Jt0yuF9TNY0pXYGy752tWGIHCV5iEnIxVYl2s4d7ziXhkXdQLBLuQGZIj9hRMd5i6wYAo31vK1s+UFV7YTbslxy1L7JnWD0pXUqGl+3Vg0qjH7LefZ//u0+hXrdCszJSDwlxadofTE3O4wFVe4Js84gMrHGZWQNqEvY4zggsPQD5HPuG7gxjoaV2jcl6wRZv2lTsfNRSLvEmj4CbXKjvXjmHSKUNiL2G8OT8o2tFCk3g/V1gpsbDK4z4JwZkhouNCySwNM56SOiwFwUhu8uepfG/UyJBFyK5/jmIiFvBTXgbO4IEN1mXN5k7KZmcUI1F6JybY+h0V4v+UmFQga24oXUM99dFCnAMZ5NXxGBSZbo1Apt8Ve/UxEsaiI41iCbViNRSq8w1Qy2E6B6V+BL9AZkmJRSv/ZUpoRKyYB19yu2nhivbn4QwCFMAS42Bk976RtMeZac+gNwJWTMy1X8HFCa62ZY0u5fhlWLC3jIGbg0HqVZTEAwDlNj4SblPuRxudx2FczzCIFv9bAAF7kZEdgsNGBYgz7IEOopBVaNwZXYBxcZVIEIaESO9tG+LjgLX4KZzh2uO8SBQLwB32zueif9rbWYx8Sq6VvsbHcofcon4OxG eGerpzff 7WbC9zk+nZCP/fBX5o0giiACN+rTch+n6nhJ2TvpSX+tVWOTIMiLvu8AXwi+y8aO8us7eQzXR404JEUxrwfjIrObGqzGhZebWS9a0hmMxxSfoW5+5Fsmx6Unz5rapAkqMk8Uvor462ekCM87Z/CWIh9KrtjX5EIKlN+KU78ontjWAETEJmVROaE+0fD8N0wFJYLfEAirKH6qL5FbeVYjda+VdyU9pV2xcuOeR0mkb1FRA6lcw6xAl5NgM5Je9nkBHTN8HfEcYoI5LEgk5oWoKhRSHn53EWrlChyq9uO9Uta40tFFUahdSd1dw2au5JVJNMP/u 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 LARGE_ANON_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 0c0d8857dfce..b3e3006738e4 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1278,31 +1278,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); } /**