From patchwork Tue Feb 15 14:43:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 12747157 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 51EE9C433EF for ; Tue, 15 Feb 2022 14:43:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEA4B6B0088; Tue, 15 Feb 2022 09:43:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C9A3F6B008A; Tue, 15 Feb 2022 09:43:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AED206B0089; Tue, 15 Feb 2022 09:43:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 9394F6B0088 for ; Tue, 15 Feb 2022 09:43:17 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4053E8249980 for ; Tue, 15 Feb 2022 14:43:17 +0000 (UTC) X-FDA: 79145282034.10.37617C1 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf17.hostedemail.com (Postfix) with ESMTP id 8956040003 for ; Tue, 15 Feb 2022 14:43:16 +0000 (UTC) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21FCHt05025010; Tue, 15 Feb 2022 14:43:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=rpeW7i+VpNUVjdcqFIoBADDk6wjxwrj3gkylGr87hJg=; b=ROBss7FXWRDou1c/Rj8OyIsFL/4XSVEZAqBh+FdzfctavKhU9a6zS7gTQwKFT21bJ1fL iY8cZzzwX/JHushqZx0WZ7rmTm7CteW5cE1Otqhzko60UINBdg2C++EeWsIbv6HlkPOQ zYzqtJODiPcQvk7V9d3X0UM8C7PAmoa8b12tCAViEVRnZqzpfZLQEszewnBimsazcTFO Kj95NbpA9yu5UhlKMhBEvqhIjUkb+H9meF2Qj5vADGtELsuJfOi9JD8Usb1bA0ESxMGe durwFvakTscpJ0VFfRYkKFS1ADFYHhGyQFl9/vUJAAw0p7G2eWQjNk2W90Mnk7fnDTv4 7Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3e871psar4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Feb 2022 14:43:15 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21FEeVaT085748; Tue, 15 Feb 2022 14:43:13 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2107.outbound.protection.outlook.com [104.47.58.107]) by userp3020.oracle.com with ESMTP id 3e66bnpja7-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Feb 2022 14:43:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IGPB5uy1NfukiF/UrVcEEeNnws48EOzj36igz+6WJWZGpttj873JRTDkwQhFhnjkPIW41P2bKaK/dJmOfrHpIyohaIZc8wQ24cr/8SYdKv1AJN4wfMPUWHCB5TYzwwP/OM9lZeSxIvkNNa4azkCBUq2N/JZsV8+KK1+XpJkcsvh81kqjGW9O/KRL+632zf5nBohVpCTbPxA4HC5w9EkHr6FI0IYMDJ3yPgJaaF6zA43AqlrE0KbM/BIrc8ihrg8WE7FZA1Wm8U3XC/7a7rU7AbT5U/THy6ZgDYvg2ezNP+aRZLzcAklnaaeVBrR+LnsJbWV/s7JkAGXl4tpt7YgU3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rpeW7i+VpNUVjdcqFIoBADDk6wjxwrj3gkylGr87hJg=; b=Bf1csUAYTL9ZzdamSR8b4rFn5MkxELhD4s0dWl+UF9T4Z3MhHr7maU2Pee3f0sSLUmwFGw74jbivwuFP4y5Vfx2NlGWaKu+Y+4vyANkxHsS6PZ3jRJGc4z090YMpZ8cn4Tembeisj28l0EbDHgt4x4O4o8m7UHSUk6otXUvAwxKjqrMYwGdYxcTcf010hQJIv6khbHqIjyadts2WjwcPE/oWcNB8TFWmWSsOmKAm8LNYFHnUdEJPv4wjrXsMgNYld5ArB7qK8lgYFEiOOOJYfO3+TXpnJTaC7IMyWCWyR8qzdQrgk4GDxPGhauW76zwDz3BQRCexDZpvr8TkDDAdPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rpeW7i+VpNUVjdcqFIoBADDk6wjxwrj3gkylGr87hJg=; b=vfSd35bUwxd56jW3FCF5U+Pd0qB8+gXgbfJGbRCMEfOHWm4ICwterFFvwZAPBl3vUTX2kZECwibN00EmhLDnlPQWjjiqjsMjLETqd5Wqz9/SQlCtws33VwM50xBD5a/KGP8PFQdB277888Uogy3Z5GHtxP99ooNtZEVIFEopxyw= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY4PR1001MB2197.namprd10.prod.outlook.com (2603:10b6:910:48::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Tue, 15 Feb 2022 14:43:07 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::899e:951a:8129:8ef1]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::899e:951a:8129:8ef1%4]) with mapi id 15.20.4975.019; Tue, 15 Feb 2022 14:43:07 +0000 From: Liam Howlett To: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton Subject: [PATCH v6 12/71] mmap: Use the VMA iterator in count_vma_pages_range() Thread-Topic: [PATCH v6 12/71] mmap: Use the VMA iterator in count_vma_pages_range() Thread-Index: AQHYInpXYHHEkS3r+0qPwfN+lMb/jQ== Date: Tue, 15 Feb 2022 14:43:06 +0000 Message-ID: <20220215144241.3812052-12-Liam.Howlett@oracle.com> References: <20220215143728.3810954-1-Liam.Howlett@oracle.com> <20220215144241.3812052-1-Liam.Howlett@oracle.com> In-Reply-To: <20220215144241.3812052-1-Liam.Howlett@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.34.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d087d4ab-46af-4ba5-4b6b-08d9f0917b1f x-ms-traffictypediagnostic: CY4PR1001MB2197:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3968; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RREV64So6RvA2qa+a53Z+pdJJDutJCrL8iBRZzD1iSWBQJ+u0wof2tiJqRzJ9bG3V9CYTRAPUgUWeMJTE+0tn8yQb45u5SqdIX0LnOr+IpJGutF3oGnVrV5YhMqs5Y5nEoQiiVT7ui6dM3dh9DroRFkY5sdBG/Q++4kPcjhkp7bSsSsWD/q8m/FEhsPFWmq6Dnu5M+BQv8gbUkg+clueW5jZAJwuamwelb+J9kKxdO9gRBTVVpC6ELj3kQDl7nHPZo10vU4f1uLKgyhU9WEGZ4Zodm27Kf3qasES/qqco0Zr8C7uPne0sYaeG2/aUcS5wg8CajW+jokuAeuGMCke6+1ischT6xfrD4zU/0UE40WVy5g/6EEZntjq9o8boHLSJPdCgwseWkWcAFfvBONYpbTgFa3q6PUOwoLmjmXCjEt2lI6cu413yxxkL9IjfWqsc6ldFYrsSq7SQ2osnqMK3pfRMCwWpTtOjp3pAyG+azFxt0M+2aPnLEnVFnZXD3Beh9QaII2dhOCUtUgA7OdungRnFyO6NZ+ZW4euP6mh8GP2f7SaWU2yMC6tZdxZLWmbDKMRbFkTdPvFU9Db0yYDQ+BOpniexqmJKcuo5QRk3RYaj79STh4j48E/EeImz7NkJB6tvVmBC0lwpvocSbWwuQu5Or14JH6wfqhMoGu8SL3L+O7EkAwgL/hLXyxunmjzYvzNAZmj0u8WikV1FdFh2Q== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(316002)(186003)(66946007)(91956017)(6506007)(1076003)(508600001)(36756003)(64756008)(66446008)(8676002)(66476007)(2616005)(76116006)(110136005)(66556008)(6486002)(5660300002)(6512007)(2906002)(86362001)(83380400001)(26005)(38070700005)(71200400001)(38100700002)(122000001)(8936002)(44832011);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?ga5pwGNd/J8N8go7Pn8eaku?= =?iso-8859-1?q?/BpsAG4NPs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hUZjR3+ExJKMNkekaoJ+?= =?iso-8859-1?q?f3gA0Y0X+f8nt0Jqcwo2xjxIQrvp9F7XNhTgeXTZacfyhw6K+sVHeibQHlwz?= =?iso-8859-1?q?+Xt5R2HsA/YWKHDnsCOPh+LxRmFnA5bwYMa+MdQUVCCiJQQ5os5EqfS71Ryi?= =?iso-8859-1?q?bOKlvxvqeG7Dv7W2/sOgMBkz6AFWvnOe9nRQa2kHjaBBmwULoNd7reYn8RCp?= =?iso-8859-1?q?wvfnptey7LwSozVJOQjtgVaVizDRcdK1S7rrbUVespfEiJgJb+X85lt4dg6/?= =?iso-8859-1?q?mpqRryW/CODM91yHv452lXCRICCD/SU5BNUK0Sm0n2J27b8X6vdnX2hVswIm?= =?iso-8859-1?q?s646U0S7xvy1MkUBaAWPe9mLVkj906IlDXN+Kco22uCt9um5fTxh5l6bIVpI?= =?iso-8859-1?q?kgJkzSjua85ENJfo4Dt62pMOOB/2bq1ubfdJTxJbAuN3+7KIv79nF5ZtSiUm?= =?iso-8859-1?q?WUoS6bGSnanSHL/nwko+3lQk6/1sEap+io0EZfrqDsHSnLOYeIlCLbbPyUou?= =?iso-8859-1?q?FINM6AEMy6y5W0PpnVa8HxWkVpaVNn07T4wXvgxWm9AEeOm4x4oIDJaPnFaV?= =?iso-8859-1?q?d2Ynl294qw8O5zWaKVPyWjNkMoFQz6JeIzzsRUS/hTTCZwvE9K5LwYiL1mO0?= =?iso-8859-1?q?sZMSoof6Kj9SQ6258cRyneuoxmCb0s078Y5hditThHIy+oAxcO72Zq7/vmf0?= =?iso-8859-1?q?+5+dtI8BmWFV3WKjp+kyvcsIQMn5K+JYLexfl3fnjGl1Y6DWrUxrDpXHWtLM?= =?iso-8859-1?q?=3D?= MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d087d4ab-46af-4ba5-4b6b-08d9f0917b1f X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Feb 2022 14:43:06.2459 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: idSEDrjaEUVfm5vzP/nAkWsVv6xcyX2wiaGdlIIyTXWe+aDZfZyoYFgTEg65cSddT/ptyS3epd05/1AiFhAE2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1001MB2197 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10258 signatures=673431 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202150085 X-Proofpoint-GUID: PH_rL_EJAttLWkuSJjavkb6CaV3F5BzL X-Proofpoint-ORIG-GUID: PH_rL_EJAttLWkuSJjavkb6CaV3F5BzL X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8956040003 X-Stat-Signature: zfiwp5ohyffwba48ott859ox6aqmx5mh X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=ROBss7FX; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vfSd35bU; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf17.hostedemail.com: domain of liam.howlett@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=liam.howlett@oracle.com X-HE-Tag: 1644936196-600314 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: From: "Matthew Wilcox (Oracle)" This simplifies the implementation and is faster than using the linked list. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Liam R. Howlett Acked-by: Vlastimil Babka --- mm/mmap.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 4623e69e2c4d..72e66cf755d1 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -670,29 +670,19 @@ munmap_vma_range(struct mm_struct *mm, unsigned long start, unsigned long len, return 0; } + static unsigned long count_vma_pages_range(struct mm_struct *mm, unsigned long addr, unsigned long end) { - unsigned long nr_pages = 0; + VMA_ITERATOR(vmi, mm, addr); struct vm_area_struct *vma; + unsigned long nr_pages = 0; - /* Find first overlapping mapping */ - vma = find_vma_intersection(mm, addr, end); - if (!vma) - return 0; - - nr_pages = (min(end, vma->vm_end) - - max(addr, vma->vm_start)) >> PAGE_SHIFT; - - /* Iterate over the rest of the overlaps */ - for (vma = vma->vm_next; vma; vma = vma->vm_next) { - unsigned long overlap_len; - - if (vma->vm_start > end) - break; + for_each_vma_range(vmi, vma, end) { + unsigned long vm_start = max(addr, vma->vm_start); + unsigned long vm_end = min(end, vma->vm_end); - overlap_len = min(end, vma->vm_end) - vma->vm_start; - nr_pages += overlap_len >> PAGE_SHIFT; + nr_pages += (vm_end - vm_start) / PAGE_SIZE; } return nr_pages;