From patchwork Wed Nov 15 13:27:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13456676 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 1C55BC48BF9 for ; Wed, 15 Nov 2023 13:28:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF5A16B033D; Wed, 15 Nov 2023 08:28:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7CD06B033E; Wed, 15 Nov 2023 08:28:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9454A6B033F; Wed, 15 Nov 2023 08:28:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7E19F6B033D for ; Wed, 15 Nov 2023 08:28:06 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 51542B5D6E for ; Wed, 15 Nov 2023 13:28:06 +0000 (UTC) X-FDA: 81460266972.22.380CBC6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 991FF40015 for ; Wed, 15 Nov 2023 13:28:04 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700054884; 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=v5seL2le1Mw6GIfT/Jkn3HeHK2JNJN/qsVUzKZyoMG0=; b=e6FURGkl6SorqVpjPBM9WT/njHsEr8/ixQZeLHElc9YmZiw0RAQtqYpTpCBL2/R/1IHJ3Z cMt0MXDwuTSpIvkndb+CzRnWpBI+UvBaVanfngqtTqHooOllKSV4oHlRJd2l6DXHougZvg dQm6/+joSBVQzwiDVNoQmKWkdcc4Sxc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700054884; a=rsa-sha256; cv=none; b=ld0qU2Oy+NdkGwkyaKkJZgol5ZfOHFNpJEgXmCTIAy5DFjU7V6JnOOVTwCAuJrVef/q5F9 LuIhOfsZT1CNGz9xDM3g2wmyVDcmySrVz3shhe+kRyDf6xCEf70p4sjH7CGwUjkv78OfeW 9An7glGs9oej2rcihS8Q2Z88E7H1iP4= 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 325DA15BF; Wed, 15 Nov 2023 05:28:49 -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 BAF573F7B4; Wed, 15 Nov 2023 05:28:00 -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: [PATCH v7 02/10] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Date: Wed, 15 Nov 2023 13:27:26 +0000 Message-Id: <20231115132734.931023-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231115132734.931023-1-ryan.roberts@arm.com> References: <20231115132734.931023-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 991FF40015 X-Rspam-User: X-Stat-Signature: nniwsd5k1u66b8zwtok38mw11huc5cbr X-Rspamd-Server: rspam01 X-HE-Tag: 1700054884-648581 X-HE-Meta: U2FsdGVkX1/8IHSlQOUtxWnWH/pS8T0WzmUDLfB1zUriUxDe17FP8rcmnHR+lMLjeLBy5loao6Tr4tV+h7zzqZyrR3zunVAMoP3ABFn/TbQomIxxjVTdx6EPAZflfY44bnWJQ3CRyqyNvj3jAUsxPQl4idHTWbBBBYYGW+LXKWUyGuldtqgQNSyIwNkr7lP/Hj1L8yYPsfWW9Dwz9XZiZJeiXt3aJTGjp+5C9LeoJ/UdjlVwjS/jZzGIDv2LZWB0CKnLanrBS7TM+YvLBxSkZP8KsMZxX75gksVjC7Qcd9k7FzuvXIWjXKDOTYTZPZ9HbbbYd7BaZf0GeyE84uF3WxAw3RP3mjjJjcWw6qqcamHIekSBqAuAfYqCREl10GwJVh8MM/w2hkNoI+NERdIazvSJ3hEmH9+wBqhgpL93lU25XFreR4pZCmAuZrHpCc1QJ/MFUMcbGh256slqYx966WUx9a06KqvpiLXzJhFLtDHDOH6UUhInwIlkaF5cX3UK+tWjejaf15YLBsGVOWJJ4tEv3235OvynUOVNr3hsz042vzy/Ru2J4lhI6ZR2uNM7FVIYi4BZoIoXAN3TCpU8A5npPFd/SMLfzsATfa13dnjxpWCTFd2+7T4XUrPp2OAXm/GamLOuTp1JXCexV1RKXviBG5Kjl2w3mldDmgjye1yv3q4Uv3Xirge2CWIFDkXgwfgqUn6aW15n3NlKhMECiedhokgnCaQ+zKroNSHEP8CjPOE3zqWzRdKz/83pS1UI/5h4ihK8LyzlNkhRgm7FVxux5cTonKefR8ahtdMoVa0OV1VGSrXIu3CmEUc6h5lZVvfP+wzAcNyoKXCyTe+e+YbsV3ZO0zAd/9Emn3ZY0HUuzPXD2KmUiwezy6bMalty0qkAb4SqBNAYnkazDzZ8Lw2+Sl8x821OonUwRiJfXIbvt7mh18U9elhuKemf/C67EftWctPTtDRU2rKLoA/ KXKHS58P 1ofEDYBRE8Z5N69Z0h0+4yzUAgx2IypUTCasXUvRGFO7IVvMb/SyrX0rqEokwdbOiS7mfYE+qUNhYjHxGi6O5W0as2U4gsKEQJ0y7FbiXIrxCslWKcdaODp3/7fjkeLwgrslumF0oqKJdQogpQXPrMB+GwR0oVKqyCoqq5TJFFWfxF3LXl8fADZxg6Jglx72E5j/iGCnpjxfngwVcxCl7dWuNqnKB60ur9zwMNM0F9lgqTWDoJtGliuAQvP6kPYwTD/L1s/d/bLcfNWlJUhlKAr+p1mMZ+KaeBwdBv4pAPYb8MQrCNqhVSc0m9gY5+6Gtu9Iw 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 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); } /**