From patchwork Wed Jan 29 18:16:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13954041 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 C24ACC0218F for ; Wed, 29 Jan 2025 18:24:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E237280083; Wed, 29 Jan 2025 13:24:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 391EE280082; Wed, 29 Jan 2025 13:24:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BD86280083; Wed, 29 Jan 2025 13:24:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EA5A4280082 for ; Wed, 29 Jan 2025 13:24:54 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 54EC5C01B7 for ; Wed, 29 Jan 2025 18:24:54 +0000 (UTC) X-FDA: 83061315708.05.82B6994 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf21.hostedemail.com (Postfix) with ESMTP id BAC071C000B for ; Wed, 29 Jan 2025 18:24:50 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="bOJ3UOF/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vm1nA8iy; spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738175091; 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=DilCm9XBnp8XWMupCy+6NTrWjbHp0vBZ4/BrXG1qvEo=; b=CkLCrNwQQtvxPEeiAaQvxp2X1STQ9GiuT1/ASFW2PdhaW0EDLnxYdckAk8eZ0NyIRPGw/r xft292/bWTqqTQDzbyft+MiFTD99UFM4CKDQyWYkMNacJF3fob3b9nsSrE7iW1TOZGGJMO ATaIqCM+jZGJc53y0T10PMxm967E3hk= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="bOJ3UOF/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vm1nA8iy; spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1738175091; a=rsa-sha256; cv=pass; b=SrMujHvKiMr1QQqAPki16pG1RYewsJ94howXiTaYvnZK/cI4hJQYG/MISG+1a+FYyw7UKD C4rDX2z9jmXGlqc58RMIx2EPtnEd7ubJya6zzB9zZEPMBBkgiYOM9u26++u7PYtUzI7XUQ I7Jr0iUBMTtemj+WOsoX7ABI1e8Ua+w= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50THYtm0016128; Wed, 29 Jan 2025 18:24:48 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=DilCm9XBnp8XWMupCy+6NTrWjbHp0vBZ4/BrXG1qvEo=; b= bOJ3UOF/ozlIxRQUoF3UaUlAYLfrUnhvjQG6xNyODkPqI+jphWmStM168RzyJ2oZ lqxnfEKsrb+R2VYlcKlFRcP0LarsESiCA0ROHF4grTfMXRFAEXIXycXi6FV1dr/I nvAIo0Uk63YnVA1TuWZSXv/sPaQnjY7rsSInLtPK/tgbB4DwAtripUcFpUMj9LiW C4fl5t0SnGIFAwsJDWI1/4Uu4HmaxRuqfCZRxb7moezdN5MSh6SiqKP6RMngYhh8 c+PLIBiryQMANpCTqlSdajXnpxhDQF9nG94j5Ygo9PDMCuDKI4LCrVEoET44opfO Bcc8uoWj2qG6pRjS0tMQKw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44frus04sf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:24:47 +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 50THE7h2036170; Wed, 29 Jan 2025 18:16:50 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44cpda2s9d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:16:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fVyFBderEedWM6tzFyKhJwiTjEq6Y7N+JQJBXFzP3sR2tkCbis9QKDo+qEO/bUe9oHn2e7Rc/JnCa73Oowv3vqFurmXkdTHHoLGdADQFmZhJH8br8WuWKxfdYIYRSJwRRzGNrKETkxOFa0FYQu4jy4wqRlvD1Xu5HKtHlulhIYAFhuDB5dcafBsr8pq+M17jbwk2EXaQhzyLAP9Pw0DAnOFddKfKXMfLkxbRMCih6OeUJDoDBP07eVkVPFnTRUzhN+itPEzO0k4eXUXUm3khDnvJuiR7reNhzz2EeFcUmmU/F0RXN7rthE6mOSAiVws666oprux8d5CcO1fKbXaxBA== 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=DilCm9XBnp8XWMupCy+6NTrWjbHp0vBZ4/BrXG1qvEo=; b=pKIXRsC7sDeLtdaqUGt++9+lWq2iFoul5xNWY9qLOFV09VbsMC6CEV4aAoFT3xHg54vir2lSB/4wf1mFY+QmwEESKrl8FfK5hP5Rqgb+8VJQdmIMgj34UsHR/oDF9btsBTFYK09exSq6rjny7VWwM1XASAtxe+vEQvGdjxNT45aG2TXUCEdk+8C3PuBRyq70MhCy64YKBFWKYnDy+pIUiHGltgbNh29ZWeLNQEK8Mo+fmPMjRWtwVhfYerBKWx1tKUggblbvUFiHiDI5p7fiuwlxbPY46VXlCIX+Ozi5ajP0QdS+kHabszGlaKEJEfOzri4WStb4XJoF8vFaUpAiHA== 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=DilCm9XBnp8XWMupCy+6NTrWjbHp0vBZ4/BrXG1qvEo=; b=vm1nA8iyUyWJymJEarYmZaRzE3C9pQg1kw+cuGpzesfVzvsNoD2xD5KBdU5fGrj08MkBefNmBwOCC2qzpL2A125OazoK9jPKlwfl2ywaOdS3YzPjKExljYB0qZObNPigMCtZAV/JUNLMTiHctR1Qvt6xRf9N9n5aHnBJoiry3LY= 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:46 +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:46 +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 1/5] mm: simplify vma merge structure and expand comments Date: Wed, 29 Jan 2025 18:16:35 +0000 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: X-ClientProxiedBy: LNXP265CA0069.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::33) 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: 6f5a0b02-b9a2-4b4d-6e24-08dd40911779 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: wEHJAREt22LW4YtkxQLplyj3VHuh1JHyvKF5R5jB+5zOdKRPXtEY/YipyY+DOY5QbOGVjYlJdssrRsJnUjTBJAv9484kHDSrs51LAt9lxMobxWTjiW/kEeB07gMKt9H6oajZhUru4C5L6BB9BAt0SVKd1oxT8s5RO9fsbvPQ2BoiGG9NAwtMGw4+gvKmdTlypWsnk9Y1p/ve/ZEQSbjmYscL8suIFbqYKtVaGVipmL+ve0DCR4EcUFoQJSmUWsjnnot5uSqyCVWUpzvn6w4RIIvOEgiSjmmqpMzwL64yqEK4gh/1vME32e9VCqAvqOvtF6GtXWZWhnGzxFG9QCsc/fqstHGlu5JPsXVjIvkBpijgXHPntIgMpOy1zDnBeTfefJcaOG/q8uuZsCBWK9WIgyIzTZX1v2MScch8X/d3+GxGncjVp/DWlqdNez0/fVPH8MMLftRhHQhsmf9TNlnROnns8e6JpgXChNtu9lcoEEnkP3zf+iG55ArhXvsp5I1maK+BGJ9MJ+VjNOPD9RmpCUOpnKKIl6ltd36l9kczhUyj4/cq51EWIlmqSR10Aog5MU1e0Wff68L8HW5QekvDXhfK0ShCDCczUl8qQwK82Gy5cLkrqvQ5o2So5xOcg1SAp7GOGVowfFgWNU5wY1G5CeSFgJWn4VqEOkDEuR5JHb6K7HNS7QnD41KcdjPW/9gcdh7QXhgvYb0nnEDMOH0ttR/HCYVZmYMEFHCB/dJKRKFEM06uXB99F+tFpZCtQALvCcro6ozm0wNBf4ZTzvWjgkF2vNGu4hjdAET2PJgPPddMx8JrMoLgMk36gGCt0+dcbgxL3LgsDSdoS9xpUXMXTHnftBoASFjzn+mhuurVsFAmOEqGFz+jxh1RBhD+823JmuFbvR4oym4jIhSS5EiaiaVryH5e3oWnD38nCsJyxBzWd44+2gLM+tx3JLrzusTjAolxi4lV+hFcYgpK3kWoQ3KIveVwta8XYRJ81DYe7EI/dTkxWkpmY78Jv8tn2Pv32+i6AecXqFqwBNzNkIVEQUHZscQxMNRohP6N4u2H9tRl7pdDUVsWKicWYeAD6ikBNQ54HGLOL0fJptu6rjdxAgguMxJqMQzVO0nowu+10x4iuh+xa4Mih2BaseO9EsRzmDN/5WHnPuBIwvP9d0QtLlty3WTKvxBQLtrUwqBfIuK23VjgVL9B4i2GUVCxHzbxddroRJ9iNw+GAf2GAIh8KOvEiOb1ED2qAYAvleb123J59fu8DnC17z1jglnCJDq3YbHguDOuT/6DCvJJPpRQSQ0dueWevC+y+aOA7C/CEdTACpzrRgwQE3kuFQiLV9v2AcZZimuKJLWq9PsNukCxem3FvR0OmEsGSgPtwOQGltHHrLuMDStHWRlqTA5Ykv8A 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: BvHvVGYmzsB9mofyzfEz6CXjY24K3lK6MiRg/JFmnzwkq1KSBjMOlGyfOVKQnUpL112OFyNTIK8mw4XJldc/RJ98qSaUOvYWizK8sq2V6+eHbpk5E9ZQRPS3EUnuAmZVmKVZUgjIovU5bkb3W+5gdsRF8JdlsaZhyI/tbCbTKM2LACgD3Kq/3fakcyNqXJ9m6gA7gF2PmQB6Xe+6VB0STXInGH+/aSA0MGs3kekn3U/bDSxdMWa2CuUBtC/MXtaHz38SfVw6Nx7r4lywDLO27rWfA00WleAdhY3qqPHENq0pc4JZibhg4D/LlaaOCUcZqv5lf8prd2/P352uX8If9w9MTAJoTiPmpZwRYUvqXi9FoQucdpeuLqpbfuo7YreyvXULZIEj07oJcf1kKJdSjLhGR5b7FYLcUnlRTMitE31Q9HCDJrOou9EyvYHEQnk7YBBq/BYEM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6h4JMls/K+hK+x6yC8fjsJEgkrPTskCg6Tu/UBejO9byX42tP9QiaY8BCfb5ywO15H+oxQE4JhbVmiHannv1g== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 0/NZGeml3UfpCdkAYFNwEkW2gsXwcc4kt0UpdGKiH46jZ3HqhP0fGV4RutavWTk7tehvFHdLqXCidiEYxqHbMjBKeZs5HIcz8d1Y2k+ajIIY8IQhHvRkw3s9Ofwd3pDwis0cQj73CoqU2oDdW8dB8P6ETDeNx2sMKnof9U/PYqKypmqF78at786TuW9Itsy2j1ZtN2O9LsQYoj4O+3WvDLCzfR7n92mMNkHMAviqWDF+Kl3k7sD6L4VUaAseBmjJnW6zVi+2aM5bJm8FTmY3+DmLEcnpEsgn9Og5Xa9FEqT7PwiZQs2c/a75vCbYiJbiLGZW6QX2cdRRIkKqqdx1t0IKrwTDZzs86AsQLb393mj0Efx4ALxWmktDeP+inVZM3iXOPHjOOsWkTfQhar3uPLsOukv3Wjw8bbDG56YF9N8xBMhV/Nax8/UrB53CznS93/l4vklle++y3RHpXSxSF2tuW4+P13a9Df0T/RjpfuJczyg4hj5QsOvQ2rPHuVQ0/qPw0SmMBqy2ES3sAr7rdaPLHQTY3xlGtgfIE8vWVBJzoNusiA/hv96rltoiVxilsYWX7TDRbuFoF8dFIfTypL5k0qd2+FlQWvknEq4m93o= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f5a0b02-b9a2-4b4d-6e24-08dd40911779 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:46.8404 (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: asgHDZu1vBBQlhXqKTGbWzz/A2H/02g3mhC/vgJjhImP/aXZ7HfBpp67oZF8LjxwZ4UeMnKrm2Va2W8nTaq4t/StlQz0DB7iLshIPam6nhc= 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: bCSSXDRnesgWi9riYY-AJnK5onjOO6Jp X-Proofpoint-ORIG-GUID: bCSSXDRnesgWi9riYY-AJnK5onjOO6Jp X-Rspamd-Queue-Id: BAC071C000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 65gmc79wsush89rnrfif3dtcwz3br1ie X-HE-Tag: 1738175090-613961 X-HE-Meta: U2FsdGVkX180DMgPd9n2iONiMmEilwweSVKRbMa7hQK/AyBx6vwMq8UXHqfWRNSueyRxBEhJOFfqaY2sspzHXGwKOPcsgndb+qAH4GCARZ7S8u6eOGkiLlnPFscvwEv5SUQzp/DEgXtu17U74DiyqY+q2LE/RZvAFYjfJrhR7TWQABptsuuKR+FpgmzA3aEqzhYG7aScLBpzAe8YODNAwlpvwhRnDeMO8AVJ9DsvFMdkHp5h/pnPKmAnO3jIMKsYsdG8Gd0wj1o9SUdjL8J4D31v3TFuhAXA8NvudR/D3VlRdqRICU47dJ+JcjAMp2vDXxIkphRJsbf1o+JlD9AAP3nOUB9jC4VKYbnPKjBZoL81dfS+vtTVBb+ZtFDFUBdVj/7C/RzGmVqBR+E/4azZe1b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Ac1ITOeUNCJNQsgd7Cj1FARsISXgxaDwdWDr1kth2RucMPuFlA2RO/pSyI27TK51ZJc+Reqt0pQ== 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 merge code, while much improved, still has a number of points of confusion. As part of a broader series cleaning this up to make this more maintainable, we start by addressing some confusion around vma_merge_struct fields. So far, the caller either provides no vmg->vma (a new VMA) or supplies the existing VMA which is being altered, setting vmg->start,end,pgoff to the proposed VMA dimensions. vmg->vma is then updated, as are vmg->start,end,pgoff as the merge process proceeds and the appropriate merge strategy is determined. This is rather confusing, as vmg->vma starts off as the 'middle' VMA between vmg->prev,next, but becomes the 'target' VMA, except in one specific edge case (merge next, shrink middle). Int his patch we introduce vmg->middle to describe the VMA that is between vmg->prev and vmg->next, and does NOT change during the merge operation. We replace vmg->vma with vmg->target, and use this only during the merge operation itself. Aside from the merge right, shrink middle case, this becomes the VMA that forms the basis of the VMA that is returned. This edge case can be addressed in a future commit. We also add a number of comments to explain what is going on. Finally, we adjust the ASCII diagrams showing each merge case in vma_merge_existing_range() to be clearer - the arrow range previously showed the vmg->start, end spanned area, but it is clearer to change this to show the final merged VMA. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/debug.c | 18 ++--- mm/mmap.c | 2 +- mm/vma.c | 166 +++++++++++++++++++++------------------- mm/vma.h | 42 ++++++++-- tools/testing/vma/vma.c | 52 ++++++------- 5 files changed, 159 insertions(+), 121 deletions(-) diff --git a/mm/debug.c b/mm/debug.c index 8d2acf432385..c9e07651677b 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -261,7 +261,7 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) pr_warn("vmg %px state: mm %px pgoff %lx\n" "vmi %px [%lx,%lx)\n" - "prev %px next %px vma %px\n" + "prev %px middle %px next %px target %px\n" "start %lx end %lx flags %lx\n" "file %px anon_vma %px policy %px\n" "uffd_ctx %px\n" @@ -270,7 +270,7 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) vmg, vmg->mm, vmg->pgoff, vmg->vmi, vmg->vmi ? vma_iter_addr(vmg->vmi) : 0, vmg->vmi ? vma_iter_end(vmg->vmi) : 0, - vmg->prev, vmg->next, vmg->vma, + vmg->prev, vmg->middle, vmg->next, vmg->target, vmg->start, vmg->end, vmg->flags, vmg->file, vmg->anon_vma, vmg->policy, #ifdef CONFIG_USERFAULTFD @@ -288,13 +288,6 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) pr_warn("vmg %px mm: (NULL)\n", vmg); } - if (vmg->vma) { - pr_warn("vmg %px vma:\n", vmg); - dump_vma(vmg->vma); - } else { - pr_warn("vmg %px vma: (NULL)\n", vmg); - } - if (vmg->prev) { pr_warn("vmg %px prev:\n", vmg); dump_vma(vmg->prev); @@ -302,6 +295,13 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) pr_warn("vmg %px prev: (NULL)\n", vmg); } + if (vmg->middle) { + pr_warn("vmg %px middle:\n", vmg); + dump_vma(vmg->middle); + } else { + pr_warn("vmg %px middle: (NULL)\n", vmg); + } + if (vmg->next) { pr_warn("vmg %px next:\n", vmg); dump_vma(vmg->next); diff --git a/mm/mmap.c b/mm/mmap.c index cda01071c7b1..6401a1d73f4a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1707,7 +1707,7 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) /* * cover the whole range: [new_start, old_end) */ - vmg.vma = vma; + vmg.middle = vma; if (vma_expand(&vmg)) return -ENOMEM; diff --git a/mm/vma.c b/mm/vma.c index af1d549b179c..68a301a76297 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -52,7 +52,7 @@ struct mmap_state { .pgoff = (map_)->pgoff, \ .file = (map_)->file, \ .prev = (map_)->prev, \ - .vma = vma_, \ + .middle = vma_, \ .next = (vma_) ? NULL : (map_)->next, \ .state = VMA_MERGE_START, \ .merge_flags = VMG_FLAG_DEFAULT, \ @@ -639,7 +639,7 @@ static int commit_merge(struct vma_merge_struct *vmg, { struct vma_prepare vp; - init_multi_vma_prep(&vp, vmg->vma, adjust, remove, remove2); + init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && vp.anon_vma != adjust->anon_vma); @@ -652,15 +652,15 @@ static int commit_merge(struct vma_merge_struct *vmg, adjust->vm_end); } - if (vma_iter_prealloc(vmg->vmi, vmg->vma)) + if (vma_iter_prealloc(vmg->vmi, vmg->target)) return -ENOMEM; vma_prepare(&vp); - vma_adjust_trans_huge(vmg->vma, vmg->start, vmg->end, adj_start); - vma_set_range(vmg->vma, vmg->start, vmg->end, vmg->pgoff); + vma_adjust_trans_huge(vmg->target, vmg->start, vmg->end, adj_start); + vma_set_range(vmg->target, vmg->start, vmg->end, vmg->pgoff); if (expanded) - vma_iter_store(vmg->vmi, vmg->vma); + vma_iter_store(vmg->vmi, vmg->target); if (adj_start) { adjust->vm_start += adj_start; @@ -671,7 +671,7 @@ static int commit_merge(struct vma_merge_struct *vmg, } } - vma_complete(&vp, vmg->vmi, vmg->vma->vm_mm); + vma_complete(&vp, vmg->vmi, vmg->target->vm_mm); return 0; } @@ -694,8 +694,9 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma) * identical properties. * * This function checks for the existence of any such mergeable VMAs and updates - * the maple tree describing the @vmg->vma->vm_mm address space to account for - * this, as well as any VMAs shrunk/expanded/deleted as a result of this merge. + * the maple tree describing the @vmg->middle->vm_mm address space to account + * for this, as well as any VMAs shrunk/expanded/deleted as a result of this + * merge. * * As part of this operation, if a merge occurs, the @vmg object will have its * vma, start, end, and pgoff fields modified to execute the merge. Subsequent @@ -704,45 +705,47 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma) * Returns: The merged VMA if merge succeeds, or NULL otherwise. * * ASSUMPTIONS: - * - The caller must assign the VMA to be modifed to @vmg->vma. + * - The caller must assign the VMA to be modifed to @vmg->middle. * - The caller must have set @vmg->prev to the previous VMA, if there is one. * - The caller must not set @vmg->next, as we determine this. * - The caller must hold a WRITE lock on the mm_struct->mmap_lock. - * - vmi must be positioned within [@vmg->vma->vm_start, @vmg->vma->vm_end). + * - vmi must be positioned within [@vmg->middle->vm_start, @vmg->middle->vm_end). */ static __must_check struct vm_area_struct *vma_merge_existing_range( struct vma_merge_struct *vmg) { - struct vm_area_struct *vma = vmg->vma; + struct vm_area_struct *middle = vmg->middle; struct vm_area_struct *prev = vmg->prev; struct vm_area_struct *next, *res; struct vm_area_struct *anon_dup = NULL; struct vm_area_struct *adjust = NULL; unsigned long start = vmg->start; unsigned long end = vmg->end; - bool left_side = vma && start == vma->vm_start; - bool right_side = vma && end == vma->vm_end; + bool left_side = middle && start == middle->vm_start; + bool right_side = middle && end == middle->vm_end; int err = 0; long adj_start = 0; - bool merge_will_delete_vma, merge_will_delete_next; + bool merge_will_delete_middle, merge_will_delete_next; bool merge_left, merge_right, merge_both; bool expanded; mmap_assert_write_locked(vmg->mm); - VM_WARN_ON_VMG(!vma, vmg); /* We are modifying a VMA, so caller must specify. */ + VM_WARN_ON_VMG(!middle, vmg); /* We are modifying a VMA, so caller must specify. */ VM_WARN_ON_VMG(vmg->next, vmg); /* We set this. */ VM_WARN_ON_VMG(prev && start <= prev->vm_start, vmg); VM_WARN_ON_VMG(start >= end, vmg); /* - * If vma == prev, then we are offset into a VMA. Otherwise, if we are + * If middle == prev, then we are offset into a VMA. Otherwise, if we are * not, we must span a portion of the VMA. */ - VM_WARN_ON_VMG(vma && ((vma != prev && vmg->start != vma->vm_start) || - vmg->end > vma->vm_end), vmg); - /* The vmi must be positioned within vmg->vma. */ - VM_WARN_ON_VMG(vma && !(vma_iter_addr(vmg->vmi) >= vma->vm_start && - vma_iter_addr(vmg->vmi) < vma->vm_end), vmg); + VM_WARN_ON_VMG(middle && + ((middle != prev && vmg->start != middle->vm_start) || + vmg->end > middle->vm_end), vmg); + /* The vmi must be positioned within vmg->middle. */ + VM_WARN_ON_VMG(middle && + !(vma_iter_addr(vmg->vmi) >= middle->vm_start && + vma_iter_addr(vmg->vmi) < middle->vm_end), vmg); vmg->state = VMA_MERGE_NOMERGE; @@ -776,13 +779,13 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( merge_both = merge_left && merge_right; /* If we span the entire VMA, a merge implies it will be deleted. */ - merge_will_delete_vma = left_side && right_side; + merge_will_delete_middle = left_side && right_side; /* - * If we need to remove vma in its entirety but are unable to do so, + * If we need to remove middle in its entirety but are unable to do so, * we have no sensible recourse but to abort the merge. */ - if (merge_will_delete_vma && !can_merge_remove_vma(vma)) + if (merge_will_delete_middle && !can_merge_remove_vma(middle)) return NULL; /* @@ -793,7 +796,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* * If we cannot delete next, then we can reduce the operation to merging - * prev and vma (thereby deleting vma). + * prev and middle (thereby deleting middle). */ if (merge_will_delete_next && !can_merge_remove_vma(next)) { merge_will_delete_next = false; @@ -801,8 +804,8 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( merge_both = false; } - /* No matter what happens, we will be adjusting vma. */ - vma_start_write(vma); + /* No matter what happens, we will be adjusting middle. */ + vma_start_write(middle); if (merge_left) vma_start_write(prev); @@ -812,13 +815,13 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (merge_both) { /* - * |<----->| - * |-------*********-------| - * prev vma next - * extend delete delete + * |<-------------------->| + * |-------********-------| + * prev middle next + * extend delete delete */ - vmg->vma = prev; + vmg->target = prev; vmg->start = prev->vm_start; vmg->end = next->vm_end; vmg->pgoff = prev->vm_pgoff; @@ -826,78 +829,79 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* * We already ensured anon_vma compatibility above, so now it's * simply a case of, if prev has no anon_vma object, which of - * next or vma contains the anon_vma we must duplicate. + * next or middle contains the anon_vma we must duplicate. */ - err = dup_anon_vma(prev, next->anon_vma ? next : vma, &anon_dup); + err = dup_anon_vma(prev, next->anon_vma ? next : middle, + &anon_dup); } else if (merge_left) { /* - * |<----->| OR - * |<--------->| + * |<------------>| OR + * |<----------------->| * |-------************* - * prev vma + * prev middle * extend shrink/delete */ - vmg->vma = prev; + vmg->target = prev; vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - if (!merge_will_delete_vma) { - adjust = vma; - adj_start = vmg->end - vma->vm_start; + if (!merge_will_delete_middle) { + adjust = middle; + adj_start = vmg->end - middle->vm_start; } - err = dup_anon_vma(prev, vma, &anon_dup); + err = dup_anon_vma(prev, middle, &anon_dup); } else { /* merge_right */ /* - * |<----->| OR - * |<--------->| + * |<------------->| OR + * |<----------------->| * *************-------| - * vma next + * middle next * shrink/delete extend */ pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start); VM_WARN_ON_VMG(!merge_right, vmg); - /* If we are offset into a VMA, then prev must be vma. */ - VM_WARN_ON_VMG(vmg->start > vma->vm_start && prev && vma != prev, vmg); + /* If we are offset into a VMA, then prev must be middle. */ + VM_WARN_ON_VMG(vmg->start > middle->vm_start && prev && middle != prev, vmg); - if (merge_will_delete_vma) { - vmg->vma = next; + if (merge_will_delete_middle) { + vmg->target = next; vmg->end = next->vm_end; vmg->pgoff = next->vm_pgoff - pglen; } else { /* - * We shrink vma and expand next. + * We shrink middle and expand next. * * IMPORTANT: This is the ONLY case where the final - * merged VMA is NOT vmg->vma, but rather vmg->next. + * merged VMA is NOT vmg->target, but rather vmg->next. */ - - vmg->start = vma->vm_start; + vmg->target = middle; + vmg->start = middle->vm_start; vmg->end = start; - vmg->pgoff = vma->vm_pgoff; + vmg->pgoff = middle->vm_pgoff; adjust = next; - adj_start = -(vma->vm_end - start); + adj_start = -(middle->vm_end - start); } - err = dup_anon_vma(next, vma, &anon_dup); + err = dup_anon_vma(next, middle, &anon_dup); } if (err) goto abort; /* - * In nearly all cases, we expand vmg->vma. There is one exception - + * In nearly all cases, we expand vmg->middle. There is one exception - * merge_right where we partially span the VMA. In this case we shrink - * the end of vmg->vma and adjust the start of vmg->next accordingly. + * the end of vmg->middle and adjust the start of vmg->next accordingly. */ - expanded = !merge_right || merge_will_delete_vma; + expanded = !merge_right || merge_will_delete_middle; if (commit_merge(vmg, adjust, - merge_will_delete_vma ? vma : NULL, + merge_will_delete_middle ? middle : NULL, merge_will_delete_next ? next : NULL, adj_start, expanded)) { if (anon_dup) @@ -973,7 +977,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) bool just_expand = vmg->merge_flags & VMG_FLAG_JUST_EXPAND; mmap_assert_write_locked(vmg->mm); - VM_WARN_ON_VMG(vmg->vma, vmg); + VM_WARN_ON_VMG(vmg->middle, vmg); /* vmi must point at or before the gap. */ VM_WARN_ON_VMG(vma_iter_addr(vmg->vmi) > end, vmg); @@ -989,13 +993,13 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) /* If we can merge with the next VMA, adjust vmg accordingly. */ if (can_merge_right) { vmg->end = next->vm_end; - vmg->vma = next; + vmg->middle = next; } /* If we can merge with the previous VMA, adjust vmg accordingly. */ if (can_merge_left) { vmg->start = prev->vm_start; - vmg->vma = prev; + vmg->middle = prev; vmg->pgoff = prev->vm_pgoff; /* @@ -1017,10 +1021,10 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) * Now try to expand adjacent VMA(s). This takes care of removing the * following VMA if we have VMAs on both sides. */ - if (vmg->vma && !vma_expand(vmg)) { - khugepaged_enter_vma(vmg->vma, vmg->flags); + if (vmg->middle && !vma_expand(vmg)) { + khugepaged_enter_vma(vmg->middle, vmg->flags); vmg->state = VMA_MERGE_SUCCESS; - return vmg->vma; + return vmg->middle; } return NULL; @@ -1032,44 +1036,46 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) * @vmg: Describes a VMA expansion operation. * * Expand @vma to vmg->start and vmg->end. Can expand off the start and end. - * Will expand over vmg->next if it's different from vmg->vma and vmg->end == - * vmg->next->vm_end. Checking if the vmg->vma can expand and merge with + * Will expand over vmg->next if it's different from vmg->middle and vmg->end == + * vmg->next->vm_end. Checking if the vmg->middle can expand and merge with * vmg->next needs to be handled by the caller. * * Returns: 0 on success. * * ASSUMPTIONS: - * - The caller must hold a WRITE lock on vmg->vma->mm->mmap_lock. - * - The caller must have set @vmg->vma and @vmg->next. + * - The caller must hold a WRITE lock on vmg->middle->mm->mmap_lock. + * - The caller must have set @vmg->middle and @vmg->next. */ int vma_expand(struct vma_merge_struct *vmg) { struct vm_area_struct *anon_dup = NULL; bool remove_next = false; - struct vm_area_struct *vma = vmg->vma; + struct vm_area_struct *middle = vmg->middle; struct vm_area_struct *next = vmg->next; mmap_assert_write_locked(vmg->mm); - vma_start_write(vma); - if (next && (vma != next) && (vmg->end == next->vm_end)) { + vma_start_write(middle); + if (next && (middle != next) && (vmg->end == next->vm_end)) { int ret; remove_next = true; /* This should already have been checked by this point. */ VM_WARN_ON_VMG(!can_merge_remove_vma(next), vmg); vma_start_write(next); - ret = dup_anon_vma(vma, next, &anon_dup); + ret = dup_anon_vma(middle, next, &anon_dup); if (ret) return ret; } /* Not merging but overwriting any part of next is not handled. */ VM_WARN_ON_VMG(next && !remove_next && - next != vma && vmg->end > next->vm_start, vmg); + next != middle && vmg->end > next->vm_start, vmg); /* Only handles expanding */ - VM_WARN_ON_VMG(vma->vm_start < vmg->start || vma->vm_end > vmg->end, vmg); + VM_WARN_ON_VMG(middle->vm_start < vmg->start || + middle->vm_end > vmg->end, vmg); + vmg->target = middle; if (commit_merge(vmg, NULL, remove_next ? next : NULL, NULL, 0, true)) goto nomem; @@ -1508,7 +1514,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, */ static struct vm_area_struct *vma_modify(struct vma_merge_struct *vmg) { - struct vm_area_struct *vma = vmg->vma; + struct vm_area_struct *vma = vmg->middle; struct vm_area_struct *merged; /* First, try to merge. */ @@ -1605,7 +1611,7 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); vmg.next = vma_iter_next_rewind(vmi, NULL); - vmg.vma = NULL; /* We use the VMA to populate VMG fields only. */ + vmg.middle = NULL; /* We use the VMA to populate VMG fields only. */ return vma_merge_new_range(&vmg); } @@ -1726,7 +1732,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, if (new_vma && new_vma->vm_start < addr + len) return NULL; /* should never get here */ - vmg.vma = NULL; /* New VMA range. */ + vmg.middle = NULL; /* New VMA range. */ vmg.pgoff = pgoff; vmg.next = vma_iter_next_rewind(&vmi, NULL); new_vma = vma_merge_new_range(&vmg); diff --git a/mm/vma.h b/mm/vma.h index a2e8710b8c47..5b5dd07e478c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -69,16 +69,48 @@ enum vma_merge_flags { VMG_FLAG_JUST_EXPAND = 1 << 0, }; -/* Represents a VMA merge operation. */ +/* + * Describes a VMA merge operation and is threaded throughout it. + * + * Any of the fields may be mutated by the merge operation, so no guarantees are + * made to the contents of this structure after a merge operation has completed. + */ struct vma_merge_struct { struct mm_struct *mm; struct vma_iterator *vmi; - pgoff_t pgoff; + /* + * Adjacent VMAs, any of which may be NULL if not present: + * + * |------|--------|------| + * | prev | middle | next | + * |------|--------|------| + * + * middle may not yet exist in the case of a proposed new VMA being + * merged, or it may be an existing VMA. + * + * next may be assigned by the caller. + */ struct vm_area_struct *prev; - struct vm_area_struct *next; /* Modified by vma_merge(). */ - struct vm_area_struct *vma; /* Either a new VMA or the one being modified. */ + struct vm_area_struct *middle; + struct vm_area_struct *next; + /* + * This is the VMA we ultimately target to become the merged VMA, except + * for the one exception of merge right, shrink next (for details of + * this scenario see vma_merge_existing_range()). + */ + struct vm_area_struct *target; + /* + * Initially, the start, end, pgoff fields are provided by the caller + * and describe the proposed new VMA range, whether modifying an + * existing VMA (which will be 'middle'), or adding a new one. + * + * During the merge process these fields are updated to describe the new + * range _including those VMAs which will be merged_. + */ unsigned long start; unsigned long end; + pgoff_t pgoff; + unsigned long flags; struct file *file; struct anon_vma *anon_vma; @@ -118,8 +150,8 @@ static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, .mm = vma_->vm_mm, \ .vmi = vmi_, \ .prev = prev_, \ + .middle = vma_, \ .next = NULL, \ - .vma = vma_, \ .start = start_, \ .end = end_, \ .flags = vma_->vm_flags, \ diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 04ab45e27fb8..3c0572120e94 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -147,8 +147,8 @@ static void vmg_set_range(struct vma_merge_struct *vmg, unsigned long start, vma_iter_set(vmg->vmi, start); vmg->prev = NULL; + vmg->middle = NULL; vmg->next = NULL; - vmg->vma = NULL; vmg->start = start; vmg->end = end; @@ -338,7 +338,7 @@ static bool test_simple_expand(void) VMA_ITERATOR(vmi, &mm, 0); struct vma_merge_struct vmg = { .vmi = &vmi, - .vma = vma, + .middle = vma, .start = 0, .end = 0x3000, .pgoff = 0, @@ -631,7 +631,7 @@ static bool test_vma_merge_special_flags(void) */ vma = alloc_and_link_vma(&mm, 0x3000, 0x4000, 3, flags); ASSERT_NE(vma, NULL); - vmg.vma = vma; + vmg.middle = vma; for (i = 0; i < ARRAY_SIZE(special_flags); i++) { vm_flags_t special_flag = special_flags[i]; @@ -760,7 +760,7 @@ static bool test_vma_merge_with_close(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; /* * The VMA being modified in a way that would otherwise merge should @@ -787,7 +787,7 @@ static bool test_vma_merge_with_close(void) vma->vm_ops = &vm_ops; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); /* * Initially this is misapprehended as an out of memory report, as the @@ -817,7 +817,7 @@ static bool test_vma_merge_with_close(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); @@ -843,7 +843,7 @@ static bool test_vma_merge_with_close(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -940,7 +940,7 @@ static bool test_merge_existing(void) vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); vma_next->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); - vmg.vma = vma; + vmg.middle = vma; vmg.prev = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_next); @@ -973,7 +973,7 @@ static bool test_merge_existing(void) vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); vma_next->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x2000, 0x6000, 2, flags); - vmg.vma = vma; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_next); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1003,7 +1003,7 @@ static bool test_merge_existing(void) vma->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); @@ -1037,7 +1037,7 @@ static bool test_merge_existing(void) vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1067,7 +1067,7 @@ static bool test_merge_existing(void) vma_next = alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, flags); vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1102,37 +1102,37 @@ static bool test_merge_existing(void) vmg_set_range(&vmg, 0x4000, 0x5000, 4, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x6000, 0x7000, 6, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x4000, 0x7000, 4, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x4000, 0x6000, 4, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); @@ -1197,7 +1197,7 @@ static bool test_anon_vma_non_mergeable(void) vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1277,7 +1277,7 @@ static bool test_dup_anon_vma(void) vma_next->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0, 0x5000, 0, flags); - vmg.vma = vma_prev; + vmg.middle = vma_prev; vmg.next = vma_next; ASSERT_EQ(expand_existing(&vmg), 0); @@ -1309,7 +1309,7 @@ static bool test_dup_anon_vma(void) vma_next->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1338,7 +1338,7 @@ static bool test_dup_anon_vma(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1366,7 +1366,7 @@ static bool test_dup_anon_vma(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1394,7 +1394,7 @@ static bool test_dup_anon_vma(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_next); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1432,7 +1432,7 @@ static bool test_vmi_prealloc_fail(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; fail_prealloc = true; @@ -1458,7 +1458,7 @@ static bool test_vmi_prealloc_fail(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0, 0x5000, 3, flags); - vmg.vma = vma_prev; + vmg.middle = vma_prev; vmg.next = vma; fail_prealloc = true; From patchwork Wed Jan 29 18:16:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13954035 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 C95B9C0218D for ; Wed, 29 Jan 2025 18:16:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58ACB6B00A8; Wed, 29 Jan 2025 13:16:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51366280267; Wed, 29 Jan 2025 13:16:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FC77280263; Wed, 29 Jan 2025 13:16:59 -0500 (EST) 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 0A1646B00A8 for ; Wed, 29 Jan 2025 13:16:59 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B60A1AECC5 for ; Wed, 29 Jan 2025 18:16:58 +0000 (UTC) X-FDA: 83061295716.15.06B4FA7 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf19.hostedemail.com (Postfix) with ESMTP id D55D91A0007 for ; Wed, 29 Jan 2025 18:16:54 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=V9pILdTv; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="NvF/g3r0"; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738174615; 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=xA4gZ9w/va1zf05DIuTP0c45SbSoox/E5exGi8usm5U=; b=XVhfLZh49LfsGHxnE8fYWJpfKD48/TiBtGWqvVM9Noyr+QGpWSANtgJNK8Usd9yNbKKNQ2 HfFgceze7HZaLQTi+hagVmadIjF517Hx/KKoQo1gzyxop4awbjgVIPX0NW59FVqNjIvfW7 zpjC88YLhfbEzlypkmTlyi9/TZ5UhCk= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=V9pILdTv; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="NvF/g3r0"; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1738174615; a=rsa-sha256; cv=pass; b=06Vl2NlE31uHOaazsQZLIPnHa/lDzMX9RBmML8ukgVRrbiYh/5smt4Dq+sMLE3GT06J5+j /rWCWFMzNiUpWAuzwe2MBtLCyZ9Rgk5blogiIHuYT3X2mmOmRPxl2/bBb5Tu07QRVt2Y7W M/jvbV0wWQqLGTrlVjk4Kg++BNvuD+4= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50THZ2cw016238; Wed, 29 Jan 2025 18:16:52 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=xA4gZ9w/va1zf05DIuTP0c45SbSoox/E5exGi8usm5U=; b= V9pILdTvdqdMg3haBh+2CmclrXizJIjoIO1sXjlVt9TC1mIulJMOtH6UZwDDNmK5 dlvwd4Qc3o7I2f39D94BRNgIkxVawrrPVVDLBHZ93t188CT8GF9yRmjsqzlcYPAI XO3zdYrrh+1IWnBvUFIctkLeCgc11ZqmJyJtw0J8lEgR037fAqZrCSTD1/3kFgpD QgQzgy4VL7Exk3nu+0/HXjc3QhUjg10Qt25FS99dMy0evnOjraUe72C2/Aa/QwwF 8WVXHNM/rVLkUGWFi0k13nmHBcnUWWlf64pg9K7MVFOyN0qxI9ZHevLIFohfreMa HqNJouI0+8q5aqCl2BuFiA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44frus03yw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:16:52 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50TI2Ina013779; Wed, 29 Jan 2025 18:16:51 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2048.outbound.protection.outlook.com [104.47.57.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44cpd9tvn9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:16:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M3yj0y268QrXAnyK7zH04XR2uxa1UvSvsEeAQWIQOhXZ3LH3ccU+7i4WgxMbw9GU9qBDc3isqRJ+AO176ZMvD071y72P7fOTszfqBI+lgwS2SoFWEtfqs9rzBPWMjqxhy02ec7OEaubzlPS76ergNvRvy3KbOKoVZek9xDmZ2eVbysStOjqzgLVH3VLg1FOB54NOonoSkOBQuD55E/Z8yB6QK97JplVJhfW/a6kbvVZpmWjxlLnui23/02ELYjf7lJ/ODdzaRbBVmvMZaQSEHC5EhJKkLLAaFNo5ODMj9bLXoFzjiZUeJC+wwGtTlx7th9Ml98jDz763u7jwgqrRRg== 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=xA4gZ9w/va1zf05DIuTP0c45SbSoox/E5exGi8usm5U=; b=PDlrSvKPcVbGlbQhxnVOHfzhLW1WDT2lU/dQraA/q2+VO+a9UpyrIR5Mqjhuq88ij3AyPVRPCxSfsiaSv4x0VXyXdrKXJ+Jc/kEWOznjB+jVhA8fDnBFC0PKAF2wfTXba/28XzRBGn+7jYDwW6kDyKbXcYTI2WtHTXSdpCXqMfb5WAM8Oxupts0QIeLSi/avrYNd1BNL2lpmquR+edUCj3sxLToLR1OJg3XN2UGscCUNhoNA8yBPWimjPo/l9qtfUgMYMpEiKNE1SkqIcPxkUIpClW2Ahm0PkQRwdgoiW5ci9G7L/w/+YkBK39HSXBebToaTMJjnDCBA1tWMbiig+g== 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=xA4gZ9w/va1zf05DIuTP0c45SbSoox/E5exGi8usm5U=; b=NvF/g3r0br2KFzz+c/lMFDATFad31eX4LlSsPbNMisHZfDGH0ird7ZBmMcNwy/PMyeQgIm11T1HgtUZXNhmgFZcStX4UTLyDVs5dUqUAEwqYD5Jf+DWg1Nc6+Ra8Ctpe+NbwHlXCiGNOD3ha2vXhoaHR91YYo02q1ELxtenVA6c= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by DM6PR10MB4314.namprd10.prod.outlook.com (2603:10b6:5:216::23) 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:49 +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:49 +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 2/5] mm: further refactor commit_merge() Date: Wed, 29 Jan 2025 18:16:36 +0000 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0041.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::12) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|DM6PR10MB4314:EE_ X-MS-Office365-Filtering-Correlation-Id: 8693c3ed-46d0-4538-b672-08dd409118de 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: C/mC4ePDDKqwhazD2BN5EFWAJOXNLk2UcF/icnSqExFokGONOE9OHZzNPCsKLC8v4dD6seUZJXEhqlDqFLr4WUqWsHpWixoV+ERNKulIbE76Q4GJx3mOiBAvt3aPe0Ldbbd33dDiX52k1K5ZLpyLrObNoZmhhRyyPU5UWQYBaiXyVNFFnoxw283ljkDkCaVc513wccAWW2PjGKBP4NMscqAmGdzuqf+90mMH/gO25mPp9yeOB2mj6Foj4s25xxTe3wAw0dLS0xaN9UzYr9S2Yg9jiaOSs+zdB7QG5E3/GWciYV6z1dCwt7xXMUMsyknvID9JfCnkShyXpvHxmyJaWbAo0Y3/o/FMLvzMCYsSjVFgD2BFvZrM+9G5G9wZetpgQQUh28zfH/LQOQD4GGad29kJzeD6+A7rw0SULnPrZO0dmCZgUM0DbEj3F9MdL/mL+E72LH8nilcZNvD18WxOqfIlk2+39oqaqKHMtktzCrUBe3FLbGTN4F7xfPr6xSMOlOyIxszACN1MGf5+FsUP8PPrNOgo17G/rVL7kA1SyJOUfZ4JI6zbz9o7IzPU9zVQ2u4KrPB3Re7oji2HmiBagEk60Z7e09PGsD1PTz5c4wNLEDXJCOY/wmkEh4Iqgfoer0wOXPSQExkPDqAYXAnbhZkZ4jPubg8K58+FO9ZLyzL8+ww60+R5HFEdMVnpkM8oKPYxXld9HtBFLgeNyamDypfHNZ2d5jbZ7ilzj7wbsJKBFRqXebUmqBi+rG1ucb4bjz+EtMhA0PCMzlR85HE7ejGaNqZJ4Ck0aUK9tyV28HPcgoflaQlx0o42s/e9sosyfvT1339RNMds8XX+oTT9wd9a86wM3L6n2hNJLXDcIrVJTBVCm/afYj0k71MjwipKbbV5FQsgGgle0SijlamblUcvtO360G6BL6AvrWLNi8WtPpLSxWpgo/V1O8AJHV4AdqjRf02HFxpCDhubDPw/+ib3h0/5Khbv4U7Q1FatjgxmbkiFq++wHH7mm/+bZybWBrQgJZvnopuukiEqgPtNFxNLllN6r4FT777m5hPGCj+2kQOvRi5ya6udEwpx1iX1LxZQOCOLRDhp1P7yBfQezBfMZPsif1khbJ8HoS0aF443vS5T7VdEXWJ3z/p6MM5TgO/OOTM0u0iOjOG57XSbQmATE0sAvMQApD4dFSmM2u08wUxEeHec1ipdcHBjaxdrIrgRpvh+uFy9TQOWoCScxCrcWOYIPWRA0Si1pil9CxIgXOZ3nsYqh7LltgD22vmZ8a69LmXqv0BiMOwe4qyqhidUZgOpyLUxuAUSp5El966BWVHvEU3Cpr+j7fhWvfdjCngASl1xXkLDfbRTNwx3Ng4E5eYPM5NKTRgJLtgmaJamZ6UUzst9fTQE+zElj/AM 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: t6MFV2AbX1F9DbMlfgWPgT8x176+xTzXV4wUPIPKk6yMEnb+QJKrvcbFFVQQf9ASe+SzRoEnVzNhciKaSnuDjlv0AeYpN4OK7hofA77PZWKTMgikKkNIqd+VJzn1Nm/yVxMha0WrLi/lv5scghRLsmB96Uaq1lF0EhTNirCc0PA+yWtOEytj/YsbYZI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M2ynUg8Au9XqCnNm73M69ydB6j2XKDCQkNIKJXyAMwtmxhjk5giXYNXfiftNLpuYmf94XgYhYZ5hHYKKDPPdpz+pxfAfpqgIEnbStpsAOIUul2lTXO2x8TQYRMa8lxSqO+mAB4/c1qRcAGy+2lIahMIp6bjm4IsfBuGKO3RDFjXitWE745NyI0RXhC5e2s3Xz5WXbC9Mxpy+84gmA12A0bkqYwBRIwhFk48q0XMz9s+F74OhjLFa/p9hAco1/uuypJyt2uOsk3IsO3MQFDnranQUm4H+FGeNUO7Hif2d04L/3q6bLzbuJpaj6251nnmG7JBiCWeDidzLzWEEyKeJm6/rK/h5YBmSyg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: M8eNZuK2F1ZNP36Rxye7iFYWNuw+atNmEtCxD4vc8tTbQRKpGZJSUtInltQaBKZ0Nu3VTM8XP69qwYN9YeN2Exc2PetqjcrKNrf64KCjH4cz72/WUieTvwbz/7YPJNOcq+VZd+LVFNAu0uXnKBkOtiAiRB208oO/w9O0f8Ugu67zxp//eJzsb2Dm/TuBIP5FaS8UpjfLJmIaZP35g45sQ+WZ6srhvjX+tlUt6U4UvphFlc99Ynnhagu/9+jMRVkoB6pETvgvfW/O0v9PbgDZHay3NhAz/TTtrH7sMGV9tM1nsZ5byoFUMoov4OwSySsPIk5saZphg0pujafCS04sF3EM7SUi3IpGDuCl+9MPxgWtlpL7Jq39kUUR8vjfen0bkoNjHxUyzmIkRa2yyXf12HAFF96HTswb6TgsSzB409umAFpAzNQvQ7NbFy1qU1fj4VWAtyQp6CFbgs2LPcdNFxX8pzJHEPk0hbvQZSuQDYAN6qipUy2UgNrguQnZfqkoMQQLxOIR15sY9ikcJDUtJCsN3za8zh5hvU7rJCsJdlGhtvDXNF/diup4hO30eA6bY8O0wWpb62LAigFJiRX63/WGu43U7HR4YkI3GR+nr1w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8693c3ed-46d0-4538-b672-08dd409118de 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:49.4896 (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: dh2RR12cbJpHyhj5UZ5hR68nNEz1dYnBpj9iLiqYAbvQ5i9GUbPYQaIF1q7VVcCP5G2IrzM2IAq2C0LrNVlCoQOsXRHSoikE9nkKrhn5Ezc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB4314 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 suspectscore=0 mlxscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501290143 X-Proofpoint-GUID: zaZq_0I9gP537w9k2Werwo5uK8MpHFYv X-Proofpoint-ORIG-GUID: zaZq_0I9gP537w9k2Werwo5uK8MpHFYv X-Rspamd-Queue-Id: D55D91A0007 X-Stat-Signature: mws7n9ah88z93pi897r6rxm1rduuu18c X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1738174614-976101 X-HE-Meta: U2FsdGVkX19y4yjaq9pzXK/0VVSViCZut4vau2WUJA2CYPiI+3wcyRebvk/RFLkjnCmtY75lhet9J2VjDfyUGUlC4PMzwa2sy5deqynFNq7Z0AoaCp20a3ckx6Eg07SWtCwnEI6HscIqwNKcKK82KKRtJ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IkU2lp1DCkyP7KrD9x3gBwUJn/qfQfACW8QHgTJVKHEfzq/a3AAez0F3On5EBzZI1tf4sMnlj1YFMlx/kn/gHlJROIsaR49SngwIB2TkT4IS1pPs4gBCENwNuEBsI5ULboHaOqozDhnCGhDieI1JlsDLL6vpTmpFvJymYKTA7A+q01UtXMx5/icNKEnXq2XtfY9AOMEqX+yywWncoHMC6m/INzL9pvE6hr4IWWfLmQm/6626DF2Ju5j/qnRP8+4WJoSxm8VnL6D11LV6003XHMg1jqGwrHfTyThnI0mMDF7hni0T/SJW7HWl+ogs35zomzPveJH3/x2gDAJsJMHKHsnozse0uB/YRK12BgCaIVwFWCZ2O4zC 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 current VMA merge mechanism contains a number of confusing mechanisms around removal of VMAs on merge and the shrinking of the VMA adjacent to vma->target in the case of merges which result in a partial merge with that adjacent VMA. Since we now have a STABLE set of VMAs - prev, middle, next - we are now able to have the caller of commit_merge() explicitly tell us which VMAs need deleting, using newly introduced internal VMA merge flags. Doing so allows us to embed this state within the VMG and remove the confusing remove, remove2 parameters from commit_merge(). We additionally are able to eliminate the highly confusing and misleading 'expanded' parameter - a parameter that in reality refers to whether or not the return VMA is the target one or the one immediately adjacent. We can infer which is the case from whether or not the adj_start parameter is negative. This also allows us to simplify further logic around iterator configuration and VMA iterator stores. Doing so means we can also eliminate the adjust parameter, as we are able to infer which VMA ought to be adjusted from adj_start - a positive value implies we adjust the start of 'middle', a negative one implies we adjust the start of 'next'. We are then able to have commit_merge() explicitly return the target VMA, or NULL on inability to pre-allocate memory. Errors were previously filtered so behaviour does not change. We additionally move from the slightly odd use of a bitwise-flag enum vmg->merge_flags field to vmg bitfields. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/debug.c | 6 ++- mm/vma.c | 101 +++++++++++++++++++++------------------- mm/vma.h | 38 +++++++++------ tools/testing/vma/vma.c | 9 +++- 4 files changed, 87 insertions(+), 67 deletions(-) diff --git a/mm/debug.c b/mm/debug.c index c9e07651677b..92936908ed0f 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -266,7 +266,8 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) "file %px anon_vma %px policy %px\n" "uffd_ctx %px\n" "anon_name %px\n" - "merge_flags %x state %x\n", + "state %x\n" + "just_expand %b __remove_middle %b __remove_next %b\n", vmg, vmg->mm, vmg->pgoff, vmg->vmi, vmg->vmi ? vma_iter_addr(vmg->vmi) : 0, vmg->vmi ? vma_iter_end(vmg->vmi) : 0, @@ -279,7 +280,8 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) (void *)0, #endif vmg->anon_name, - (int)vmg->merge_flags, (int)vmg->state); + (int)vmg->state, + vmg->just_expand, vmg->__remove_middle, vmg->__remove_next); if (vmg->mm) { pr_warn("vmg %px mm:\n", vmg); diff --git a/mm/vma.c b/mm/vma.c index 68a301a76297..206e3523cf38 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -55,7 +55,6 @@ struct mmap_state { .middle = vma_, \ .next = (vma_) ? NULL : (map_)->next, \ .state = VMA_MERGE_START, \ - .merge_flags = VMG_FLAG_DEFAULT, \ } static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_next) @@ -120,8 +119,8 @@ static void init_multi_vma_prep(struct vma_prepare *vp, memset(vp, 0, sizeof(struct vma_prepare)); vp->vma = vma; vp->anon_vma = vma->anon_vma; - vp->remove = remove; - vp->remove2 = remove2; + vp->remove = remove ? remove : remove2; + vp->remove2 = remove ? remove2 : NULL; vp->adj_next = next; if (!vp->anon_vma && next) vp->anon_vma = next->anon_vma; @@ -129,7 +128,6 @@ static void init_multi_vma_prep(struct vma_prepare *vp, vp->file = vma->vm_file; if (vp->file) vp->mapping = vma->vm_file->f_mapping; - } /* @@ -629,22 +627,40 @@ void validate_mm(struct mm_struct *mm) } #endif /* CONFIG_DEBUG_VM_MAPLE_TREE */ -/* Actually perform the VMA merge operation. */ -static int commit_merge(struct vma_merge_struct *vmg, - struct vm_area_struct *adjust, - struct vm_area_struct *remove, - struct vm_area_struct *remove2, - long adj_start, - bool expanded) +/* + * Actually perform the VMA merge operation. + * + * On success, returns the merged VMA. Otherwise returns NULL. + */ +static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg, + long adj_start) { struct vma_prepare vp; + struct vm_area_struct *remove = NULL; + struct vm_area_struct *remove2 = NULL; + struct vm_area_struct *adjust = NULL; + /* + * In all cases but that of merge right, shrink next, we write + * vmg->target to the maple tree and return this as the merged VMA. + */ + bool merge_target = adj_start >= 0; + + if (vmg->__remove_middle) + remove = vmg->middle; + if (vmg->__remove_next) + remove2 = vmg->next; + + if (adj_start > 0) + adjust = vmg->middle; + else if (adj_start < 0) + adjust = vmg->next; init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && vp.anon_vma != adjust->anon_vma); - if (expanded) { + if (merge_target) { /* Note: vma iterator must be pointing to 'start'. */ vma_iter_config(vmg->vmi, vmg->start, vmg->end); } else { @@ -653,27 +669,26 @@ static int commit_merge(struct vma_merge_struct *vmg, } if (vma_iter_prealloc(vmg->vmi, vmg->target)) - return -ENOMEM; + return NULL; vma_prepare(&vp); vma_adjust_trans_huge(vmg->target, vmg->start, vmg->end, adj_start); vma_set_range(vmg->target, vmg->start, vmg->end, vmg->pgoff); - if (expanded) + if (merge_target) vma_iter_store(vmg->vmi, vmg->target); if (adj_start) { adjust->vm_start += adj_start; adjust->vm_pgoff += PHYS_PFN(adj_start); - if (adj_start < 0) { - WARN_ON(expanded); + + if (!merge_target) vma_iter_store(vmg->vmi, adjust); - } } vma_complete(&vp, vmg->vmi, vmg->target->vm_mm); - return 0; + return merge_target ? vmg->target : vmg->next; } /* We can only remove VMAs when merging if they do not have a close hook. */ @@ -718,16 +733,13 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( struct vm_area_struct *prev = vmg->prev; struct vm_area_struct *next, *res; struct vm_area_struct *anon_dup = NULL; - struct vm_area_struct *adjust = NULL; unsigned long start = vmg->start; unsigned long end = vmg->end; bool left_side = middle && start == middle->vm_start; bool right_side = middle && end == middle->vm_end; int err = 0; long adj_start = 0; - bool merge_will_delete_middle, merge_will_delete_next; bool merge_left, merge_right, merge_both; - bool expanded; mmap_assert_write_locked(vmg->mm); VM_WARN_ON_VMG(!middle, vmg); /* We are modifying a VMA, so caller must specify. */ @@ -779,27 +791,27 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( merge_both = merge_left && merge_right; /* If we span the entire VMA, a merge implies it will be deleted. */ - merge_will_delete_middle = left_side && right_side; + vmg->__remove_middle = left_side && right_side; /* * If we need to remove middle in its entirety but are unable to do so, * we have no sensible recourse but to abort the merge. */ - if (merge_will_delete_middle && !can_merge_remove_vma(middle)) + if (vmg->__remove_middle && !can_merge_remove_vma(middle)) return NULL; /* * If we merge both VMAs, then next is also deleted. This implies * merge_will_delete_vma also. */ - merge_will_delete_next = merge_both; + vmg->__remove_next = merge_both; /* * If we cannot delete next, then we can reduce the operation to merging * prev and middle (thereby deleting middle). */ - if (merge_will_delete_next && !can_merge_remove_vma(next)) { - merge_will_delete_next = false; + if (vmg->__remove_next && !can_merge_remove_vma(next)) { + vmg->__remove_next = false; merge_right = false; merge_both = false; } @@ -846,10 +858,11 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - if (!merge_will_delete_middle) { - adjust = middle; + /* + * We both expand prev and shrink middle. + */ + if (!vmg->__remove_middle) adj_start = vmg->end - middle->vm_start; - } err = dup_anon_vma(prev, middle, &anon_dup); } else { /* merge_right */ @@ -867,7 +880,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* If we are offset into a VMA, then prev must be middle. */ VM_WARN_ON_VMG(vmg->start > middle->vm_start && prev && middle != prev, vmg); - if (merge_will_delete_middle) { + if (vmg->__remove_middle) { vmg->target = next; vmg->end = next->vm_end; vmg->pgoff = next->vm_pgoff - pglen; @@ -883,7 +896,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->end = start; vmg->pgoff = middle->vm_pgoff; - adjust = next; adj_start = -(middle->vm_end - start); } @@ -893,17 +905,8 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (err) goto abort; - /* - * In nearly all cases, we expand vmg->middle. There is one exception - - * merge_right where we partially span the VMA. In this case we shrink - * the end of vmg->middle and adjust the start of vmg->next accordingly. - */ - expanded = !merge_right || merge_will_delete_middle; - - if (commit_merge(vmg, adjust, - merge_will_delete_middle ? middle : NULL, - merge_will_delete_next ? next : NULL, - adj_start, expanded)) { + res = commit_merge(vmg, adj_start); + if (!res) { if (anon_dup) unlink_anon_vmas(anon_dup); @@ -911,9 +914,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( return NULL; } - res = merge_left ? prev : next; khugepaged_enter_vma(res, vmg->flags); - vmg->state = VMA_MERGE_SUCCESS; return res; @@ -974,7 +975,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) struct vm_area_struct *next = vmg->next; unsigned long end = vmg->end; bool can_merge_left, can_merge_right; - bool just_expand = vmg->merge_flags & VMG_FLAG_JUST_EXPAND; mmap_assert_write_locked(vmg->mm); VM_WARN_ON_VMG(vmg->middle, vmg); @@ -988,7 +988,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) return NULL; can_merge_left = can_vma_merge_left(vmg); - can_merge_right = !just_expand && can_vma_merge_right(vmg, can_merge_left); + can_merge_right = !vmg->just_expand && can_vma_merge_right(vmg, can_merge_left); /* If we can merge with the next VMA, adjust vmg accordingly. */ if (can_merge_right) { @@ -1011,7 +1011,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) vmg->end = end; /* In expand-only case we are already positioned at prev. */ - if (!just_expand) { + if (!vmg->just_expand) { /* Equivalent to going to the previous range. */ vma_prev(vmg->vmi); } @@ -1076,7 +1076,10 @@ int vma_expand(struct vma_merge_struct *vmg) middle->vm_end > vmg->end, vmg); vmg->target = middle; - if (commit_merge(vmg, NULL, remove_next ? next : NULL, NULL, 0, true)) + if (remove_next) + vmg->__remove_next = true; + + if (!commit_merge(vmg, 0)) goto nomem; return 0; @@ -2588,7 +2591,7 @@ int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, vmg.prev = vma; /* vmi is positioned at prev, which this mode expects. */ - vmg.merge_flags = VMG_FLAG_JUST_EXPAND; + vmg.just_expand = true; if (vma_merge_new_range(&vmg)) goto out; diff --git a/mm/vma.h b/mm/vma.h index 5b5dd07e478c..7935681a2db8 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -58,17 +58,6 @@ enum vma_merge_state { VMA_MERGE_SUCCESS, }; -enum vma_merge_flags { - VMG_FLAG_DEFAULT = 0, - /* - * If we can expand, simply do so. We know there is nothing to merge to - * the right. Does not reset state upon failure to merge. The VMA - * iterator is assumed to be positioned at the previous VMA, rather than - * at the gap. - */ - VMG_FLAG_JUST_EXPAND = 1 << 0, -}; - /* * Describes a VMA merge operation and is threaded throughout it. * @@ -117,8 +106,31 @@ struct vma_merge_struct { struct mempolicy *policy; struct vm_userfaultfd_ctx uffd_ctx; struct anon_vma_name *anon_name; - enum vma_merge_flags merge_flags; enum vma_merge_state state; + + /* Flags which callers can use to modify merge behaviour: */ + + /* + * If we can expand, simply do so. We know there is nothing to merge to + * the right. Does not reset state upon failure to merge. The VMA + * iterator is assumed to be positioned at the previous VMA, rather than + * at the gap. + */ + bool just_expand :1; + + /* Internal flags set during merge process: */ + + /* + * Internal flag used during the merge operation to indicate we will + * remove vmg->middle. + */ + bool __remove_middle :1; + /* + * Internal flag used during the merge operationr to indicate we will + * remove vmg->next. + */ + bool __remove_next :1; + }; static inline bool vmg_nomem(struct vma_merge_struct *vmg) @@ -142,7 +154,6 @@ static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, .flags = flags_, \ .pgoff = pgoff_, \ .state = VMA_MERGE_START, \ - .merge_flags = VMG_FLAG_DEFAULT, \ } #define VMG_VMA_STATE(name, vmi_, prev_, vma_, start_, end_) \ @@ -162,7 +173,6 @@ static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, .uffd_ctx = vma_->vm_userfaultfd_ctx, \ .anon_name = anon_vma_name(vma_), \ .state = VMA_MERGE_START, \ - .merge_flags = VMG_FLAG_DEFAULT, \ } #ifdef CONFIG_DEBUG_VM_MAPLE_TREE diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 3c0572120e94..7728498b2f7e 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -149,11 +149,16 @@ static void vmg_set_range(struct vma_merge_struct *vmg, unsigned long start, vmg->prev = NULL; vmg->middle = NULL; vmg->next = NULL; + vmg->target = NULL; vmg->start = start; vmg->end = end; vmg->pgoff = pgoff; vmg->flags = flags; + + vmg->just_expand = false; + vmg->__remove_middle = false; + vmg->__remove_next = false; } /* @@ -1546,7 +1551,7 @@ static bool test_expand_only_mode(void) /* * Place a VMA prior to the one we're expanding so we assert that we do * not erroneously try to traverse to the previous VMA even though we - * have, through the use of VMG_FLAG_JUST_EXPAND, indicated we do not + * have, through the use of the just_expand flag, indicated we do not * need to do so. */ alloc_and_link_vma(&mm, 0, 0x2000, 0, flags); @@ -1558,7 +1563,7 @@ static bool test_expand_only_mode(void) vma_iter_set(&vmi, 0x3000); vma_prev = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.merge_flags = VMG_FLAG_JUST_EXPAND; + vmg.just_expand = true; vma = vma_merge_new_range(&vmg); ASSERT_NE(vma, NULL); From patchwork Wed Jan 29 18:16:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13954036 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 859DEC0218D for ; Wed, 29 Jan 2025 18:17:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 144F9280267; Wed, 29 Jan 2025 13:17:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F4B9280263; Wed, 29 Jan 2025 13:17:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1414280267; Wed, 29 Jan 2025 13:17:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BE308280263 for ; Wed, 29 Jan 2025 13:17:04 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 70562AECAB for ; Wed, 29 Jan 2025 18:17:04 +0000 (UTC) X-FDA: 83061295968.17.97C6A7C Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf21.hostedemail.com (Postfix) with ESMTP id 0147D1C000B for ; Wed, 29 Jan 2025 18:17:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=GspEyiFk; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=u1ENQiHq; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1738174621; a=rsa-sha256; cv=pass; b=3jeZOL93ZMuOGPFGqxHGhH84reO8hPXt4z1pfEEhXUbOJVTPBlnSiC1xKSTlaZCSptB6sC Fy3tQvm5FG5zpGuq4VkrF3m2BKIVCkQIMWddOMlI1E0kLtddSJbVwZmPVqXSARoFp0Aqxz ydI4uUiLBLcImyMH52rJeSMA30d0k2U= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=GspEyiFk; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=u1ENQiHq; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738174621; 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=zuBLPjGNSUMx8Fj6nZFfWbvJyPOQbygIlbM01t+C9kk=; b=UkYc/2+9/j+AEnypw73UlAI/URDbWijwx9FdRtyR+ebHVfgoIqUS4+4ALImBJEEYubRVju rX7HebAFP71fwEySLXG7Ves8j8ZvydDY2cq27HMSjjcTXgZocHcK4p9zN9AtdAEOUQA6as 80g2Jj1SBB3B/CroHvcF7UWNwoWwAMo= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50THQo9J003831; Wed, 29 Jan 2025 18:16:58 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=zuBLPjGNSUMx8Fj6nZFfWbvJyPOQbygIlbM01t+C9kk=; b= GspEyiFk4KugGAU/doK4vOGzkRgHMTDPFVgb/DQTKFwG8muELWPncw/EviQZv018 TeTGqqJVZkdkEGf5JzXIofOaUjqRlKo9jnn6r9E+sWXsmcOAsXQP2Z+ojMLO6/Uw wHJbFIzq+ANBhBwPgy0zm7oORWGYG1k82lwJMs8EEKwQFyqG2qDb5RG5pTCfGW7C yY7sLiuUe9c13tL3mOddADJVl8aaeteYQLjXMgdIw+DOCTPA28WnDZJKJXWjHPVH f7mtfYqhMy7l/ag70S394RZiDeeaAXLq2CwrMLAAPGotgkzN59AMVR2kHQvyuZFh ECSbcuYLEO+l0YHh4pIk+g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44frccr7e6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:16:57 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50THEKQP003410; Wed, 29 Jan 2025 18:16:53 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2043.outbound.protection.outlook.com [104.47.56.43]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 44cpda6jxr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:16:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mzt5z6okw567DRvIyK1kPrd0iG1meBI8fgUQ26HJZGmHseplSD7AM1Xbp3mz7bhLZVnK0vpwFRB8p+Ejd3Y7Fv/TR2cM/+DaZdbN3u2HCG2vYoYTGtqQxW0qQ+Tz7qVhj8b2RLUYWryhvJE/3IcbEtVn+3I53ra/JISAZ0a+v/uX0HMQrM08Eq+VU3h5HJnAzyGCgoJ4gWDpdh6Ooi9BWlWseXwWROdpP4byjknM6WWcBOvid6rugQfetvK0nds2ah01PvNCBuZENYxqIBSIsjNwDIJzADqjn1taiVauMZcOiK029N8XAKXTbCYrwYyuOwg7tECADq7wCH2UIRrzbA== 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=zuBLPjGNSUMx8Fj6nZFfWbvJyPOQbygIlbM01t+C9kk=; b=RgQ6X+eg0TArj203Ab0E1XbA0Jk9kMAyBEuO3TNttA7W/ajTf1cHf+hlGxvafn7NW3pK1jGKJDm+rGvhfScskqxJlFNxmmPJyTk8BBUQPD1VaaEKeUaBUgRJLkZ0gw3gW18FgzzXAVWOLcYW9C2H9ex6jUOyLjs8uiwUEWR/FeQlk801KMYSXgdLqxdz5h3O0HA4Pr2hzSap21jimeIuAiDr3qzLTFsT+A0AF5sUjOa1my2QvD0wNC4d9J9wCnspAJLQfvOunBisK08vCa8GcWnsBivHndJr6mQXddv+5+knoRk9KyXt6sLg2k2KBQNIcpQmrqZefi8/fXTwS1zV1g== 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=zuBLPjGNSUMx8Fj6nZFfWbvJyPOQbygIlbM01t+C9kk=; b=u1ENQiHqKXYV64wNC2A1/aqNK4jefNn13sq3gvCQ5aLk/ZTidpbe2ZQKNDmXgNetuNVL1i5Rh0VYoSIxvPgOqXP4T0QtjTumWU7cPm+g7Xyhq2MCNPJGqz4UK4TJ4UXxmSMCFXMJIHtc8pELNdVVZnZGkxCu2dMEVIPFFR0fK8s= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by DM6PR10MB4314.namprd10.prod.outlook.com (2603:10b6:5:216::23) 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:51 +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:51 +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 3/5] mm: eliminate adj_start parameter from commit_merge() Date: Wed, 29 Jan 2025 18:16:37 +0000 Message-ID: <5a12615fc1432f353c4424ef58d4ebbda7a08b14.1738172812.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0259.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::31) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|DM6PR10MB4314:EE_ X-MS-Office365-Filtering-Correlation-Id: 17b80085-af79-4770-4d66-08dd40911a6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Micros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XA/vV+trsqCfA1XZ4dWjh4corKmbvccW3Q5M7uLt4FSI9RIkA4DY0/ROYgP3MEIAlmNwFcEg2eJx4DAqt48UdhjfxaBIoRG+7yMoXOU0O3TJsEFJdU/igY003qFQP3+X08PBbyHNxTalHqklJHHWbQk5ontcHmgJomInxwA7gNMHU/c/NlXyS73BUp73krnfTy5Ds5OveNG4nZD4P11qsXjMs1qxE6EbZA1+KdzN8mMN5VI/3ip6K8tm9oH252TthE6tO2nSIu80Eh6djkpoK3mNnNvRlKtdMbh9ujiP49hw3w19yHmn7hutOiujHy3zi44W5ETupkhfanOK16yO7aPYn5gDebfNwXTO0JZyIv4PVLbhoTttwAqeS8IbGixHyo 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: RULCMshJwWLa1E9f/jkJhxYbSf634KW8oj/XYKBrvo/12p9ymnj1NtHIkT+WzKbMSFfaY4vCrC/yXkBf42fj6uXHZ5CP66j77f/vsjSul8OgoQ94GW10Ib8p8MUw010esqMWEGda9Lhkpo1O7MVtoAxYLbm/1nHDD3RBttT5P9eWcCCh8QvjD/W1I+VtZkt4exqgl51zuyDNeeQMOJuSKJvTB+4BHXXAecka0gn3yXFilIGZPTPC2IvBZosznULs5qPMsGZkMwoF+K0sN5CkPkes83kCXRh0nwBLtq2Ennfqty6vhvTZNWVwpryFXOdGpuYwc/YSJsKkJ9JC9tG3cxCECGytIzBmuOBghepht4eVhtyB4QI+H7thbi06Wl7wss1uUmAT6sl2P4a7/ZI/uTEx7n2JDTf4R28fDBzPsiLtR4qngL9wa+/Mu9XDQ6GVwCFlGvvtLGU5F/qPFkJi2hpvI6ZOBMNTlw0Q+ojs3zB0NSO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9fzFoFUJnaS91+1bEIx1ail6ly5EZnFAQvhTaNkmeXg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: MepEcMTy3KtlOtT6Q4DvxRKq8Zs8U5elj5jQrpRhIhsdEiP2gJ/EQUN6Yd0YmRCrj0Jjyw/ajNSSUcKBnUH3mT7ojpmmJIS5nI9oFSW8/ELiNJC33i1MSx4QFNh/ScJc8Wrhn7vgie+qf3yxCs8aE6bLjctEQSt9YyR0krPIzxoY8nFQY1dkNSd0A1b4fKfiCT/Ay2EnHINFRvoFGnbmSM5MMMxu12+SdmKizA+H1tXlJiIZyi1Mnc5B47ZCdodnpOhhBlHdYobsD0rs/Jxso96EAJT1kzID0myJSbWdSg9XmKGf+lo/91qkiYuxat19m7rPLRjdimmT6oAKzAb9GN7bCpE8wJ3q7EHoW4+LWZ5S+qVqZanQb3Ft7//V2Nz9fXcH9jF447dqLwUvRSWPCmTOr5i4X5LDjWTpOjaMicsmcRHQmHWT9YNBoV130fnkzPjwd0D2C5aFag6dcRvOZYerrZQCJVpx9WChXMY3w1lu0sz4An4iMM3hmDx697Fj5AVttB7KJ57QqDBlwNNugWAlf7BhlAsdydXFNn6qNwWcmQYO5zFT3ODAOF3B5zOpmhRHbS4PWy4jB1ye8DJ6U9iUoaNr5jxTFI+Wv7J3TGk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17b80085-af79-4770-4d66-08dd40911a6c 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:51.6642 (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: z7v4WNSRSNmJorKyxW54hb9BAZ+D7JcGn5RH39en6dqJrfhD4oPOJtjAfvkbwK30EDTBaYotEab0+7yrkDlik9ODFn4UzBwQYppDKf7DOsI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB4314 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 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501290143 X-Proofpoint-ORIG-GUID: IlW52EpNATf-MzfwXxiCNOVbYQFbkO6a X-Proofpoint-GUID: IlW52EpNATf-MzfwXxiCNOVbYQFbkO6a X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0147D1C000B X-Stat-Signature: jo4zdyyucfyzeae3nye4oyaqteh5ah3p X-Rspam-User: X-HE-Tag: 1738174620-191413 X-HE-Meta: U2FsdGVkX19JsGaXpqmgsjp8NAgXSxyvEdu7FaqEp3QPPUIbVmCQqY37WkMNUbmMO7fInq4j8YMF9TKrKUoWvG+xfi/o5cHOmnv2rFhoZQLwAEGNz45xSN08l2Qq3T61BUGmKhSDg3cy+RmF4H/xhRJ/NQ/cV2cnP2m7KJ9AHSHtdU0gVzKDipXEbuV2twMt50SYRl9czKn8CMiJLmksYQqxdXDekPEJWXbpbx6RQjHi3QaIRZasYgEPnWOpudbDzZyJGsk5tId+SYIkunXO2QPUgkWTs1tKrAhD9jj3DdDFuNk8yTwynnx0tZBlPPc6vd3A3Y/cVtY6cIeNWx78uiHpWbfMH3TFwlYyNz5FYrc5vc5ujLZq2mJZCcQN/COO2E+4PuklV9nxV5EeHf47ufMXjB1yl1ZYoQUcyoZrav0zml8nytZoItr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yvu9U6pwJ2czqBiTnZsGwcd6AHBS8puyU7GhlnXeRvAxYyztR82oJfmW09fNoUEkwn8+BTYyDtPuCqEMXVpLWuVnOwPk= 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: Introduce internal vmg->__adjust_middle_start and vmg->__adjust_next_start merge flags, enabling us to indicate to commit_merge() that we are performing a merge which either spans only part of vmg->middle, or part of vmg->next respectively. In the former instance, we change the start of vmg->middle to match the attributes of vmg->prev, without spanning all of vmg->middle. This implies that vmg->prev->vm_end and vmg->middle->vm_start are both increased to form the new merged VMA (vmg->prev) and the new subsequent VMA (vmg->middle). In the latter case, we change the end of vmg->middle to match the attributes of vmg->next, without spanning all of vmg->next. This implies that vmg->middle->vm_end and vmg->next->vm_start are both decreased to form the new merged VMA (vmg->next) and the new prior VMA (vmg->middle). Since we now have a stable set of prev, middle, next VMAs threaded through vmg and with these flags set know what is happening, we can perform the calculation in commit_merge() instead. This allows us to drop the confusing adj_start parameter and instead pass semantic information to commit_merge(). In the latter case the -(middle->vm_end - start) calculation becomes -(middle->vm-end - vmg->end), however this is correct as vmg->end is set to the start parameter. This is because in this case (rather confusingly), we manipulate vmg->middle, but ultimately return vmg->next, whose range will be correctly specified. At this point vmg->start, end is the new range for the prior VMA rather than the merged one. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/debug.c | 8 +++++-- mm/vma.c | 50 ++++++++++++++++++++++++----------------- mm/vma.h | 10 +++++++++ tools/testing/vma/vma.c | 2 ++ 4 files changed, 48 insertions(+), 22 deletions(-) -- 2.48.1 diff --git a/mm/debug.c b/mm/debug.c index 92936908ed0f..adddfd69dbf7 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -267,7 +267,9 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) "uffd_ctx %px\n" "anon_name %px\n" "state %x\n" - "just_expand %b __remove_middle %b __remove_next %b\n", + "just_expand %b\n" + "__adjust_middle_start %b __adjust_next_start %b\n" + "__remove_middle %b __remove_next %b\n", vmg, vmg->mm, vmg->pgoff, vmg->vmi, vmg->vmi ? vma_iter_addr(vmg->vmi) : 0, vmg->vmi ? vma_iter_end(vmg->vmi) : 0, @@ -281,7 +283,9 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) #endif vmg->anon_name, (int)vmg->state, - vmg->just_expand, vmg->__remove_middle, vmg->__remove_next); + vmg->just_expand, + vmg->__adjust_middle_start, vmg->__adjust_next_start, + vmg->__remove_middle, vmg->__remove_next); if (vmg->mm) { pr_warn("vmg %px mm:\n", vmg); diff --git a/mm/vma.c b/mm/vma.c index 206e3523cf38..3fe264200b79 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -632,29 +632,44 @@ void validate_mm(struct mm_struct *mm) * * On success, returns the merged VMA. Otherwise returns NULL. */ -static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg, - long adj_start) +static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) { - struct vma_prepare vp; struct vm_area_struct *remove = NULL; struct vm_area_struct *remove2 = NULL; + struct vma_prepare vp; struct vm_area_struct *adjust = NULL; + long adj_start; + bool merge_target; + /* - * In all cases but that of merge right, shrink next, we write - * vmg->target to the maple tree and return this as the merged VMA. + * If modifying an existing VMA and we don't remove vmg->middle, then we + * shrink the adjacent VMA. */ - bool merge_target = adj_start >= 0; + if (vmg->__adjust_middle_start) { + adjust = vmg->middle; + /* The POSITIVE value by which we offset vmg->middle->vm_start. */ + adj_start = vmg->end - vmg->middle->vm_start; + merge_target = true; + } else if (vmg->__adjust_next_start) { + adjust = vmg->next; + /* The NEGATIVE value by which we offset vmg->next->vm_start. */ + adj_start = -(vmg->middle->vm_end - vmg->end); + /* + * In all cases but this - merge right, shrink next - we write + * vmg->target to the maple tree and return this as the merged VMA. + */ + merge_target = false; + } else { + adjust = NULL; + adj_start = 0; + merge_target = true; + } if (vmg->__remove_middle) remove = vmg->middle; if (vmg->__remove_next) remove2 = vmg->next; - if (adj_start > 0) - adjust = vmg->middle; - else if (adj_start < 0) - adjust = vmg->next; - init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && @@ -738,7 +753,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( bool left_side = middle && start == middle->vm_start; bool right_side = middle && end == middle->vm_end; int err = 0; - long adj_start = 0; bool merge_left, merge_right, merge_both; mmap_assert_write_locked(vmg->mm); @@ -858,11 +872,8 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - /* - * We both expand prev and shrink middle. - */ if (!vmg->__remove_middle) - adj_start = vmg->end - middle->vm_start; + vmg->__adjust_middle_start = true; err = dup_anon_vma(prev, middle, &anon_dup); } else { /* merge_right */ @@ -891,12 +902,11 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * IMPORTANT: This is the ONLY case where the final * merged VMA is NOT vmg->target, but rather vmg->next. */ + vmg->__adjust_next_start = true; vmg->target = middle; vmg->start = middle->vm_start; vmg->end = start; vmg->pgoff = middle->vm_pgoff; - - adj_start = -(middle->vm_end - start); } err = dup_anon_vma(next, middle, &anon_dup); @@ -905,7 +915,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (err) goto abort; - res = commit_merge(vmg, adj_start); + res = commit_merge(vmg); if (!res) { if (anon_dup) unlink_anon_vmas(anon_dup); @@ -1079,7 +1089,7 @@ int vma_expand(struct vma_merge_struct *vmg) if (remove_next) vmg->__remove_next = true; - if (!commit_merge(vmg, 0)) + if (!commit_merge(vmg)) goto nomem; return 0; diff --git a/mm/vma.h b/mm/vma.h index 7935681a2db8..e18487797fa4 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -120,6 +120,16 @@ struct vma_merge_struct { /* Internal flags set during merge process: */ + /* + * Internal flag indicating the merge increases vmg->middle->vm_start + * (and thereby, vmg->prev->vm_end). + */ + bool __adjust_middle_start :1; + /* + * Internal flag indicating the merge decreases vmg->next->vm_start + * (and thereby, vmg->middle->vm_end). + */ + bool __adjust_next_start :1; /* * Internal flag used during the merge operation to indicate we will * remove vmg->middle. diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 7728498b2f7e..c7ffa71841ca 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -159,6 +159,8 @@ static void vmg_set_range(struct vma_merge_struct *vmg, unsigned long start, vmg->just_expand = false; vmg->__remove_middle = false; vmg->__remove_next = false; + vmg->__adjust_middle_start = false; + vmg->__adjust_next_start = false; } /* From patchwork Wed Jan 29 18:16:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13954037 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 A866FC0218D for ; Wed, 29 Jan 2025 18:17:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22FFA280268; Wed, 29 Jan 2025 13:17:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E06B280263; Wed, 29 Jan 2025 13:17:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED87C280268; Wed, 29 Jan 2025 13:17:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C92D8280263 for ; Wed, 29 Jan 2025 13:17:08 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 40E0F440EE for ; Wed, 29 Jan 2025 18:17:08 +0000 (UTC) X-FDA: 83061296136.16.71FB58C Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 0359040011 for ; Wed, 29 Jan 2025 18:17:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=h9L5mj8d; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=PXT0eFmb; spf=pass (imf01.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738174625; 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=/pm97kA0QTHF1nI3s5oQ5v8v869bmuA/oC9oHoS2dr8=; b=u3dCNKQPXUezXJzOTpItyoBL6Pi3qfuF7BDfj+vxKVYcpeOonU+/v/u3SpJbOwQHpI2Ms1 83WCCodm0HBNkMq2sdQpUaNkrGcaWdYw9WEVZBm/LN7f/R1K4ulw1CybH81AVpwDhse/9C aisJf72/Kx8gMbi6aQxB+SQQIB82lAE= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=h9L5mj8d; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=PXT0eFmb; spf=pass (imf01.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1738174625; a=rsa-sha256; cv=pass; b=cwBzU0/GB+2yIvv1gh8x4aPHdtjdyjV6YeMXD0wgIa+NpQV8ooT6UmKan9wHksEK273nTS dJV8S1UDKo+OOml3ipljuw7JiLnKnNNaUz8fC7tw0RRcgX38k0zRmLxYNA2QpWhuYr9F3J A51oBOtFvKAlZ5yk5/IX72GLbPphDOU= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50THQmA4018733; Wed, 29 Jan 2025 18:17:03 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=/pm97kA0QTHF1nI3s5oQ5v8v869bmuA/oC9oHoS2dr8=; b= h9L5mj8dnjK9DSzY76P7OzL5WaoKyEn6qrAyuIzxwV5YuXyYzWaVNGFzF0vgy+ds r2bm8M2p2JV7Gtvg2peFEcFhwQCVKLwSE1W7HzQ2dsW+i/1QhtR8fE5Yi2z4pDc/ stXqlkkEi05OxL5otTthgUfJqOqP4b+FtfU/Fe3t6GOmV8mU/O5ACMO7Jcu4vAp3 OGHiM27wyqfzppP9uPQV4zmHXxHRj6//dd1O4WGm+BbCf6neGc392y2/8uGjowHZ 4SBcSyM0Vozk4MrYxbCuULeX8oCWzOdSC9iF1O0uTXM2VYZJ0qwU0/8RjKKHFn8o 4PvFh8taeudKOaPNScSlXA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44fqg6ga57-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:17:02 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50THQ6SU034307; Wed, 29 Jan 2025 18:16:56 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2049.outbound.protection.outlook.com [104.47.56.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44cpda2b2d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 Jan 2025 18:16:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ASMXIZfrGJwqWycvFbGtG47Wu/8Mdi2h80WCfWo5DNMG2VnFADTBVmNxtNHgs2fe9QWThGPSW9n7WPbcDG7NQ43AvDMcXv2zNASVJ+jiFyJlqfwl0hW/X16H5ZG7kaFKc36XXKdIUcUjafqOBTr183P7VVNDEJgom4eaaCMXF0Z/5Lxu6ZlLbe0wf4wMem7+PU8LICf+Hx+RthzZGBP0UxH3/sNPjFbgMSQD4B1Zq09TTN8bYJiutnFZBIOnsZq0yqT4PHBKIt1P8f4kV2FaMKjqJLbYN3XIDosyIlbt9PsTRATIxmCoczIHMd7icYz7wHLwsL5tZHms/AHzEAwOBQ== 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=/pm97kA0QTHF1nI3s5oQ5v8v869bmuA/oC9oHoS2dr8=; b=yKYv2rpw5R07FaTa8W5vGOPSdojyx/Ff89pJEWg+i6X3ZHNLwVUHjzsaEAcqb2W1+//brEPOzrXb8oeL4DdN+UuhhugcghFVBIN6S5lglrQxiZQL7j/yTX+6zXQEwNGbN2on04iPXchaaEl97ei9ADCpo9OPCiUVqrliEPkUBTU/iH0mPS9faRsMuNmv6EOnpoPRFm+3+agD/Ib6vta7Za2UfMrW9uBnaNvjeva8XDAHCT/YspY51nufjeXtMyiXvHWYwSHqSYCXS3p0LqevLkHtLUvcnMnXp00KBABu7Za0o/0gp2mb3rITzv26ylTq8ujAAqRSSYZFuDGsrLPOAw== 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=/pm97kA0QTHF1nI3s5oQ5v8v869bmuA/oC9oHoS2dr8=; b=PXT0eFmb+AofMvGA+9X0wrLhc0LMjAVqRWeINVrrbz6io3Ci0IZfvRU0MoilUQ31cbBWQFJ39pMZxyPX1uA7Gc9/ZT+XzXjLg8fYwwGbVhqLmT9EyUATFE4kxD6iQ6uWrzCJ1CPg7AabnY1LahgJR7VlR6KHxQsybm3BKT52ocs= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by DM6PR10MB4314.namprd10.prod.outlook.com (2603:10b6:5:216::23) 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:53 +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:53 +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 4/5] mm: make vmg->target consistent and further simplify commit_merge() Date: Wed, 29 Jan 2025 18:16:38 +0000 Message-ID: <96d33b2251265da01595b97f2639f1b23fea6b2a.1738172812.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0035.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::8) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|DM6PR10MB4314:EE_ X-MS-Office365-Filtering-Correlation-Id: 642ef9cf-743f-4399-3e67-08dd40911bbc 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: x2usHfvgl361DE7adSMbLd1lLDb7XMR4aExzQ10LfNSSZy5pnwAwFTbi8kfEvpoIleu+7LkE6CDxBQLDbyttf3wFk+Aq1WANbrtz8bP7tbENhZIDmKhGV5lMezNDYNeGH0mEFsARz8VB+Qm/ThiXN5KqpVv03UNSxVznOrnjXoOp/ZQYYRaEF9RYM/8DlpvxLv0JmURqyxFLuuO6W6rh4YPLp2REXdlw9yVWjO09p0zpmGQ1KDed6M4mwMZa4eHbwOnW+rYawkFGZOJcMg1v4eNOIpQe+ggE4Wo/GF2KSaiX2phVHWxM1gnE5dLmdV/34+Uc00r2XHhMfaDM4NI3Zqs4GUePTQzFyE5xXvrWlo50iEM6YBS4x1wqQzJfbIOYGwvo6FRDZtTCI2SXwgLi5MvaFu8DEaJgXqwzQzXPsUJhOYsmfSrXtd1RWzWicFMzmQsvhCKZQpsKdKPXBwiMLr9rUVaG2tNGF1h7N4aX6NnhXemlpn8DqjMeZk32By6mBoRnvrg7OkXjogjBQfqof3Z2srROUeiijMkYXIWXc2AVlIcbUKcMUxUR7JDwsCCPsUWZZNWHZUCIwiKOm0BpYNbSKoQ+5uNTjM963KAziJ+iIP8iZLnkGcWNm37PF70JrG4Ua042eE48zV/w6IqlFHpiiDRzzNKjdviE4ZVbawVADzNICdpixApj2ykaeLgWhYmIpUK7vEOOZiQvBLMcenZBIFaKOWjPEjImqHCUU0C+4I87dJKcZqXDpYXoDNcVkZVq1sm/li9XBH9Fznq8AAEtWeQKJelUKR51zpwFIlJqJ/5BqL9QsIcSIXLJCazGXJcCGQ/mnQtfMpQUrz0e1hiWfUhLXo5LWCVkvjnQZlWDAxhunvjxOoNlLnqeKW8AL+CGVTF+aLmMwKVagX+hIXkurjk4kOgmG+qM9epLBZoGoFHQv6ujm3gCQnkKkLjmvYs5hUmW5LM+31bqQYfEwPdeWhPlQYOWwqVRBS5UrOtz5CKFvBSysSN3gymCB4hEP+kjpKowpvjgGBOrMyriNDuHFo5cBamnrCBsOheLS0NhcvzVZ6NiX+eXFfYPRykYHgNoTl7SidFeHHHHCfKwA4IIZGBjpZubPTU0PR2/AQ2DEAvUipIye7EUSNTJRwh/e8TJlPvWAElxJZPK7iHSvBzTXoG0ftDVieCGGdCadQzIMM6uRI4C0o2b/0BszElGX3N/BMmqLvl3ARqtZQedmyN/6JgC1dcIJGn6R3Lki204d2n+HR+8QjLOQnoyM9aclN+ioSsrqYw0MRfbbQF5IWrHXAhV5iVfOpmmsnkIgKUrbDb37AcCNMMUUZ6CKhXySDwr69E+GKlzWq0+UFc5dnQi0o9KiJCbZuR0XgdkSGoWCcwoQV6+F5seZWwfegeA 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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Wf+E05y6PkgUhWy0Mozo4GJcKwEuf2UpIwiZEbO0aTOzSGgocBMAHEVMg0zREDO/M1SfG3BU/3YyHkjO/ezCru89qhDaM+5vF5DUwkgUWwg8c4n1LTldfVv/9sewcq8sTAQ2ZX2XDSvAOHZABbx3Ah1n1FDOcslDRHqYMy2KANS0dvhOphjhDgEiNBWBXvaPG1Q= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 642ef9cf-743f-4399-3e67-08dd40911bbc 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:53.7549 (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: bgzzdQb39McVYhLsFl4Eh5CxLFjFAgku/GVMOZxBxcmJZsxjplT6AxGAAC04Un1NrK+9cKfiJOtpXKnO2F2kpv6RqRyWTMxciJnR1Gbb6/4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB4314 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 phishscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501290143 X-Proofpoint-GUID: XHzyXCLLp1lw6_oduByeG9NNMcdjbnbr X-Proofpoint-ORIG-GUID: XHzyXCLLp1lw6_oduByeG9NNMcdjbnbr X-Rspamd-Server: rspam07 X-Rspamd-Que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5FoyXOE0SO+YN4AznVdi85+G0uZffSmCSBNG+qiDTZtLLFuseq40FqW6Kd1YTh8O0s9OLx0KDJLFbljLLMoBs5PqFiauIN+pSrI53btFsZVkt1E2Be8dy4RD+U8m7v25y4jd9w8QnDkmHckuEO9e75W0t9v8W9GlZxKUQ7Uwk8WgFwLFw/jmW4lBWNgLy8pVIqhccHu20P0aXa9Cedol8d1UZpMBw2e8qNvOVK2lmPRY0aHaKQzpIcXqDK7D6Iw1XJZYAOU0Joyz+Kg3ad2BqTtvnyQG4nBk4woIuCVY9dHmmGmwa6yZgLOWFBC2Rq5V4VK0xNsiNYEhUSJY/P34WuEC89B1DfgeUzM+uh8oTolzht+t7uJahVihl9O5HwkreueaDXJ0/VeIZwpwKk59SKyC9YLs04tuiA7DTb/MrabwigDcmBdvGliQ4jAdK1/vaUxdMN4K7mnk8hvJBvwytqVZ3uMO2zq2DjZioWZEkTZ+2AoHt0F+rnIaXLGBaJVD+jiZxgRBfac/6Ht2Ul40PolqpBcU2AHP6lmVbE3bOVrhuTY90LYA2ekspjnlX2x6u+BR/P7cC+YTxnJoEyepQqMP0NG40+B27Igdz 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: It is confusing for vmg->target to sometimes be the target merged VMA and in one case not. Fix this by having commit_merge() use its awareness of the vmg->_adjust_next_start case to know that it is manipulating a separate vma, abstracted in the 'vma' local variable. Place removal and adjust VMA determination logic into init_multi_vma_prep(), as the flags give us enough information to do so, and since this is the function that sets up the vma_prepare struct it makes sense to do so here. Doing this significantly simplifies commit_merge(), allowing us to eliminate the 'merge_target' handling, initialise the VMA iterator in a more sensible place and simply return vmg->target consistently. This also allows us to simplify setting vmg->target in vma_merge_existing_range() since we are then left only with two cases - merge left (or both) where the target is vmg->prev or merge right in which the target is vmg->next. This makes it easy for somebody reading the code to know what VMA will actually be the one returned and merged into and removes a great deal of the confusing 'adjust' nonsense. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/vma.c | 119 ++++++++++++++++++++++++++++--------------------------- mm/vma.h | 6 +-- 2 files changed, 62 insertions(+), 63 deletions(-) -- 2.48.1 diff --git a/mm/vma.c b/mm/vma.c index 3fe264200b79..75bbe82b2e65 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -106,24 +106,40 @@ static inline bool are_anon_vmas_compatible(struct vm_area_struct *vma1, * init_multi_vma_prep() - Initializer for struct vma_prepare * @vp: The vma_prepare struct * @vma: The vma that will be altered once locked - * @next: The next vma if it is to be adjusted - * @remove: The first vma to be removed - * @remove2: The second vma to be removed + * @vmg: The merge state that will be used to determine adjustment and VMA + * removal. */ static void init_multi_vma_prep(struct vma_prepare *vp, struct vm_area_struct *vma, - struct vm_area_struct *next, - struct vm_area_struct *remove, - struct vm_area_struct *remove2) + struct vma_merge_struct *vmg) { + struct vm_area_struct *adjust; + struct vm_area_struct **remove = &vp->remove; + memset(vp, 0, sizeof(struct vma_prepare)); vp->vma = vma; vp->anon_vma = vma->anon_vma; - vp->remove = remove ? remove : remove2; - vp->remove2 = remove ? remove2 : NULL; - vp->adj_next = next; - if (!vp->anon_vma && next) - vp->anon_vma = next->anon_vma; + + if (vmg && vmg->__remove_middle) { + *remove = vmg->middle; + remove = &vp->remove2; + } + if (vmg && vmg->__remove_next) + *remove = vmg->next; + + if (vmg && vmg->__adjust_middle_start) + adjust = vmg->middle; + else if (vmg && vmg->__adjust_next_start) + adjust = vmg->next; + else + adjust = NULL; + + vp->adj_next = adjust; + if (!vp->anon_vma && adjust) + vp->anon_vma = adjust->anon_vma; + + VM_WARN_ON(vp->anon_vma && adjust && adjust->anon_vma && + vp->anon_vma != adjust->anon_vma); vp->file = vma->vm_file; if (vp->file) @@ -360,7 +376,7 @@ static void vma_complete(struct vma_prepare *vp, struct vma_iterator *vmi, */ static void init_vma_prep(struct vma_prepare *vp, struct vm_area_struct *vma) { - init_multi_vma_prep(vp, vma, NULL, NULL, NULL); + init_multi_vma_prep(vp, vma, NULL); } /* @@ -634,76 +650,63 @@ void validate_mm(struct mm_struct *mm) */ static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) { - struct vm_area_struct *remove = NULL; - struct vm_area_struct *remove2 = NULL; + struct vm_area_struct *vma; struct vma_prepare vp; - struct vm_area_struct *adjust = NULL; + struct vm_area_struct *adjust; long adj_start; - bool merge_target; /* * 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; - merge_target = true; + + /* Note: vma iterator must be pointing to 'start'. */ + vma_iter_config(vmg->vmi, vmg->start, vmg->end); } 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); - /* - * In all cases but this - merge right, shrink next - we write - * vmg->target to the maple tree and return this as the merged VMA. - */ - merge_target = false; + + vma_iter_config(vmg->vmi, vmg->next->vm_start + adj_start, + vmg->next->vm_end); } else { + vma = vmg->target; adjust = NULL; adj_start = 0; - merge_target = true; - } - - if (vmg->__remove_middle) - remove = vmg->middle; - if (vmg->__remove_next) - remove2 = vmg->next; - - init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); - VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && - vp.anon_vma != adjust->anon_vma); - - if (merge_target) { - /* Note: vma iterator must be pointing to 'start'. */ + /* Note: vma iterator must be pointing to 'start'. */ vma_iter_config(vmg->vmi, vmg->start, vmg->end); - } else { - vma_iter_config(vmg->vmi, adjust->vm_start + adj_start, - adjust->vm_end); } - if (vma_iter_prealloc(vmg->vmi, vmg->target)) + init_multi_vma_prep(&vp, vma, vmg); + + if (vma_iter_prealloc(vmg->vmi, vma)) return NULL; vma_prepare(&vp); - vma_adjust_trans_huge(vmg->target, vmg->start, vmg->end, adj_start); - vma_set_range(vmg->target, vmg->start, vmg->end, vmg->pgoff); - - if (merge_target) - vma_iter_store(vmg->vmi, vmg->target); + vma_adjust_trans_huge(vma, vmg->start, vmg->end, adj_start); + 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); - - if (!merge_target) - vma_iter_store(vmg->vmi, adjust); } - vma_complete(&vp, vmg->vmi, vmg->target->vm_mm); + vma_iter_store(vmg->vmi, vmg->target); + + vma_complete(&vp, vmg->vmi, vma->vm_mm); - return merge_target ? vmg->target : vmg->next; + return vmg->target; } /* We can only remove VMAs when merging if they do not have a close hook. */ @@ -833,11 +836,15 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* No matter what happens, we will be adjusting middle. */ vma_start_write(middle); - if (merge_left) - vma_start_write(prev); - - if (merge_right) + if (merge_right) { vma_start_write(next); + vmg->target = next; + } + + if (merge_left) { + vma_start_write(prev); + vmg->target = prev; + } if (merge_both) { /* @@ -847,7 +854,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * extend delete delete */ - vmg->target = prev; vmg->start = prev->vm_start; vmg->end = next->vm_end; vmg->pgoff = prev->vm_pgoff; @@ -868,7 +874,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * extend shrink/delete */ - vmg->target = prev; vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; @@ -892,7 +897,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( VM_WARN_ON_VMG(vmg->start > middle->vm_start && prev && middle != prev, vmg); if (vmg->__remove_middle) { - vmg->target = next; vmg->end = next->vm_end; vmg->pgoff = next->vm_pgoff - pglen; } else { @@ -903,7 +907,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * merged VMA is NOT vmg->target, but rather vmg->next. */ vmg->__adjust_next_start = true; - vmg->target = middle; vmg->start = middle->vm_start; vmg->end = start; vmg->pgoff = middle->vm_pgoff; diff --git a/mm/vma.h b/mm/vma.h index e18487797fa4..e55e68abfbe3 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -82,11 +82,7 @@ struct vma_merge_struct { struct vm_area_struct *prev; struct vm_area_struct *middle; struct vm_area_struct *next; - /* - * This is the VMA we ultimately target to become the merged VMA, except - * for the one exception of merge right, shrink next (for details of - * this scenario see vma_merge_existing_range()). - */ + /* This is the VMA we ultimately target to become the merged VMA. */ struct vm_area_struct *target; /* * Initially, the start, end, pgoff fields are provided by the caller 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: PXVL2L1FwZK1zMhaHT4lK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iPSCIBXunQQ6x7ktCdnF1HZl83HCHT+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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h0UWgP8YAgHrt736FpN8UGl8cAOzV4JJVjEeQAvdz8++UeAzJWWueGasvhIXkYhLfOUnh/gSjacREVK4tXu8AHDWl0lOrZOgZuXgmJOcRX0i8t5lkX/HI9F3Zk4qQzl714Ufaspm3QUoNqpKIodjeoNkE+Vv++9qCPMGQ/wALiU7VfVkm8SRahNJWqEiO9FXTbRuUgVKxDAvXU/4+n+7kutvm3aa0BCDtlUvOm8DDMO7MSs/yrNIUN580O3/XHAbptn+9VLCqHrmW9OhJO4QCYL3CdBZRuZr5gAF9Pk5YJMAvsqPvr90MSd+wp0ocuILQR1T2McyzIrUB5+uCCrbOCSoYiMCD60p0HpenDnVbhmFcvYsTxY/aGaSbcFSMAgt7GVUPEFnILsbBO0EAnfrGeQcNojo+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)