From patchwork Wed May 4 01:07:52 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: 12836623 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 CA71CC43217 for ; Wed, 4 May 2022 01:08:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 677718D0005; Tue, 3 May 2022 21:08:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FCCE8D0006; Tue, 3 May 2022 21:08:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4012F8D0005; Tue, 3 May 2022 21:08:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1FEC88D0006 for ; Tue, 3 May 2022 21:08:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E25792928D for ; Wed, 4 May 2022 01:07:59 +0000 (UTC) X-FDA: 79426273878.03.DC46756 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf31.hostedemail.com (Postfix) with ESMTP id 4D83B20080 for ; Wed, 4 May 2022 01:07:44 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 243KvDs6027626; Wed, 4 May 2022 01:07:58 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=FBfmXrp9KlKhKWdEz+tIPzTviS3VeWBUi0almuvY3SQ=; b=sxnm2UOObL1nzSCd1U9NMniGTsgj9h4rEMBhCwIrvPAto9SauxVNdvgJS3hnyrLCKsGx zDaiNhrPShU0guZfx14kQt9M2+TZaVOOXITTxMhRZunlwu3bhphsZN+f8mD72kPyRjX1 blU3o7bH2P3pZ0r7O+9Js9bGNoxyTczeThxIHqhfl+o0wfmlDa6NiCH/VK360jsoqGRR K0I2OD+/48Sfv0ytp/pKSRumu/xVQ8ZFaNHLzbPLHdc18ilN72TJfh72c1026MOTgv7p i2oEmadNrlLNXXYeB1xTYS8KrYQ80ik8Dvmx506ipW9SGT++YGmepKuRwRdTQqF1go5D JA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fruw2f65r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 May 2022 01:07:58 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 24416SvK039119; Wed, 4 May 2022 01:07:57 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2176.outbound.protection.outlook.com [104.47.55.176]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fruj2wdr3-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 May 2022 01:07:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UPEdvSYhFhxH/y9vR/3+l7WUcRLdhrTHHGDyrbCOmH8ic9QpNViys1Dmx/Hz9ZGN1WZsItOmxnwTHYqVTTy8yfaLer4XvbJcmNi9wIjjigYO5RRnn+M9oVIA1+m/vBVsDK5KFRjEW0JGLMhW/TedNLusqSp4suxwDKjunow0PG/ZLv1Tdb2ZEgvWIAWwYBph4wcwk/qhw8kyWBiRhV0rCShCL4AYboHDXrh5sFoCRe0TJtRSW3LY7DxHTumu6Bjap3PrwUq2i5mZlJUOJ/lALFzsirdnY2sM9jXD+oPQIL0cpum4H17/4HHdbhzH0GbVyQSAmRm7PkSzbnI7IQoMQg== 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=FBfmXrp9KlKhKWdEz+tIPzTviS3VeWBUi0almuvY3SQ=; b=AAFavG+NusKY5JbJv4Q0wV0DilqEmzUgQ7WmfRzTnz8DAQh+by7xTik1tePSGOE/6tn5qP94g/GvzpdOaEO8sGbmOT4pk65l+hIQZf5+70FThmo/KmzNeq8YRGuz4vsIYOq9UFJqpaT8uaD3IEHfiUQEc9lq0dSOtZESNrdLeBS21gApp5G1MXKbLVfOfofuVjZ47RyAYOyzzBdscpDLJjZYb9OJjSx7Kv7R+JC+95DK2plsk7GooS7UyimCkXdamdMMt3RifNRnbfcbxRbU8US4KJfRLYZHcUDA2AZyc06ALlL6dHqbsOgFcfnYrA3kBI9D+i1SztcZrvwp/ZiMug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; 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=FBfmXrp9KlKhKWdEz+tIPzTviS3VeWBUi0almuvY3SQ=; b=nrqIuNTB2kW8ZTdlykK//ZMgehb3oLoB+A8GBRx3eeql6fB0/wsrtIR0uXGvvUzWxSJUFTB3X7AFP11fesoxg/A7fwczcPuwMnaxKlAr7WyW/wyaqVv2svZ1y+bK1tSX7W/kwAGaAlcBoZUD7xsfmTVb7zoZ+KsRSv+wXYjfljo= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CH2PR10MB4214.namprd10.prod.outlook.com (2603:10b6:610:a6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Wed, 4 May 2022 01:07:54 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::318c:d02:2280:c2c]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::318c:d02:2280:c2c%7]) with mapi id 15.20.5206.024; Wed, 4 May 2022 01:07:54 +0000 From: Liam Howlett To: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton Subject: [PATCH v9 10/69] mmap: use the VMA iterator in count_vma_pages_range() Thread-Topic: [PATCH v9 10/69] mmap: use the VMA iterator in count_vma_pages_range() Thread-Index: AQHYX1Nh7aXcGbnpL0+njfyrlBp0pQ== Date: Wed, 4 May 2022 01:07:52 +0000 Message-ID: <20220504010716.661115-12-Liam.Howlett@oracle.com> References: <20220504010716.661115-1-Liam.Howlett@oracle.com> In-Reply-To: <20220504010716.661115-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.35.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ae9c0e72-7310-4367-ce37-08da2d6a84d1 x-ms-traffictypediagnostic: CH2PR10MB4214:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: BRLKU9Nf1PqFfvJMR1UVTNoOwpCoHVWV9WFiR4JdfORbMrBLK46PGujvQmswndNhezvRcJtBKVZYC9AGxhE6+tRtHVyH0l4lWIu09IbOjU1nNngqxYserkSsJPFrpYqDOjEg9Bac2rULtIgXJDmPzJvAqkRiMmeEfASjLLpz2QbI3GuplWeT7ev+2qCMHH8swBNto8I9fLT3jw9txRPp1cW80OFXz1CbcAuaqfbhMXqO2CwkWCL5w6yvV0ZuTjmymjTYmkWbtKrIHauM417jhnsXFVm3bmGAbyr2hEIUDDEJp+c39wNhND4tZ7vHZ9pn/HDiAAMc5k+eCaUWdObHstRPBO/lQ9gz/WpDWGMGnFoeC0XA93gcDsP988Ki+4O/AGXiSmFSu8ugTjUlfOpkHGJ5AKlDlzjrTeEEgDZLrzjQnq3IZHhqvzgLjBdkI9u8V1YhupoFXFTj0dO6sVYo3uHpCNufhg+tugD2ddlJRXmAJtUGppvMWshdCxGGPtp0NwfntR1tcUZSxaSFdREfa1vtbu9QwU683tulUDE68oWKV7bjGkMdLMgBkOUhOoyuFzuIq3PTZO6P9kQO+0qJHHI4BwSHg+b/9XUMBgeX/r0PnF2OnBdkPFrryWAHPZ971f4dC6JQf1cPzaJlWagJNnK2L7WUP/aFpLORwS6sZuslDBj49IDsIlXNUFT+DF5crbExWF/d/LRYW0W8W2lKbw== 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)(66446008)(64756008)(66946007)(66556008)(66476007)(8676002)(76116006)(83380400001)(2616005)(110136005)(186003)(1076003)(316002)(6512007)(86362001)(26005)(2906002)(6506007)(71200400001)(36756003)(5660300002)(44832011)(38100700002)(508600001)(8936002)(38070700005)(122000001)(6486002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?PLoMw9zw3dHlAx/Jf6p86W7?= =?iso-8859-1?q?G9SEkGOlJFCdLCyK357Jk9JI2iIMMEUgWGempUVnRfDy0jNL1O2NrX9KOeGl?= =?iso-8859-1?q?UEx9H+6uGKThH8ju+LIdGtASubfdTdwU1Q9WNXMRrIKdbVmwFvA8kY4DdpCM?= =?iso-8859-1?q?mzcZ2oLMiaY7ukaViUWxMEVwlrg5ypjArm1ZubZ/9uqmB0qFAyGpNaio9Ezv?= =?iso-8859-1?q?NAHnGGz/OOKGn3uv6oQJ01UJzpFiamHy5CFG4prrzhMbtvmru0VT/rcqslTd?= =?iso-8859-1?q?dwC+LcQOIDGa3fPqKQyNnSDnCKilT01Cwboqw1oo3OL6x5SxhMKw4Z4PYokP?= =?iso-8859-1?q?nwzf79TB7JgBo61p1GAyWpW0iO9Pea39n0pQxT0aaO8X1FFDln35l9w6zqES?= =?iso-8859-1?q?pN3XCc7I9YPPrlgx771t+75F4K08nC6U6ScEbDJ5E/aKbpRtg1ba69lV+9pV?= =?iso-8859-1?q?Om5OjRIH8v3FP6w028H0+CV+NBqZqcuVtDg0Dh3G2+hcaOECIzf0v2I78t79?= =?iso-8859-1?q?A/IGRkxVnpllGRo5HQrE4cyn1Y/9XF6DdE3hv+jMvgRLWwGzsP5GtW7jN9ur?= =?iso-8859-1?q?DLQfxe02oGAiCOZuNqo0jxHtndrMF7v3r63DCazFhU/58BKgmnx1NWZojbgR?= =?iso-8859-1?q?TJtM/JlED5S91Sn6OY0qoSgoJalarNmHUp/zng/QfzVGFSWnnjJczmRQXRAO?= =?iso-8859-1?q?gA1aKlJW0yrirka01chEQaQPujitWmRBrtfb9/1E8DGAVE+kDByYkHv2lbMv?= =?iso-8859-1?q?cXXFwkb8Q8HQYnk8cN5O2reqwkJBSLxrOogF4LRXr/rOQS06LJRGm4YOduru?= =?iso-8859-1?q?b889qcV6zSYlBMlMgucIUskyQgpf1P8VNXNSM7o5oEXBPvlWPo0CA5lxmBH8?= =?iso-8859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ZmGg1U95JetdqT4hX0GvQab7RjKN5yL6YeiLq?= =?iso-8859-1?q?q+rqE/3w=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: ae9c0e72-7310-4367-ce37-08da2d6a84d1 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 May 2022 01:07:52.9941 (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: WfKb1SKnOKRjFpQV1woaFu3hyoInZoUrxXZQ4i1WKdeiCo3SRBGt/nZwA8GvM+ykz8L3g51xypXNklhpV+xCDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4214 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486,18.0.858 definitions=2022-05-03_10:2022-05-02,2022-05-03 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205040005 X-Proofpoint-GUID: WqMfaISErelorzYWXi-1RZC6AEinjAe9 X-Proofpoint-ORIG-GUID: WqMfaISErelorzYWXi-1RZC6AEinjAe9 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=sxnm2UOO; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=nrqIuNTB; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf31.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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4D83B20080 X-Rspam-User: X-Stat-Signature: 48n66jow8cjg4s6p7tggpdmd6ap8qy49 X-HE-Tag: 1651626464-551034 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 7e01bab46416..4343286a6ca1 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -675,29 +675,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;