From patchwork Wed Nov 22 16:29: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: 13465121 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 62759C61D9D for ; Wed, 22 Nov 2023 16:30:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7C778D0038; Wed, 22 Nov 2023 11:30:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDE6B8D0008; Wed, 22 Nov 2023 11:30:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE36B8D0038; Wed, 22 Nov 2023 11:30:14 -0500 (EST) 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 B10828D0008 for ; Wed, 22 Nov 2023 11:30:14 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 623E91CBE42 for ; Wed, 22 Nov 2023 16:30:14 +0000 (UTC) X-FDA: 81486127548.08.A24ADDB Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf28.hostedemail.com (Postfix) with ESMTP id 4CF59C0021 for ; Wed, 22 Nov 2023 16:30:12 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1700670612; 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=IPUNt6U2jwJhFX746QEQo+/G2+cG2KhY4KsnrUityrZdLcK8BI/zJEdpEQ3z2V/KEkLzIS meB5IEfljnuNkubAEJsERu0FyKq+nVCBjxLLmXt66/trFox4irpd82QnVuEP8oxLmbtg2e QaVFF9Br5gprPfdQsIvcVl9d4t71oNo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700670612; a=rsa-sha256; cv=none; b=Zn8qCwGUDOgXVY8KmvaMvcaKiQeI89H6Sf4afzBzhBJNPRZTnzn2DqFyta1M5rtXcEMZhT +okWcY72tSmiU+UiTk6vH29tLkc8AEa5YxoT+oTWBlvMDzQSKiC6s1iVLdhlR5vyFsKk7U 8D6qs3WALpk7D16l/uQwqWPpp+EtbeI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.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 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 X-Rspamd-Queue-Id: 4CF59C0021 X-Rspam-User: X-Stat-Signature: sw3io67nbgtm4cbfsgg8tykqnuopo7sw X-Rspamd-Server: rspam03 X-HE-Tag: 1700670612-80244 X-HE-Meta: U2FsdGVkX1/MpePK6NVZz3ewxM3YNffH7vlak+VxdAakSf+MooNGWf0fcrvIWna1UwlxBDO4ne6pttPj5GgNnUSK8JKVa+akKIXyosTr3tk80ZDR9doBkMztQvqDkH3QN6Ew8O9RhuQWFh5DaviCPM3W8WR88XfssFN5f0upIwTaSYtRz+dbktvGl3QvZK6fCtOCkdt7g6Zbm3QtAErFsa9krVgUiZCTY7xx8fW5zvnoimSIc50fEGPZlEyjl15A9tcNYxOf+mKc7NZ7Dd4SwSq+HkVbifZQgmslqSLcQkySeLMOEFaHXym+ZDlUJVejC1NXnFGPKez2HKmTDcd7OnXUQNxj+ugC8uApCr1d/XyfhdBpYCcCpch02whoDxXLZHBOh/SODa5QUXQonrY+u7p0Koj+V34kOXVvcoCYrs/pH0n0MgsS4go/V4Q77uZzn9oBOeGQ6VPht/QhY7wqZByqzwvZWbjcEgIZGquL/OeLR7+Letj33xJC2uAx2pIdmod37aWoalA6m+j+SqoNozrzSFNMqUqTTviYIAyJOsftq3gK82nyZsWNYETztb8jNa6iJycI2hKXLWu7uyIrkCaF/AuLJp3BkTxfvdcM7xBZ4BiISPdtADS2+cN/m1ToPMWSQ3Jb7m5kX3m1eA1R0k+kS5f+Xss4XEFBS5T8iq7rlMuXGMGi8HcS7BICvZbHyuWGc9mRQGcqwUGU1C/QmO9xp259Jz2DmeNhYlfmrT3tC+jW9gTdR6TDC9+WyPMT7lOQDYlrCW0SuXkMmm5ap521SgIXOUbG8xFuX5r642CweoZMP/ep6X7lT0weO5uzx8yUeGJnmCyD/o80ra513pTuWQVtCWLnuKW3Gimcw3jQ9GRk0R0y9IhRw5JCEpC7zdKqp3pSkAMW4A8frBMnp7W9ChlMcI+GSit1/BTMn3C/EM2WbIWwimR49q0ChKCbKdrcFLEXxlnWCmey2Aq OrxCv2Hq zXJUb0jLWSFrMRl4bd5/RNIpGeASrjND9/0Q2eSIdKZkj/b+RxaWClP11cENpi3kn0izq4BCcIJzwEwD9JTSYvvY46aFu8SDMr6MtIm3Xl/Vw+q5Nw/P7iP2GJ79CxxYexEUbpo+WTwKU0EN3u/Bd1y2eRHuySFD2FHG4q/G2TMGOJUf5PtauMbkZGfEpQghwdORdNY+Hv9EC5W1cXTcqyfotDJu1sSXr3Pe3DeJ/AOTpN8vk/0Fjl1KBDgJtDFdRB79VgFsmkRS4Vrf4r+S0Mag8Cp299F1f9K+IrVSV1HK0kb05AF4XuzqDcceMbpkyUBw9 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 Reviewed-by: David Hildenbrand --- mm/rmap.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) -- 2.25.1 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); } /**