From patchwork Mon Jan 27 15:50:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13951626 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 5B462C02188 for ; Mon, 27 Jan 2025 16:41:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7564028015C; Mon, 27 Jan 2025 11:41:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 705A4280148; Mon, 27 Jan 2025 11:41:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BB9028015C; Mon, 27 Jan 2025 11:41:50 -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 252C9280148 for ; Mon, 27 Jan 2025 11:41:50 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CE9361C6025 for ; Mon, 27 Jan 2025 16:41:49 +0000 (UTC) X-FDA: 83053798338.27.4254657 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf23.hostedemail.com (Postfix) with ESMTP id 620E1140013 for ; Mon, 27 Jan 2025 16:41:45 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="HXjdw/Vv"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Dk4m1gV5; spf=pass (imf23.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"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737996105; 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=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b=UYH9QeW9Z7xvzS6YHQ2K7lsUUz8ZxYreACNxxz71wbvQHMQwLYzlaA6ZvSREl+pYHwZmXe 8K+H+QDe4zAvqSM8f/i09keGhEYOI8gm+G++OjpDQqfKqa0RJQMC8yQSPhpdIY9m23Kpze llur62OX23F0Z/HzSRGto2w+bgJ+z18= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737996105; a=rsa-sha256; cv=pass; b=I2gfYDaKZ9VC3D9SN++NLkqm6IRAA5RHZWx3Q+mbuoXmGHSFXwOueUY9Nq8RfoWvB5Uady IefPMetkfPqtybzGjeWEp+P44BAiglW/Em2dAT32VnzIcuZG77CDj0xs+d7tsY1KgFNZis 2WoCvDf0EAP46N10gvt4PbjBkt462K0= ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="HXjdw/Vv"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Dk4m1gV5; spf=pass (imf23.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"); dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50RFjSSP015964; Mon, 27 Jan 2025 15:51:18 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=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b= HXjdw/Vv82E3xdVn+aPaSaAcZPYIfgi0mm74RUpaS0b2XuCHjjK3UTAwuhN0dKdy H1IauILSh/gpGUsszxNDnNk9ua4+o3j5BHGuNMYp4aeXNszC9jTHkB8hSp9mqP/V +vP2DtD7LdbWASeh2L+PbX0UzHwcj0S/iJhxmz4AohiH7wkwVnEghMl2c/Uxxniw 1IZEsggpLWD3oMWi7kx7H1SZm/BkpwH0MPevlSykOH16DGORhEDb2P+46GhlRFrM dpXAhT2XYMciv+zfLPqo2QrzlI89GfBAdEKRuKg2fHnmvHZwCTtA6gp4bP8GrZN4 IYwUPsr5HN0YiovQGiGNBw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44ed2br0e6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:18 +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 50RFes8v036983; Mon, 27 Jan 2025 15:51:17 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2049.outbound.protection.outlook.com [104.47.57.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44cpd73xue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sdHyYnQef37/GoB4HWgBhX9nVh1QUEZtB6PGTK+B76U5/HWWC+P6sCUXCN56iG5I2t7VS1/leGXlyP+/tTUB8KdPLuDpRlNMqoHxLzZBXOAvUPa7+y2561Tn0bJReLRhA0hsa4hmNm/gOJND/5vmfsM2O0FGTJuConDcebsJ2k7N1YWpQFEVtmEMaX+DXacMXbbyoBknfWEhsBwm9IBrFKY2iG2uLk6yFgWTpIkf4YTWhERtc70AL5Yol3cAwlLaIC0KF3OBdRddkqBqTb6z9UxdwAsVBGc1qzKwOWKDIgHYOPhEi3qxhmrwQ+s8p4tHGNqrqb6fEvWKER93CdY3Zg== 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=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b=b7oQxpZEPCPvz+/A8aDtFUGIGAw6ACMAumuFJCvIvtMlR9FGQ4ZcInMZGoy6qnwXj1Js41C/6Yl0Ul8GuDmagD2nEng3p/EbwSMpC4ko+OXiyey5IGdrmBvg4XIIKNUCcj3gmmrDhxbWBF+3yLyK7mEWSwZSKwATDw61NjHb6a7o62qRK5yOSIld/WUVPl4p3kHa6zo96cfJCh7zPtuB33BlK6x86P1sycWrR3kdLOUUb5mMIHTlyjb0AyjAhsYJBgb+6yBUIExOShWDyC21Zak90C2fxY6eS3mTgFntBe8IYOeTCHcf2LEkndANLqdZbjp9jV567gs/zT9fz9HTyg== 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=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b=Dk4m1gV5U+cAT0fVSiahNux/WEn1JXzrX0bPXsCJd6edH8MObdZnoumI5ZvvsqRn/IuUmKItgcqr2agIiKzSvPWFFL7QU8YR/SbGByAZ55CIU/stpuogdLdcoONb1P9g7xaHiCDr22Hnfh7bk57GRJeIHDhZxBREfP6QBUuGAQk= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by PH8PR10MB6339.namprd10.prod.outlook.com (2603:10b6:510:1ce::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.19; Mon, 27 Jan 2025 15:51:15 +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.8377.021; Mon, 27 Jan 2025 15:51:15 +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 5/5] mm: completely abstract unnecessary adj_start calculation Date: Mon, 27 Jan 2025 15:50:44 +0000 Message-ID: X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0018.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:150::23) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|PH8PR10MB6339:EE_ X-MS-Office365-Filtering-Correlation-Id: 59023535-4251-4f81-c22a-08dd3eea6e49 X-MS-Exchange-SenderADCheck: 1 X-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GwxUHCk9lmeKbmeyEADwinFJqZMZaaspB/ZrGYq0q209cegq0GOAMyUk4V0JGgnYWpx2oCatALF7kgpyNRwCSruw1cXk3EM1zKHxPfFg15jYssok/xmZInhlDBDO/yh9cxg/6jCBcWFcchn1dfeecJ6JYeXejX+TBy1mUFgVGzq7jXBeKZpLpmZQqN5O1oIhCB12conlUNkv4nZ+IJSbhFwRXAecjgvPQK0iHxLWWLyb8h2Kc5NNP5DmkUn80S2ZHUM68Tbl2BMapXlAvz3qc3Xjl50azo0rQCb0ktoFJZVMmrlH8O0+4aEvUuCDFSigFnN8TBfHt8L5FSvfrRWslQoY19GM7edR47HcE+Nai9zjXz108SPTTqfelv3jlCsdP/FCkBeK5b0f2oF2UhNWP16x3cM758K4dtsV9TI 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)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V7YJd+xvw7hLLqci3rpT8BROOcwENJuqRV2fHKFhqV5aBuddr3l0h6JZmtRe8JX3PYiJZgKwJCWV6zN5/sLEcuyReIJ2KQnFe6vc8O4TIXu/9VQtmsScUWTYSPA8ffXzs5SZ4J1KPS5aQe0yRloU1ZFKHtcnUxzvG8yFaCM7fvezpXovD2UECdEloYu005Kiz/IYrpOODBWIvzmfW/uh0knF8JWroK2ifrLiNMSLVgdoVMPDwo7yvg7NUYH0z5SunsKrrJXc621752mWP+czx1UUIwL8jpRB+bRzkLBeKJtpSaZTurkKkCCjnKw3ktLRO8hroL7XW3uYAt/BYNp8qKqdDk9XHqPIR7RlDNRxqcav1V0vFJ195U/LvIu82Y3JeEnVOcJ22qz+cNvQ+Fo2dmyKpOqHH0t0/OWwPyTQailBnW1syF6TTB6BogEDMy4ulpc2p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RbMKCje+mn6B082KNHZnA2S8XrGD4bfxwS4hP/nu2ZBN+urYPtDagbLcH3qsW3QnZPRmZV1YcMygm6X060LYw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: O0wKc1aDonh8cZMFLu5EsTkv9MobcBCu+/GSbPcR3/8sNXCGgFGE3bDOfctoZCshGeqzDhRnLs0JP3ox3Sd/11xfGT1g2MwWoemK7Iz/mm/S+stklheMKfKVyCQC6lTCsg4II7a2ms2d1UY4QCLT4L8rCz+2/zfQTwsDPGlNGGzwThWgTzpE91XEdpM6S3U8k9mdQV3ObYuoDA+WzNvAJaNxHWyekvEoK6obVJrsKg65czy5H8We+vz8zypzZss/NFvIjQHz78FcPqgAzFtNRe8p5DCrdzEiZGbq5llBjdtCnd+tWEBykEG45if3MmXn/ivWRSCVkbzsKmxyQAPqTWv3pT9a3mF9V3YAblCm4+I26iJWY3o04IQcCdx3JEz7AWPn10Ytn5OqHToeHZEnT0MpJN3UyUOMGbQv9nlpmpY0eSGG/PYa2fcwiSuX/Bum/ntqDVQPHnfZTCVY5AGYKiVGyQY8yd8BI/EKKax2UvjNy3MIEIuC2di2LlLzRf9AyJDquT7zIwA0wUsrVjWzERbOjvi3dHBasLx7ULifZi9sk36M+/M1uwiQxfu/6Obx3C7X1zdDokIGGnzrclLs24VOCCoDaedy5CAtuQSUqZ0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59023535-4251-4f81-c22a-08dd3eea6e49 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2025 15:51:15.2099 (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: JQ/6fRQufDeIVpUJrNqvxpcduGbS259S1KVtVKxZIG9jDA1kM+OJRkukYuXcmY2RMUVdTHt/wSgsnjeU0wQi9B8BHMzToaoBpXQu36K7BZY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6339 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-27_07,2025-01-27_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-2501270126 X-Proofpoint-ORIG-GUID: eyna2I2dl_N7AeoS0NgDRV8Ci7ddphod X-Proofpoint-GUID: eyna2I2dl_N7AeoS0NgDRV8Ci7ddphod X-Stat-Signature: s3eys3j1ntx5fkrob3ypozi88h8xms4h X-Rspam-User: X-Rspamd-Queue-Id: 620E1140013 X-Rspamd-Server: rspam03 X-HE-Tag: 1737996105-85899 X-HE-Meta: U2FsdGVkX1+W7ERS8+l5eE1d98ZLd/FVSqlwn0NPsY684B92lYDU80QDtA3M7sVIgMhuQZWZ+8ly0EShGWB0SYNX0o56Q8b9tKFwUEYb7AUQs7kTtyGbSL//m0TR9U9i07yk2AfWB8ZBakJet8XnQvSqP8OXBK3mPMrnNAmrj99ta9C3oUCqcHY/DOLy9oKWgLfDHmnLLCqmHulDlPinARfFdIrqqoyGOrFZAIwFV+IC64gLULE8TvbNAKWOMY1379n2WZjSczhSd3/V8Ybfs7hZ3iNGrJYbx1Yk6HRMnWJyK8Dyq1YJCvtbUnKmiZyGaUTwOGyGXLDjqQzVuJSXSqLoP5BEQM85wyY5uP72lwOLO3gXpiN+RAMfMT+5m+hrnigJaSzTv1LTH8AGj/QVAmOevgeAeB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VC1YODIozRJJ4/pg8AHx8f8i+uF2hR+4jjwEv3+35Jg3gf/iXaIa3pwP55eSA90onV4xl6d/Lt4RoDQsRpcOmW+JURfc7F/Rv5P 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_FLAG_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.t he __VMG_FLAG_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_FLAG_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 | 2 +- mm/huge_memory.c | 19 ++---- mm/vma.c | 102 +++++++++++++++---------------- tools/testing/vma/vma_internal.h | 4 +- 4 files changed, 58 insertions(+), 69 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 93e509b6c00e..43f76b54b522 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); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3d3ebdc002d5..c44599f9ad09 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 cfcadca7b116..48a7acc83a82 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -515,7 +515,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; @@ -646,47 +646,46 @@ 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; unsigned long flags = vmg->merge_flags; + struct vm_area_struct *adjust; + pgoff_t pgoff; - /* - * If modifying an existing VMA and we don't remove vmg->middle, then we - * shrink the adjacent VMA. - */ if (flags & __VMG_FLAG_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 (flags & __VMG_FLAG_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. + * + * On success, returns the merged VMA. Otherwise returns NULL. + */ +static int commit_merge(struct vma_merge_struct *vmg) +{ + struct vm_area_struct *vma; + struct vma_prepare vp; + bool adj_middle = vmg->merge_flags & __VMG_FLAG_ADJUST_MIDDLE_START; - vma_iter_config(vmg->vmi, vmg->next->vm_start + adj_start, - vmg->next->vm_end); + if (vmg->merge_flags & __VMG_FLAG_ADJUST_NEXT_START) { + /* In this case we manipulate middle and return next. */ + 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); } @@ -694,22 +693,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, + adj_middle ? 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. */ @@ -752,7 +751,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; @@ -904,12 +903,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->merge_flags |= __VMG_FLAG_ADJUST_NEXT_START; vmg->start = middle->vm_start; vmg->end = start; @@ -927,8 +921,10 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (merge_will_delete_next) vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; - 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); @@ -936,9 +932,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); @@ -1102,7 +1098,7 @@ int vma_expand(struct vma_merge_struct *vmg) if (remove_next) vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; - if (!commit_merge(vmg)) + if (commit_merge(vmg)) goto nomem; return 0; @@ -1142,7 +1138,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)