From patchwork Fri Apr 14 13:02:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13211456 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 5C12EC77B6E for ; Fri, 14 Apr 2023 13:03:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69A7A6B007D; Fri, 14 Apr 2023 09:03:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 623716B007E; Fri, 14 Apr 2023 09:03:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49C7D6B0080; Fri, 14 Apr 2023 09:03:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 374206B007D for ; Fri, 14 Apr 2023 09:03:27 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 041C01C5C48 for ; Fri, 14 Apr 2023 13:03:26 +0000 (UTC) X-FDA: 80680012854.06.B116F30 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id BA92F1C0029 for ; Fri, 14 Apr 2023 13:03:24 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.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=1681477404; a=rsa-sha256; cv=none; b=T0F2OlwrcYZDquKXkrYgnl5aCgkgPFP9yTI8fuFU5Y7jlWq+p1FwaN3P50klBrVh5RGHh7 +U0tCfszcq12oA+y+UHGajP+DwpcrbS08N9B2ROn+LCpe9NIbeWcB7SBPHQxjcRXg+o6ir owExTVcuNIzus28IAL/7mqrO/DxSn/k= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.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=1681477404; 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=eEfBR/V5t3+D39tjfvkOsML7QYeIT9w8k1Ieor3nb6Q=; b=e6mXsabdAi/PKyygGlux4t5WKG1P5JKKuW+lwMVZhWYZYAiqztcM6lO28T70ZZ+b7Z9/nw oyDmGDZpnEA+LZNhvYaKNrD27vCFG31EmAafTfNFbIk+ACdXhR/Cn464CzmNwgg7AXdH9d ns25fUsyWoFnAMFtcUN0rJDsolgIHAA= 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 73A851756; Fri, 14 Apr 2023 06:04:08 -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 EF0BF3F6C4; Fri, 14 Apr 2023 06:03:22 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , "Matthew Wilcox (Oracle)" , Yu Zhao , "Yin, Fengwei" Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v2 PATCH 04/17] mm: Implement folio_add_new_anon_rmap_range() Date: Fri, 14 Apr 2023 14:02:50 +0100 Message-Id: <20230414130303.2345383-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414130303.2345383-1-ryan.roberts@arm.com> References: <20230414130303.2345383-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: BA92F1C0029 X-Rspamd-Server: rspam01 X-Stat-Signature: fdd81w666383j1m7g6qi8n1jy9s6cq6d X-HE-Tag: 1681477404-521747 X-HE-Meta: U2FsdGVkX18iRDQwrAraEkxb8355CB/DyVXyyZiVsntErD5ZWbmP4rvB/0977iIKm78vfRrXCr5XWGh2rfICHmSqOevyT6avZWnvY3DrzWQeQAACGgBSBk1DQOAnqOh0sC2tChB5IJVK/WCbFarPl6ZE32OJlP2u02H3T1CBoN8UDF/llJysK755MWHQbFGPIRcjlpHoOKjn/HsJPd2vgdd+0t1wsBy7LQSgHd1j5O0wb5xC1qdFROBms0koKb5UkzteBAvLeZSN2raODyAEhIMc9wphTS3/+Y01tJ9SdhOeRnyff/zaqzduK6Iw99eSUeiMxFJJarqvxi90rM3XRjlmydsT6FIePmkvucB4LZectYX7469OFlNsA4UAkzfFzCVSqbCsKY5bFQIxYLIkjluH0taj5p+jsEtrW7hW73+UQlgDy9/U9sJnueDoXSjyOZN/VxtYVeEvLOC9EInm+UfFTFlG6y/TQbhedVzCrTy0FABX5KYo3g+/MtzXXcGGla+pSl3/Yd5lr6c4JJGdw/rp4gE30QODu2vguyrtHUhoYe5KHhLp9MrIjXlOSaobB4ajatEfk9MH57tTd24OjwI6JWfFav270ETbks/nlEAiojQ6FczsGoNr8E76cxF7HXNYdw7muh8mzZMdrutB+IQjgRs5iRp2RY2qmJ3GIJVz8E10pPEs+RxM6T5dYwF3dbzFsoN6lOVhKqe0KyFxtRBw7icY/zrRAdXJw93zZoCSSZS0jGUYkLZwGpgdzgyx0c9dn5NGNeRrlC9qLFT+azrYWuonXmfbkO5PeOPo9yiJNdSM8r/YeBUoDuUuK/t9EIcGvihEUv7SofByYNntrSlXNR0Mh+upsWDow7cjBUDZS68q9Y82t6yGquCGlgd+NYRb5PH/uXAkVT8HxNxGisIKoc6hchlxwY3r+SfNar3AnYvcC2Rbj2RabCv8O2ZjYg4Ffq8KzZaIeThYAjB NCBB0tcX AXBlbWE38cMkcF+YLD2BB5AlrnJw56W9wIPRPq3b9VSb6EL0nk6cv8PGMsTo4+0mQsR//TLPC7ey8e8HwHEBmGZxUOwJctVqnSJ0dj8iCi+OaDdVD6bBrydztxGmlLIVUw6ffJNiHhjpD58OWHs3ZEvVOuPJ4tvOMSs7n7nGJMIrz8IZvwzvKZDO/W16AG+cV9039RpQAQOPFvi/gkiUvdJlrE611qtv2ydG1 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: Like folio_add_new_anon_rmap() but batch-rmaps a range of pages belonging to a folio, for effciency savings. All pages are accounted as small pages. Signed-off-by: Ryan Roberts --- include/linux/rmap.h | 2 ++ mm/rmap.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) -- 2.25.1 diff --git a/include/linux/rmap.h b/include/linux/rmap.h index b87d01660412..5c707f53d7b5 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -196,6 +196,8 @@ void page_add_new_anon_rmap(struct page *, struct vm_area_struct *, unsigned long address); void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address); +void folio_add_new_anon_rmap_range(struct folio *folio, struct page *page, + int nr, struct vm_area_struct *vma, unsigned long address); void page_add_file_rmap(struct page *, struct vm_area_struct *, bool compound); void page_remove_rmap(struct page *, struct vm_area_struct *, diff --git a/mm/rmap.c b/mm/rmap.c index 8632e02661ac..d563d979c005 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1302,6 +1302,49 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, __page_set_anon_rmap(folio, &folio->page, vma, address, 1); } +/** + * folio_add_new_anon_rmap_range - Add mapping to a set of pages within a new + * anonymous potentially large folio. + * @folio: The folio containing the pages to be mapped + * @page: First page in the folio to be mapped + * @nr: Number of pages to be mapped + * @vma: the vm area in which the mapping is added + * @address: the user virtual address of the first page to be mapped + * + * Like folio_add_new_anon_rmap() but batch-maps a range of pages within a folio + * using non-THP accounting. Like folio_add_new_anon_rmap(), the inc-and-test is + * bypassed and the folio does not have to be locked. All pages in the folio are + * individually accounted. + * + * As the folio is new, it's assumed to be mapped exclusively by a single + * process. + */ +void folio_add_new_anon_rmap_range(struct folio *folio, struct page *page, + int nr, struct vm_area_struct *vma, unsigned long address) +{ + int i; + + VM_BUG_ON_VMA(address < vma->vm_start || + address + (nr << PAGE_SHIFT) > vma->vm_end, vma); + __folio_set_swapbacked(folio); + + if (folio_test_large(folio)) { + /* increment count (starts at 0) */ + atomic_set(&folio->_nr_pages_mapped, nr); + } + + for (i = 0; i < nr; i++) { + /* increment count (starts at -1) */ + atomic_set(&page->_mapcount, 0); + __page_set_anon_rmap(folio, page, vma, address, 1); + page++; + address += PAGE_SIZE; + } + + __lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr); + +} + /** * page_add_file_rmap - add pte mapping to a file page * @page: the page to add the mapping to