From patchwork Wed Jan 29 18:16:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13954042 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 DB114C0218D for ; Wed, 29 Jan 2025 18:32:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E61128008A; Wed, 29 Jan 2025 13:32:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 593A8280089; Wed, 29 Jan 2025 13:32:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E5D028008A; Wed, 29 Jan 2025 13:32:10 -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 1B8FF280089 for ; Wed, 29 Jan 2025 13:32:10 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C06F7A0235 for ; Wed, 29 Jan 2025 18:32:09 +0000 (UTC) X-FDA: 83061333978.24.5839FC8 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf13.hostedemail.com (Postfix) with ESMTP id 1FCE520016 for ; Wed, 29 Jan 2025 18:32:05 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=b3hchN9H; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=sDsPQE1Q; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1738175526; a=rsa-sha256; cv=pass; b=cq62YYwdD+HfHoz1Ip2IPPQDij8/kGSEg2Wai26JHG+v5/6WZKcK8P88VlsYvV8Xh9UKPN bCpXpxIE4lPaZljpKmMFpPmexLzNIAjYNABEKb2P2FxwNZK3vqOInaCxM/rnO0XEmbkuqk 4BbU/w5Pc2q1eg//szL/a+uVlIpb81g= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=b3hchN9H; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=sDsPQE1Q; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738175526; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YJSKWlatYWLBz+jZN7/O6d3gx2Ck2wdZ4ueX3ZXgvIM=; b=1AKOZBdrr3T9gVKui4Sc0M83Oa3LMFa7GQBZbstkXbDok1A3Y9Ue9gG06hWUxBl6oSt5si XzWqzztrrEW0jv9F+Ec0rGG15khRCfkoQ6s2yJaATLzwZH4wD23PksHToF3m5/8Wajidzb 13rkgKa119iGcbnEmb95tWEJYhfgl+s= Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50TIBj5K020203; Wed, 29 Jan 2025 18:31:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=YJSKWlatYWLBz+jZN7/O6d3gx2Ck2wdZ4ueX3ZXgvIM=; b= b3hchN9HdESwB6bGDF6kIwjwaZjuuksasbZIib3fB8jVOaFjNHIlWl3Zdem6qQRm blNeQf9O3+F8vpJsVBA23dddXUxXNKs/k66PzRA26ABFz2YSwbHV5BnuApuzh6ll IfP1P/Pm+HI7JqydAXRj3P7fNZUC5/H3nIouy9YmfhP8alXyns3a28uu/Jz2VPjE EsbdoFzKu9aDAyJmQAZmRoL4KlDuItO/fBAlnlh12ww12YfGfpkYJ0rniAVtpWen o7NqPvctNOrzNwuiM3+cxOYgMXz9RhfKNdQt7IQPg2XTETpD8Y/Lx9fxmP9BMhis kEt31s5uuK4h4cc3DCqPbw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTP id 44fsd501cd-1; Wed, 29 Jan 2025 18:31:52 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50TH3nZH034139; Wed, 29 Jan 2025 18:16:58 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2175.outbound.protection.outlook.com [104.47.55.175]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44cpda2sec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:16:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Csg9+iC/KLOl2ncE9t9eQJ2yViRHQhvtacRe+hIGu+eWi5pdy0zD0xUWIm0NdagrfyD30fE1HOTxsB/aODilwbY6UJcxv1VZpvEYIUw3bMVcqPmgPBD53k7hSJqN2cx29/06wMM6GaR70hLmWIks0Kl73oMBlMapxOIKOR9mGSqR6Lsf3Z5D7/6ZFpeKY7Ov+MJFaVLGUc9u/RK+i0AByxpO/UD6mZ6IMaVryygkBDjWreFF29oTQcLS/qboKPIgDAI0mc+5y80/SFLSfu2lBI3TQ6PjcTxomDZO3Vbu6GJLkLepgyJZKxzp8uvW/wJI4H+0Wcg2IOGAqdRI+Ea25w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=YJSKWlatYWLBz+jZN7/O6d3gx2Ck2wdZ4ueX3ZXgvIM=; b=Tcf6KXTW19ZlLQwg7mkILEqLmYpAbl17YgANsC8AH9VBOsyETqUigeDJu8FyNPQ55XbDw8CULZakcqqDjb/QGwCRRmDJw2fAzP/bkp/DAWGwms1vjhtBO8U+NEUojJVEQc+29ZevO+0Kks9FQ2oMYf0EOhOJ0UJbzPWms0IzCsldHlGbcoKanin7/7qU6av80VqWaGgSrjKc2z+NrT6tQJFA7oSWttMFbFvGuGc5yKGsPvF06xlUn9JoRei5+ZWJr2Tz7HliRvzmAlFZ1IJ2FmoMf9E6A5jYe9j8lrfbUmJyduTDDanKQh3w9m/rP8/dz5CC5eeSnOQQzCKhVk9SAQ== 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=YJSKWlatYWLBz+jZN7/O6d3gx2Ck2wdZ4ueX3ZXgvIM=; b=sDsPQE1QUZA3wHuTBm55bSYBix9FZjFoiF5kMTAea/YZZvzKzAJ5E9s9du3IFzwZb6kWT08PtjHG74HQoYzw9lgWZjEPO74xDZgX8RVhvZzz2h3xGMGHN/FH/d0cB/3S+fCHeGX3iWkiHnJBROS3hCfG6T41wElg0VeFCDRpDws= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by BN0PR10MB4919.namprd10.prod.outlook.com (2603:10b6:408:129::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.18; Wed, 29 Jan 2025 18:16:55 +0000 Received: from MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348]) by MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348%3]) with mapi id 15.20.8398.014; Wed, 29 Jan 2025 18:16:55 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] mm: completely abstract unnecessary adj_start calculation Date: Wed, 29 Jan 2025 18:16:39 +0000 Message-ID: <9f87c3bbcc1ee6714a94b5bfa593ea667958ed03.1738172812.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0524.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2c5::9) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|BN0PR10MB4919:EE_ X-MS-Office365-Filtering-Correlation-Id: 27ef871f-bb49-49aa-dd61-08dd40911cee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: Tmo5Tn/UXh9M2sYyJ6rwOjzaO3NDA4+ZFT4XUiG/wMldxKfVloyuysjZ5TRCqx3SxdY+mHIF6h5zPjlZD9BQ4AoUAjMLtooXMxJTlINRSrgZaaaxELjt14PkwT/P5euHMbnb3FvBg2ZCqUueDK9tMDuENtzI6FvCd4jIjoOp/8PaA28eKoSGSVxw7/RjR66ZRDA7NHvIArq1MptyT2auQQMR2/uM6L1rRS3NomCHdpWyWBE4CJ265gE7SPsBRvshLXdr0c0TLZRCSFYfFNfS4p4lx4JKhTKL2bjv9VaV+NHnKo5ne+rJA0i2qY+NEMM15dHEx5tYgiddGSIBaWmhdbTQ+AcxoU/+kwEO4dH6HGwzGNn5+2EhDiyVYYSD6n9KdZ744nvgHcDd1TfY8PVMJCltDY6jt9JEiqcKSDUFx3BILEDct6Wf16sYiCH8mCfmpTOtdGkQLWDg0/M+9ep5ofPZP1PIBnAk8rQrJdC56AaZC0QDBgu34h7+4g/OM8JkOIF8VduLcj8LITiiObdxijqWx34n3eSZKzwF8Tt0km1lEGyF7PXQU38/MsVKIpDV09UEqP7HOFPBbK76rMN2G/mYFck+Vdoj8oJW+tzjRCiFZWVwt6UpLOsB6GKLpb+ml8WyYCeahz+aEGOdcqczV3uI53HyvZRI9FiC2SECM4U3aauAJUbifewgNaCdw4agscZp45iEf+zEB6hf487Zc6XYK5R4Zk22KLwEbqRdLRYK6Jx5Lo5Uu5UbrZLCmMXnW/A/fa1CE9rHRVfEnZsxApQrzrRVf5Q/Z56LeHk+3KGF1TxNqat/ipp5g4asJIBBuAPBEG6MCYzB2NGG0USkeAbKKRhREf+NFj+syqzlP3U+xK9ou8FCUzK0JRfL3JYpc/LA++LMwtjjWVgJG5r4mOeU+5tkM5NYFRx2hoJlWoHCOqGBCl6ZDO5nnhURTGuGmGDXoWHbKe5BWXf4EhIDE4qEPRVMq9boiMs9Yqf9KDkMHkqApOCsjlnMCBQgugU0/QTXPTRTcO2982xjzcfXTXZhN1odSPf4/xk+IhmE2CbEl6Wownzyi39wZ7IRPEx+TrLZKonelOVOcnG++vJmSb8NyzZ0wHEOqKP+hpbEfPPYoj3jaZnBVcl3qiLjxTtvFetGhh0/4J86IdzbtLzfiSGUFdU51KFuM5FdvTORmSzkYQEOfskll94ikeVLg8inLbWEEDbNnE7wp9AgK42WEV23FU1YbBoT4FbZoq35vDxTZThNqT1X8pHQ3AVK9bHaXgl9EEIqp3dtl4HVoGJQc6n7Tx7+D1sfpHCXL7XEcGOqV4w0jm/gQRgR7xQgpuZqoOp/84xfBn0PBJnM/TWiUworn/7mp1+acsQevOp6bLLi4Vyiv7YH6OPDYiGPqQry X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB3374.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PXVL2L1FwZK1zMhaHT4lK5PKQPdPtx/AKp6iznCbVJl6Nf7RCFmIdvh/NYaMogmkrHIWf8wWJpxL84EsdN0pdbehdS24ynb44+iq/i2CfHQmHkcWrOogqePkWwMk/qck/QsmaKQG6BfmL1UOzaYhazr8YBxbmV1FaHnjVAQcPOypMr0c42KLp1CGqqi2BEDeSSfINoYp60u9W9Mf66L3GHiI7UMBkyy50C5Xe4EJma8sS+dqVKTEvrxYmEhZMHgjUhlCw+gJAld71ZdiMClJaOZwYOLf9HVBqMMkFRcuLxCY4F9N9KXvZgKJ7ewqS2qW4u1Rw9EEkXUmNGo9NplE4SgI9dh0CujHPkOdJ1qdRIiyre1bD8Whauf0m2ide4C7PW+MkU5TrZHLgL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HrXqaaQEaMJ5kgd8Drc3YcMB+V5xSmWw3qQsI1B/Ix6QWVAzSaVUizp39s6FG+eynNxlAwP4qwqQKseru2v+SpSnldrViUhiUANzSYq4rtHTR2OC9V0hQ5MC5A1sVE8IyA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: EqYdcUo+6BJAEgrfmR5Wt6LtOHOx4I45LORQCeCS/bId9YjHeGlzIOv9FSEL9YqjtFHHmMCnXcuT3gCZKc04lbP8+x7RaYXUnji0O1fn/GpBXuUxl9xUAS8oQpyzt0EhFF2RB0QSqYCF17upLc1ySgmoWjcSe1egNF5HZ2vFMiIGW4zJQNClfBAbf1VUj37jX8x2/y00AVdjDtAX/24E+aQY8aer+CIvhJrTCPuquLr54lAR9QAc5peeV+BKyOq45nyShr3pNy1P6HFsx6qZyO3tkYvtqRgEny0GneWvAZ0ocjOrCMc5wc/sI8qqQg3RUoLJnSKlzM10JGHxEOkoGcXrjXhSz1mF+Hi9gJXsez+EYuWh3Aes8G5a/mA3T1MDzgpZN7vWrVJA4Yle875YrqjMS3Jf6R1f1zrzqf7LRoDMd/nDC02imBOhT7n1zZ056GFZhXAPTfmzp2B4DMmgzDBPISPoAf9QCfzku+agyEUPPyiPSCIBXunQQ6x7ktCdnF1HZl83HCHT+s4EIjEq1rrBsbWh73TSB/AUaM/1ELu/J7KMZ6Dfd4Y0DQOINOIkEzYjPja1/f+kFs7as7CbNN7EU0eC+dcK/o3Nu5nHZ3A= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27ef871f-bb49-49aa-dd61-08dd40911cee X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2025 18:16:55.8539 (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: BJughdbP89743OUF7IHnfQoyoCWzdIdMtYBGWLd6UX/ApeZe5KPNUrtHNwZ1Up81pDn4JsXuBDorwfnQWIg+o1e+1uiwJNbFojmpUCfa054= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB4919 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-29_03,2025-01-29_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501290143 X-Proofpoint-GUID: nSyN8DRMfhDOOnlh0lMw3soeOSZ77E4r X-Proofpoint-ORIG-GUID: nSyN8DRMfhDOOnlh0lMw3soeOSZ77E4r X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1FCE520016 X-Stat-Signature: zj9yj4xunf1fkyh4sic1xm31cumz95xw X-HE-Tag: 1738175525-256128 X-HE-Meta: U2FsdGVkX1+mo2HtivCPRD6CgAizyLNzDk1UAtbGau/dtme3o/arTpiFa9cgE7qD/X7SrCRaknqflmEri8sHruL90V6OR3kYdX+oNvr95q37f5bRnqBD0poDBJRb03sguBC81Rz9MZKbQ5/aTK7TULz9qbkD3DvCTZT/CHwfa7YVQzeTqTR1Oc15PGQgIo81ogRRUOL4qIE1ebAAhqEQEsffRPGsjKhXezS7bXhYHIRN+DwOhkoguFUg219gDa83uM6sADC0CrGwX6qrcoFZbDDZXMN4OzTcZuVsAabSzSqViK9Co5TAp/Wv+V7HeXb+TDtkiA+zOGL6crdLi1qoEHzKG2FgcxdsucIRS22BvuxzOI3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cFSMAgt7GVUPEFnILsbBO0EAnfrGeQcNojo+Q/9gxLtQq1khdWtsdtW5l7lk/urwYP9M1zHZH9kKosDdvp9NZAHQfbk7kRX478z4XRKdf0osbHRuaIzjeQZneaT/Ft40I/sx0HtOQ9AJrMU0mJV65VolEx1nbAsaFNoUMa9/ 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: The adj_start calculation has been a constant source of confusion in the VMA merge code. There are two cases to consider, one where we adjust the start of the vmg->middle VMA (i.e. the vmg->__adjust_middle_start merge flag is set), in which case adj_start is calculated as: (1) adj_start = vmg->end - vmg->middle->vm_start And the case where we adjust the start of the vmg->next VMA (i.e. the vmg->__adjust_next_start merge flag is set), in which case adj_start is calculated as: (2) adj_start = -(vmg->middle->vm_end - vmg->end) We apply (1) thusly: vmg->middle->vm_start = vmg->middle->vm_start + vmg->end - vmg->middle->vm_start Which simplifies to: vmg->middle->vm_start = vmg->end Similarly, we apply (2) as: vmg->next->vm_start = vmg->next->vm_start + -(vmg->middle->vm_end - vmg->end) Noting that for these VMAs to be mergeable vmg->middle->vm_end == vmg->next->vm_start and so this simplifies to: vmg->next->vm_start = vmg->next->vm_start + -(vmg->next->vm_start - vmg->end) Which simplifies to: vmg->next->vm_start = vmg->end Therefore in each case, we simply need to adjust the start of the VMA to vmg->end (!) and can do away with this adj_start calculation. The only caveat is that we must ensure we update the vm_pgoff field correctly. We therefore abstract this entire calculation to a new function vmg_adjust_set_range() which performs this calculation and sets the adjusted VMA's new range using the general vma_set_range() function. We also must update vma_adjust_trans_huge() which expects the now-abstracted adj_start parameter. It turns out this is wholly unnecessary. In vma_adjust_trans_huge() the relevant code is: if (adjust_next > 0) { struct vm_area_struct *next = find_vma(vma->vm_mm, vma->vm_end); unsigned long nstart = next->vm_start; nstart += adjust_next; split_huge_pmd_if_needed(next, nstart); } The only case where this is relevant is when vmg->__adjust_middle_start is specified (in which case adj_next would have been positive), i.e. the one in which the vma specified is vmg->prev and this the sought 'next' VMA would be vmg->middle. We can therefore eliminate the find_vma() invocation altogether and simply provide the vmg->middle VMA in this instance, or NULL otherwise. Again we have an adj_next offset calculation: next->vm_start + vmg->end - vmg->middle->vm_start Where next == vmg->middle this simplifies to vmg->end as previously demonstrated. Therefore nstart is equal to vmg->end, which is already passed to vma_adjust_trans_huge() via the 'end' parameter and so this code (rather delightfully) simplifies to: if (next) split_huge_pmd_if_needed(next, end); With these changes in place, it becomes silly for commit_merge() to return vmg->target, as it is always the same and threaded through vmg, so we finally change commit_merge() to return an error value once again. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- include/linux/huge_mm.h | 4 +- mm/huge_memory.c | 19 ++---- mm/vma.c | 99 +++++++++++++++----------------- tools/testing/vma/vma_internal.h | 4 +- 4 files changed, 57 insertions(+), 69 deletions(-) -- 2.48.1 diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 93e509b6c00e..e1bea54820ff 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -404,7 +404,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, unsigned long start, unsigned long end); void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start, - unsigned long end, long adjust_next); + unsigned long end, struct vm_area_struct *next); spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma); spinlock_t *__pud_trans_huge_lock(pud_t *pud, struct vm_area_struct *vma); @@ -571,7 +571,7 @@ static inline int madvise_collapse(struct vm_area_struct *vma, static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start, unsigned long end, - long adjust_next) + struct vm_area_struct *next) { } static inline int is_swap_pmd(pmd_t pmd) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8d21218dc740..de72713b1c45 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3017,9 +3017,9 @@ static inline void split_huge_pmd_if_needed(struct vm_area_struct *vma, unsigned } void vma_adjust_trans_huge(struct vm_area_struct *vma, - unsigned long start, - unsigned long end, - long adjust_next) + unsigned long start, + unsigned long end, + struct vm_area_struct *next) { /* Check if we need to split start first. */ split_huge_pmd_if_needed(vma, start); @@ -3027,16 +3027,9 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma, /* Check if we need to split end next. */ split_huge_pmd_if_needed(vma, end); - /* - * If we're also updating the next vma vm_start, - * check if we need to split it. - */ - if (adjust_next > 0) { - struct vm_area_struct *next = find_vma(vma->vm_mm, vma->vm_end); - unsigned long nstart = next->vm_start; - nstart += adjust_next; - split_huge_pmd_if_needed(next, nstart); - } + /* If we're incrementing next->vm_start, we might need to split it. */ + if (next) + split_huge_pmd_if_needed(next, end); } static void unmap_folio(struct folio *folio) diff --git a/mm/vma.c b/mm/vma.c index 75bbe82b2e65..39146c19f316 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -513,7 +513,7 @@ __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, init_vma_prep(&vp, vma); vp.insert = new; vma_prepare(&vp); - vma_adjust_trans_huge(vma, vma->vm_start, addr, 0); + vma_adjust_trans_huge(vma, vma->vm_start, addr, NULL); if (new_below) { vma->vm_start = addr; @@ -644,46 +644,44 @@ void validate_mm(struct mm_struct *mm) #endif /* CONFIG_DEBUG_VM_MAPLE_TREE */ /* - * Actually perform the VMA merge operation. - * - * On success, returns the merged VMA. Otherwise returns NULL. + * Based on the vmg flag indicating whether we need to adjust the vm_start field + * for the middle or next VMA, we calculate what the range of the newly adjusted + * VMA ought to be, and set the VMA's range accordingly. */ -static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) +static void vmg_adjust_set_range(struct vma_merge_struct *vmg) { - struct vm_area_struct *vma; - struct vma_prepare vp; struct vm_area_struct *adjust; - long adj_start; + pgoff_t pgoff; - /* - * If modifying an existing VMA and we don't remove vmg->middle, then we - * shrink the adjacent VMA. - */ if (vmg->__adjust_middle_start) { - vma = vmg->target; adjust = vmg->middle; - /* The POSITIVE value by which we offset vmg->middle->vm_start. */ - adj_start = vmg->end - vmg->middle->vm_start; - - /* Note: vma iterator must be pointing to 'start'. */ - vma_iter_config(vmg->vmi, vmg->start, vmg->end); + pgoff = adjust->vm_pgoff + PHYS_PFN(vmg->end - adjust->vm_start); } else if (vmg->__adjust_next_start) { - /* - * In this case alone, the VMA we manipulate is vmg->middle, but - * we ultimately return vmg->next. - */ - vma = vmg->middle; adjust = vmg->next; - /* The NEGATIVE value by which we offset vmg->next->vm_start. */ - adj_start = -(vmg->middle->vm_end - vmg->end); + pgoff = adjust->vm_pgoff - PHYS_PFN(adjust->vm_start - vmg->end); + } else { + return; + } + + vma_set_range(adjust, vmg->end, adjust->vm_end, pgoff); +} + +/* + * Actually perform the VMA merge operation. + * + * Returns 0 on success, or an error value on failure. + */ +static int commit_merge(struct vma_merge_struct *vmg) +{ + struct vm_area_struct *vma; + struct vma_prepare vp; - vma_iter_config(vmg->vmi, vmg->next->vm_start + adj_start, - vmg->next->vm_end); + if (vmg->__adjust_next_start) { + /* We manipulate middle and adjust next, which is the target. */ + vma = vmg->middle; + vma_iter_config(vmg->vmi, vmg->end, vmg->next->vm_end); } else { vma = vmg->target; - adjust = NULL; - adj_start = 0; - /* Note: vma iterator must be pointing to 'start'. */ vma_iter_config(vmg->vmi, vmg->start, vmg->end); } @@ -691,22 +689,22 @@ static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) init_multi_vma_prep(&vp, vma, vmg); if (vma_iter_prealloc(vmg->vmi, vma)) - return NULL; + return -ENOMEM; vma_prepare(&vp); - vma_adjust_trans_huge(vma, vmg->start, vmg->end, adj_start); + /* + * THP pages may need to do additional splits if we increase + * middle->vm_start. + */ + vma_adjust_trans_huge(vma, vmg->start, vmg->end, + vmg->__adjust_middle_start ? vmg->middle : NULL); vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff); - - if (adj_start) { - adjust->vm_start += adj_start; - adjust->vm_pgoff += PHYS_PFN(adj_start); - } - + vmg_adjust_set_range(vmg); vma_iter_store(vmg->vmi, vmg->target); vma_complete(&vp, vmg->vmi, vma->vm_mm); - return vmg->target; + return 0; } /* We can only remove VMAs when merging if they do not have a close hook. */ @@ -749,7 +747,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( { struct vm_area_struct *middle = vmg->middle; struct vm_area_struct *prev = vmg->prev; - struct vm_area_struct *next, *res; + struct vm_area_struct *next; struct vm_area_struct *anon_dup = NULL; unsigned long start = vmg->start; unsigned long end = vmg->end; @@ -900,12 +898,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->end = next->vm_end; vmg->pgoff = next->vm_pgoff - pglen; } else { - /* - * We shrink middle and expand next. - * - * IMPORTANT: This is the ONLY case where the final - * merged VMA is NOT vmg->target, but rather vmg->next. - */ + /* We shrink middle and expand next. */ vmg->__adjust_next_start = true; vmg->start = middle->vm_start; vmg->end = start; @@ -918,8 +911,10 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (err) goto abort; - res = commit_merge(vmg); - if (!res) { + err = commit_merge(vmg); + if (err) { + VM_WARN_ON(err != -ENOMEM); + if (anon_dup) unlink_anon_vmas(anon_dup); @@ -927,9 +922,9 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( return NULL; } - khugepaged_enter_vma(res, vmg->flags); + khugepaged_enter_vma(vmg->target, vmg->flags); vmg->state = VMA_MERGE_SUCCESS; - return res; + return vmg->target; abort: vma_iter_set(vmg->vmi, start); @@ -1092,7 +1087,7 @@ int vma_expand(struct vma_merge_struct *vmg) if (remove_next) vmg->__remove_next = true; - if (!commit_merge(vmg)) + if (commit_merge(vmg)) goto nomem; return 0; @@ -1132,7 +1127,7 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, init_vma_prep(&vp, vma); vma_prepare(&vp); - vma_adjust_trans_huge(vma, start, end, 0); + vma_adjust_trans_huge(vma, start, end, NULL); vma_iter_clear(vmi); vma_set_range(vma, start, end, pgoff); diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index 1eae23039854..bb273927af0f 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -796,12 +796,12 @@ static inline void vma_start_write(struct vm_area_struct *vma) static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start, unsigned long end, - long adjust_next) + struct vm_area_struct *next) { (void)vma; (void)start; (void)end; - (void)adjust_next; + (void)next; } static inline void vma_iter_free(struct vma_iterator *vmi)