From patchwork Tue Oct 11 16:08:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 13004134 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 10155C433FE for ; Tue, 11 Oct 2022 16:08:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19EED6B0071; Tue, 11 Oct 2022 12:08:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14E7B6B0073; Tue, 11 Oct 2022 12:08:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE33D6B0074; Tue, 11 Oct 2022 12:08:43 -0400 (EDT) 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 DA6766B0071 for ; Tue, 11 Oct 2022 12:08:43 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1C76881272 for ; Tue, 11 Oct 2022 16:08:43 +0000 (UTC) X-FDA: 80009151726.12.94267AF Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 45E90180010 for ; Tue, 11 Oct 2022 16:08:42 +0000 (UTC) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29BFOcVL020067; Tue, 11 Oct 2022 16:08:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=corp-2022-7-12; bh=M73CoG/zwcq42BekkteyGMOr7SRzTJgMEtJNJU+4zOg=; b=AKvjqB6+vLaGNQnZJO1OkAcGBP2+cp9ONgRGEgx6q+TV/d6ZpAxyAnLYZYEPl1KM9mik JoCb+E8uPTgMaAyPNLvagSCzoNGI0HtWJegGmwp+y5DbZnx791f6QFFyhdtwV4+cTO62 qHijZMfFfIlBfg4LTZcRSTjjKHBLXgIiFYBC2f5MqEUDcJRIgVnn0JNOtbpSiMLtcZLT FnTYBE4AK25ERBPq1hDrOV5s1fQnjtQrIm89AvrImlRiRTC5zAJcQIq97TPPISYFqvC9 Lt3oIaCsRu2qa/jJG30nTbI7vJP1BQEjKueC1vuqp1/v1F+XMbgjViyb673Z1WnVasfr yg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3k31rtf9wg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Oct 2022 16:08:39 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29BERltv002884; Tue, 11 Oct 2022 16:08:39 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3k2yn3sey0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Oct 2022 16:08:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EAUXVVqHSKcb5shu9aACSRWNPiF0iRj45urA3rtKupYyMw3sualGW8XYRa8prgOiSnf0tB3QCZj/efFcXDQv3I09NCw8dnqPEcF71Hw9ub1CBECkEcrEIEoKzGu3FL+lvq/LinxJlV4CFoiDKFz/Ch4RQUhnOFOTOMoBsHP3oPPqYsKwGn6cID5Vf2bZSKyhyUrIlDcFiZ2ULOTuSBMIKg00R9hLfqs8k0jEureJDQE5alLsWj7PAWxWPyp6EZKM11OhAuHece71WM8Gu3AR3VmH0A3NgpqNbM8QSNdEedSkGL0+jQ3HyX6LlZxFpLgz3fMItJMhphTAEfUny7l2bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=M73CoG/zwcq42BekkteyGMOr7SRzTJgMEtJNJU+4zOg=; b=EWY+QqMnT39tItrba4ODquLInTX40Yf/DRgBr5RxTYuilvW/DOsCJ5wwN2iQfSiqEytOMDBvqdDRHuGBV1vPoLSemlncR5GSXTPhq7toPfUlGSo8i8nPGFwcrKK34v5HzuaF9z3wtJ82y4mvKybial5R1Hh22dBSneiv//yuOonTPttZf7ghi2eohQiBwknFqRJSpLO751Y3CjKc+zVYVfAQWCo2CWLb2v9N2kPLZ6wOW0jLT7bGlYT+H8tTR7TLaFkKJhxYzQfN9ZjMCHj24/6Yphq+FPZAs0oLA57FpD5mZnYehvvzhXoQCslDC40XyIVlR0lzsC2BRIk/EIsvVg== 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=M73CoG/zwcq42BekkteyGMOr7SRzTJgMEtJNJU+4zOg=; b=TAikKfyHHunh5pKGzeTsHjZhmpyl0CXlpTHyG1m8vm3nowqPiJWVMNTFPpaMhV2fSIDoDwMchf4wniE0mZpGcdYwem6B9SpSlXx/jBpYOhbp4he6/3vZBhT0LNFGkBejGNmvupNxZlAYk3xuEX0yPKYuDGKhTVIXuBTqQ5GKfeI= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by MN2PR10MB4125.namprd10.prod.outlook.com (2603:10b6:208:1df::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Tue, 11 Oct 2022 16:08:37 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::2d77:5bd1:1bba:df5e]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::2d77:5bd1:1bba:df5e%2]) with mapi id 15.20.5709.021; Tue, 11 Oct 2022 16:08:37 +0000 From: Liam Howlett To: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton CC: Yu Zhao , Liam Howlett Subject: [PATCH] mm/mmap: Preallocate maple nodes for brk vma expansion Thread-Topic: [PATCH] mm/mmap: Preallocate maple nodes for brk vma expansion Thread-Index: AQHY3Yu4FDy+85Aso0SE0pqHEc5P9w== Date: Tue, 11 Oct 2022 16:08:37 +0000 Message-ID: <20221011160624.1253454-1-Liam.Howlett@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.35.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SN6PR10MB3022:EE_|MN2PR10MB4125:EE_ x-ms-office365-filtering-correlation-id: 718dd444-456a-4416-ca43-08daaba2dada x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: c4LKarqSkkKMDudBPVAMgmH5YHntpp2UCWJs488uU0fhuI1koyfk8GfkpJQMc2LuvtrtUsvSEpK6tViTBv93UBGUzP2tmoZkxP1kjXIrDSLx3+Yz7mvH6I3gvg/and9OTvWpJiBoWMyy/t3afOXMkNxIF43D0MFFDW3iUQ4Lx3G2HcxaWKiQdlVTdwAB1O/6Vi5UfC9E06MGDJdMaRNRk4YzSF1MrWO8gml0nAXTfECIfRIOg3sxswHVLQeQ5QnJp1AuRU8GtoZUavr1stJ81e+meXzKMwCben3e/NBxKvGo2L/9WEdUUwgxHF7+d3EBWE9HSVbRxB6KXNhDgo8jMD15Cis1Z3gddjx6xMblT029uvpu36/PF6dU/RkWNGS2OXRcXdbp4HbOpoc64R7sc9DhlXo2sg2gouUevWfMe/SHvbE9t/xXuFyFCeoPYEVfF/M5uLM3FNm00ckeoi/64YjuuiYlJkt5nSTpaN4oSYkiNIiT1xrD/tTg+A+wldJLZU897bU85Na75eiDcBlHErpU9goHNAoR+Lbi85AOqXRG7V7NuK2aIdkxDCKSDBV9WGHCwCNoheA3etocZkaFHII5zT++clSKQeQeuJtftnZw74q/xKFK70BESag3iZ6TNFkw2YSOsecK3b4UbJdhxFxLdE7nwtfuH0rTkj2reXsBuN6cw1ZLwukiXoc3CfXG+hlEEhhCudJpmhJzOizpx9W4I8wLSpCN2CCSPYbQOOVob9H6kCUrGrPuI7yje9NscSeRuS4cJ81F6V7j/DNpBQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(39860400002)(396003)(366004)(136003)(376002)(346002)(451199015)(38070700005)(122000001)(38100700002)(36756003)(86362001)(2906002)(186003)(83380400001)(5660300002)(44832011)(2616005)(1076003)(6512007)(66556008)(26005)(6506007)(107886003)(64756008)(8676002)(66946007)(91956017)(66476007)(66446008)(4326008)(54906003)(76116006)(110136005)(71200400001)(41300700001)(316002)(8936002)(478600001)(6486002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?zuGSQ15CCRDSJNfc6bahmPC?= =?iso-8859-1?q?Zg72U1J6Dx78+Y6YnjqM6VXhSNya2/BaxYGMTIfIFQcGS2uqaSM4hx6HpdAv?= =?iso-8859-1?q?km9Pl2riq2q8+zZrNsWzmZJzLPCgjHxwk8k7QwMBUCePgyMYfo2TfAYvpKZw?= =?iso-8859-1?q?KMB8dR6mMdrV05Xssiroovi2/1vOeDF7vbn7fKvbRBOAkdHtzEldnzywiMbv?= =?iso-8859-1?q?2eHThEzJut4agNT1jw/sNhfCIjL//vVzkiu820jvieRMXkdVVCC+loR0uEYZ?= =?iso-8859-1?q?a2hY2b5N/CUlQc+rK5ACCWOCVGNGtZ72WIvD8a7t47rRUk12kO9D4FkhbtIr?= =?iso-8859-1?q?xN9SzsV75vzgHr+XD8sB/kcmTpOcSzk7b0DL+Kgam6btrtgFaYTQDdZKKl2y?= =?iso-8859-1?q?7pvMIioAmdRMJWnCjsFkMR2PY4g5fxlf07gIQhGT5P3/DiYVBhtAT9xceLFp?= =?iso-8859-1?q?mlIQWCkpMbHF54P4F75HJR5X1iDw5SEyLmyuHv6pUebjSeIsLzyBsO3+AeBA?= =?iso-8859-1?q?RjSNPFYX0BwScXUo4FPPe29OfcyusbmxStYEtHM7512i2m0/UEx4d52X4kfd?= =?iso-8859-1?q?qtGsYPtXtrcAUrbH4PSHe5tDiNYTYUWFTB8+TXXCfCdvLSAD71GwHlyPLKU2?= =?iso-8859-1?q?PaAiWM0jy6ixNIKSBvZYiAZ9WgsLhLslHacT6NYJVgiZQdVDjn5eCCEQBFuW?= =?iso-8859-1?q?WwWXu2eLz8tLIJ+b3xyXOJqxag++bnZ2ZctplV5dgNs7HY3LQFrfhdtwVN21?= =?iso-8859-1?q?JXonvGJBp3anD8EKZrg436Vwg9G/7bwdW/kqpxD85Df25Vmf7OeYiMgsWJ5i?= =?iso-8859-1?q?IOkqywFc3RdmRHCQ0c9DsVluL/XR4wHUvR+mRoEqO9ebo62gv/qcl0ydcrd1?= =?iso-8859-1?q?tGzHMsBIy8RRu8oVo1khnUx+CgPHe2dhH73FflqPaQYVDOENWnHOAuH5M77r?= =?iso-8859-1?q?JaKIRmOaJ5fZbaE3Ulxmntds3cT55VeH7OZdbmU4hmaiIpatYcJDd9SyVa+D?= =?iso-8859-1?q?usdinDVZ6SLMt2K2IbpdUmEVP1Z27DinOwdpG9tVL90yppuoiHSyNByKtRfe?= =?iso-8859-1?q?Tn1OOewrbi4DboTOuCQzfXH5rKYY7WC7qQfQjqdfzAXhAgR7RIFN33G+9uZk?= =?iso-8859-1?q?VuJeiueKxufml8n/vaU186NpzBoBBWfGwhBppkIKlp9QBGWLim0SaONFkGFL?= =?iso-8859-1?q?8FBahHLrZxVzo3FPqJYzV9YNdjd2jz4RUN0SgGJs4b3MMSJOZE4BmiDaucBa?= =?iso-8859-1?q?iWJJqIEnWm4MxBVqfPMSDF40Wlbh2HmcMiu2Gc1wk86Qttx6RNiFVV+byE6Q?= =?iso-8859-1?q?f/4XM1VSU2F3fa6xj1Ea4a/uJtVKM5eVuWzkWK3wODp4/uj364SpTspGagpg?= =?iso-8859-1?q?VCJ+WFB88Lw7Q9Bf3Uu/YjfwEByRJJ9uVklFbRrLFm5PMrs0nHrg44f+kxtC?= =?iso-8859-1?q?ALc9GJeIC9J21rlf3OQyHy8kBJwCunCHV8AzJ18mvDPg1rnhwryvzI/O4WOM?= =?iso-8859-1?q?RDkozprSqquhNpiDq/9gLVaAtqx+dtJcEWGntpfuD4t3ikjgiYcGMOB3wr0B?= =?iso-8859-1?q?UBzp5VUHbGEffyfcq9t1/IZ9j2hE+g0Kw7l9dGY4sOl6SlRbs8VwQc6cSWEq?= =?iso-8859-1?q?uAfHDWJjMiC8qGvt8u8brZNwhZA8MoRXQBUkHOA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 718dd444-456a-4416-ca43-08daaba2dada X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Oct 2022 16:08:37.0857 (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: h5arYXiB2coUbLmyAM9c0IoBLfch+uORAZT4LFA1JpxRkyD/z137ykIKQ1MHlzRmdVCTv3k1nrcRVmD+uBA2uQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4125 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-11_08,2022-10-11_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 adultscore=0 malwarescore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210110093 X-Proofpoint-GUID: sudWUtX824Ivyoqt_Ng_Yki4stvDj2Zb X-Proofpoint-ORIG-GUID: sudWUtX824Ivyoqt_Ng_Yki4stvDj2Zb ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665504522; 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: references:dkim-signature; bh=M73CoG/zwcq42BekkteyGMOr7SRzTJgMEtJNJU+4zOg=; b=Tx/BVcNhowIKc/QjhPZ2Qpdd4GskrfZpAog4ARqtec67ZEWPSnISu8XQpng6jCLlGmt/1I iGYYMSi/ljSP/eQLbXsRuvnSHxYVYDUH6xyBvJpR5mcZTGiV33O3LR4zo4GRe9NUA4+W8Q nJf63g1n4HVnNB2mYXRlC7iiUAWaICY= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=AKvjqB6+; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TAikKfyH; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf16.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=liam.howlett@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1665504522; a=rsa-sha256; cv=pass; b=Ya1BYyvbvstfTifmMF9De0lBk9M76tDf0cboNPhwU2jiwpNroV1naLnMnJAzFHl1KA9j0O 12CTeQO92WS4QT0GkvxkLzJ4/a1GbEbkK4Yr2t6uj0GKiD+0LCsnTT08MwehRdDXrcSCuQ PsGy0adWNHy7Rb9aTnQR5Io87w2t748= Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=AKvjqB6+; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TAikKfyH; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf16.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=liam.howlett@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Stat-Signature: z6u9uf8tz4pgnkufo7h19fz5aqqknzie X-Rspamd-Queue-Id: 45E90180010 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1665504522-776078 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: If the brk VMA is the last vma in a maple node and meets the rare criteria that it can be expanded, then preallocation is necessary to avoid a potential fs_reclaim circular lock issue on low resources. At the same time use the actual vma start address (unaligned) when calling vma_adjust_trans_huge(). Fixes: 2e7ce7d354f2 (mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap()) Reported-by: Yu Zhao Signed-off-by: Liam R. Howlett --- mm/mmap.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 6e447544f07d..74c0e3784500 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2942,17 +2942,18 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma, if (vma && (!vma->anon_vma || list_is_singular(&vma->anon_vma_chain)) && ((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) { - mas->index = vma->vm_start; - mas->last = addr + len - 1; - vma_adjust_trans_huge(vma, addr, addr + len, 0); + mas_set_range(mas, vma->vm_start, addr + len - 1); + if (mas_preallocate(mas, vma, GFP_KERNEL)) + return -ENOMEM; + + vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); if (vma->anon_vma) { anon_vma_lock_write(vma->anon_vma); anon_vma_interval_tree_pre_update_vma(vma); } vma->vm_end = addr + len; vma->vm_flags |= VM_SOFTDIRTY; - if (mas_store_gfp(mas, vma, GFP_KERNEL)) - goto mas_expand_failed; + mas_store_prealloc(mas, vma); if (vma->anon_vma) { anon_vma_interval_tree_post_update_vma(vma); @@ -2993,13 +2994,6 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma, vma_alloc_fail: vm_unacct_memory(len >> PAGE_SHIFT); return -ENOMEM; - -mas_expand_failed: - if (vma->anon_vma) { - anon_vma_interval_tree_post_update_vma(vma); - anon_vma_unlock_write(vma->anon_vma); - } - return -ENOMEM; } int vm_brk_flags(unsigned long addr, unsigned long request, unsigned long flags)