From patchwork Wed Dec 1 14:29:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 12650013 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 A7D37C433EF for ; Wed, 1 Dec 2021 14:33:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B4BC6B007D; Wed, 1 Dec 2021 09:30:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 864046B007E; Wed, 1 Dec 2021 09:30:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6901E6B0080; Wed, 1 Dec 2021 09:30:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0127.hostedemail.com [216.40.44.127]) by kanga.kvack.org (Postfix) with ESMTP id 59BF06B007D for ; Wed, 1 Dec 2021 09:30:34 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1DE5682499B9 for ; Wed, 1 Dec 2021 14:30:24 +0000 (UTC) X-FDA: 78869460768.13.573AF7D Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf24.hostedemail.com (Postfix) with ESMTP id 124A8B00009E for ; Wed, 1 Dec 2021 14:30:19 +0000 (UTC) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1B1E16m2002526; Wed, 1 Dec 2021 14:30:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2021-07-09; bh=6njkiCW7jib9ZL0eAiceyfSDxsI4D6CKn99K4UiZZSQ=; b=ChQhOG5tM706mvrAoM8dg49weAG5H3n56OTc07/STZCg0B7VhQykTwMTdx+CpOOanCil FCPfHTtE9Df8Xe7yIdxbT6I2/6V3gNDHlxjlron7vbanjyhvCsNnTZCvYa07CrNBlYjb p7RDnZkC00Nsb6J6v0tr26ScDYsVMkA3B53EesKAJwDNAVhWqd9pUTwkqG7ZtaW0lkUk HOeEiJ46Cm8rIlsf1Cp/fvdMtYqpL6oVjl7OCvM4knfon3Hv8vwhb4VGyrxxuftnBQFT xR5aknTEdrw4w9lMyvVO/0x5ELm9WcKrHJ+V8N5dZJcOSRCe5QiCTs991utvkjgJs0gG tg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3cmvmx21sa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Dec 2021 14:30:03 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1B1EBMFG049269; Wed, 1 Dec 2021 14:29:55 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2175.outbound.protection.outlook.com [104.47.55.175]) by aserp3030.oracle.com with ESMTP id 3ckaqgkcte-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Dec 2021 14:29:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YSY3YAA1Eylt52OXVYPZFpMSPHwaDlJO2jwnbPMSzNfciTosrgKrJ86Cx08vM/XNQe6zqLn4RCDiCJk7GNeAfIF2bVFV2x/mpKWptfsS8CiacisCIZhcHBD9edT2gBtma/WLUeaEbrHWHjiAj6fD2wxQyMW34G5m2opA9zCgZBHQsj/4bw2TdQbliOh7AMVhzSG7kPcxUbC7/t8e1756ihWP8lKMwdJDO2NuE0AAbppMkMfn1Bz9SCnTsDcYaowzn9KB1rwi1CD28OIfD+UKRhr8bGvQti4fvPyCn67nocCuUHQjI1GDfhNYPKjfGjSdejoJEeYWcI8VbpoQACreWw== 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=6njkiCW7jib9ZL0eAiceyfSDxsI4D6CKn99K4UiZZSQ=; b=MAnP+o51gkm/32RJRTO4Xyb5mHvqL6O38dm5UQGBjkH2ZaM6WtCIROPJUFpx6eWwHMvgVA1iua33q8p/zt4qSCmE2kA2qd3ZzrS5LNV57gX2f8IIIM3HFuv+hE2LpttAXqu92HHxTmDIiIJQ7lqApKjsG7Y46oK1OG8ks9Ni+/SMiIaRfYbaUtsH7s8iBwqvM8s0OIqnIBiqHQd5HdUX+cFwuZd5mzUDXRdw512KWVtVwfXZEaFRZb/Vu5Yx35WFNdSj9e3ULKnkd4wm8+CAESOEi1Tw5G2zUt2c6E77GN1ulFN4DODKeSLf1eE7m6wUqG4xiwk0gorT4ukAqA4CGA== 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=6njkiCW7jib9ZL0eAiceyfSDxsI4D6CKn99K4UiZZSQ=; b=0R/rTJsqWcM2opGOJpwQl7c3ySUe0AdNAcWcX0H3g+J/h6n6co6A5Gq7IhbphzgCZGKvDsECZtnYnKBvrAO5S35qnK/1j2bi7elepqzvNHr6VRJAVeyO725Xci5Z6YGwOYuWlKBcM7A2+vdAacYDmtO388xstxLgLigR9YuRi30= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SN6PR10MB2768.namprd10.prod.outlook.com (2603:10b6:805:4a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Wed, 1 Dec 2021 14:29:52 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::c4d0:8291:84d:ac66]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::c4d0:8291:84d:ac66%7]) with mapi id 15.20.4734.027; Wed, 1 Dec 2021 14:29:52 +0000 From: Liam Howlett To: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton CC: Song Liu , Davidlohr Bueso , "Paul E . McKenney" , Matthew Wilcox , Laurent Dufour , David Rientjes , Axel Rasmussen , Suren Baghdasaryan , Vlastimil Babka , Rik van Riel , Peter Zijlstra , Michel Lespinasse , Jerome Glisse , Minchan Kim , Joel Fernandes , Rom Lemarchand , Liam Howlett Subject: [PATCH v4 08/66] mmap: Use the VMA iterator in count_vma_pages_range() Thread-Topic: [PATCH v4 08/66] mmap: Use the VMA iterator in count_vma_pages_range() Thread-Index: AQHX5r/nCuIxHsF9tESS2yzv8mvmIg== Date: Wed, 1 Dec 2021 14:29:52 +0000 Message-ID: <20211201142918.921493-9-Liam.Howlett@oracle.com> References: <20211201142918.921493-1-Liam.Howlett@oracle.com> In-Reply-To: <20211201142918.921493-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.30.2 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4ed84142-a74c-49fb-ae51-08d9b4d709e7 x-ms-traffictypediagnostic: SN6PR10MB2768: 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: jSiTXLEI9iOozDodNpV0eN418xrT2GHp54vvZpEmIR+rgQ1VYpYA3JUAb/svj0cuTB6ELnvsKWVWbYYFAFnh7XtZWtHdXagDTEqu4BHlV7dSKlPz8cpYYida1mF+rmt6VZmf4+kYRE8mCFoDsdO5Od4dJXzq7qvsNkZ7Z6tFCG1Q+h/3xoIKD96zSsAoOI7aDASxKlaIdby1iCaITm3ZbaRbq3+1Bkn5avrvo8o5PI3Xknc2tA4DjUl74gr1ib8DEWxJcOPtf6VCBfzRA4TMo4lSjq7eC1kaCclQffDvf2VGRrxwakIOgM5aRE82SC0jk16NHn2blCCMmDZ2ueqDygmCtEv5WlW2l4z+CiVCLRmIJ+/FA7QtM7SkOlz8/0fuWEqDh8hjFMyyCObKD4JphMStUQfNy73I2vqREASRRal2S3i9n6xx1JMfQA7ASQuFjshZeAhl2MpDADE+2lfqiXBSzr0u8GaVUfotTKSTCOAjUlakRDq0Uzxn4tvys6OlG8GvgbGgc9Fli9HM8mIboYLPsLv2JGRXXczhAb4HqTZ9RPLq4kRd0akA5uubHChBZJZBvMuZ2b5AgNyMyj/Mr9AYMqZsm+n3BunEvoS/ZU6WYrVq0ZmyPcG+c/UneTO3mynv5hUfjf4uu36ajsReru70fn0idl8PijQscmKgH1jcCWp2lCXglJe4YvJzax4e6gXFt3IwL5B1dypnCIk2Pw== 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:(366004)(6512007)(508600001)(66446008)(64756008)(66556008)(66476007)(44832011)(7416002)(66946007)(110136005)(316002)(36756003)(122000001)(6486002)(54906003)(2616005)(4326008)(186003)(91956017)(5660300002)(71200400001)(38070700005)(26005)(8676002)(86362001)(83380400001)(76116006)(2906002)(1076003)(38100700002)(8936002)(6506007)(107886003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?p3SOf9ERqOASr0JRZZ+KJAK?= =?iso-8859-1?q?cbqSzhGrAGQYNbXWHSduSh9Yfe/zMKP1HBTzeZLZITzNCGKp2hK8y+6joDO8?= =?iso-8859-1?q?mlQ1dmSSlagTry4WRpiXSfyY9OONZGs8cVM0EDtaWyxgjvouex+IAY3H+8jW?= =?iso-8859-1?q?BfgdMVvUc0GSznDXSdm6W2AD2x0He7x+r4SEpq+dHqyhPo1qznyG1QTH0xVD?= =?iso-8859-1?q?+TGQQN5GExOAhgaF05cyv6ynUz1y0/4wuNssSFef9teCoVYMflTsI7yjZcRV?= =?iso-8859-1?q?mgR/AMTI55NLKYy4GqLb2TDc9occIJnbCakexSDb3NcA0YCXEJmJlnOm2tlH?= =?iso-8859-1?q?/TkVMrPXbRN8aHUshQl2F8Tha0QGd1OX+UckbHoS1bh08xhik+eIvhwmlgCr?= =?iso-8859-1?q?LpQsb74uazK8mQXll/t4cMN9PMJDdgZ6fwHSOUUEUSNQtI13Sz3qp6rjiqII?= =?iso-8859-1?q?uNuvPJuO62tsbO5Y3dUFtABO3auRyF3hCyonm8pV8OojQRRDfPgmO1eIw8Xf?= =?iso-8859-1?q?A3zNTR/5HGT3KpNK5cNxIJGVV6FppoPiZauB5hOkGmneTpi7KaZIeKFlIIfy?= =?iso-8859-1?q?yUOhfePyzlgNhTQaoh5swONuot6hwd9/cNcSQCuR/xk/IZWI8qz5tGa9vD5G?= =?iso-8859-1?q?bpCqJq1EKQDPl2AN7ceOupA2kfAFU6zYS406MlgkO50IQ59BTwgGpHuWFPI0?= =?iso-8859-1?q?+orSBWkxfUc9vAZI21HQW7NqxRMszkdRtx+yLZsaKEhDaiHm+driHnl1NvsJ?= =?iso-8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TL3ORYFfZmcc4xphtRZb0IIp912zIb52Xw?= =?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: 4ed84142-a74c-49fb-ae51-08d9b4d709e7 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Dec 2021 14:29:52.1275 (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: SJcBaYookkzBJLVfdMx46HxpwWcdiGeuYZzu0vXJ1OUSBbrZZWeMXckqfJuQrTxy2YmgROl1KmEsVQMh1JBC0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB2768 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10184 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112010081 X-Proofpoint-ORIG-GUID: Fpx_ra1SG59DMpWNUCuCPBKw08UPoTtH X-Proofpoint-GUID: Fpx_ra1SG59DMpWNUCuCPBKw08UPoTtH X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 124A8B00009E X-Stat-Signature: z9r6ajzfsrzjogk4ibeqaqe3fpyos4qh Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=ChQhOG5t; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="0R/rTJsq"; spf=none (imf24.hostedemail.com: domain of liam.howlett@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=liam.howlett@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-HE-Tag: 1638369019-134992 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) 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 9fee6e6b276f..de78fc0ce809 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -669,29 +669,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;