From patchwork Thu Oct 19 02:31:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428193 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 8BC80CDB482 for ; Thu, 19 Oct 2023 02:32:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 363FE80080; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23C5980074; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 044FC8007F; Wed, 18 Oct 2023 22:32:09 -0400 (EDT) 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 E433F80074 for ; Wed, 18 Oct 2023 22:32:09 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C6B831A108C for ; Thu, 19 Oct 2023 02:32:09 +0000 (UTC) X-FDA: 81360636378.12.30EDB9E Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf07.hostedemail.com (Postfix) with ESMTP id 8F67F40014 for ; Thu, 19 Oct 2023 02:32:06 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=e9YEpOuc; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=VcQCFtKW; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf07.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682726; 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=aj9XYBvc1umDA4dSHKq8Dgaza9nvmhLjC3NH0H6MDKA=; b=A09dJcBB6DVOKliw0M2Y618HweWPdsz/c361bUTap47y/+wewoZKiyJx3zmoMbsypOkjjT pP2XpiQviUrXa7Ls+b6hJjVjyGTFJaqTYZ8GqDklJEGEr24JcwxovEu+L3iecct7TeV7xG XrPzgay33U0He2OARO1zeQN8naWXAMk= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=e9YEpOuc; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=VcQCFtKW; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf07.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682726; a=rsa-sha256; cv=pass; b=m6JoPymtSzZMeanD0aNLdze0PIgXpV/IQnnWskSkuUkfDkiWpeIsrdsBGCf6hZpMge5Jeq jdk2dLc59heJD7VD/3/nOmfxEB4H74b5e43orJ5RhC9XpoEZGyo3ZoLCq3JiBGoAgMLjIX 8IJb8bJXlSZdiAO/JP8F+SInkTbqR2E= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IIn3Cn027685; Thu, 19 Oct 2023 02:31:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=aj9XYBvc1umDA4dSHKq8Dgaza9nvmhLjC3NH0H6MDKA=; b=e9YEpOuccwTjeZWuQ1t3MT5hXeGQMLPTfONh/qmXjzwXA1hqm1Jnq7L1VCznDFent1DN ZUNRmUSzeRzcn5Q2AZzm7wYLHIUokQoFIKIrWft7BkBVfDPXZqWKrlCHr/Z6l8i81En0 Sl5MAOVFrSpx9Z45rlwm5llvdiRMQXgeeEsMcYgxZgDWKdQz0CyjSEVrlrQlcDmfmxet aSwXS+jxELMuOsMqxb21FWzRTIMcnFcOmLTuwgzFtZkbbVkSs7DW7IOyEtwPEZwOpTdf trTZTu8eqYjGD96+Kc3QYyMj+3vqI0MY0s01tBjeJ6T5h+b773WhsNQW8TJf2/ozd6ir 6A== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqk1bs38e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:23 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J1r0c0040448; Thu, 19 Oct 2023 02:31:22 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3trfypjxg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V1KBugUHc2dqKT3skjw0iTR5kvxNa9vUvVOizhCJmK6tcfGuFXfs8oiSFnmUUgx4/mZN9rwKr8C+bw92CaWUeP7UT3rtZMcFfiV20PDpJpGUsNuSfY6GUPpnuj2/mNthLqg6eD1vpU4xqh9zFjbe/rQYPWdevSbV+nW2/wiO40Sw8yze33KuPykK2mwat16WCf9YlE7vFgHtSeIPZF4BFLY50DCeAVOaTLhTyh68sBoLWnqDEEja5SiT75iUoP66BDfJXptE3yRxA3xJtNn0/cYnwY+kzLymtJEhOb0xRyxAG6IeTfLmNlJhKUPqXXzT5eWrRK9XVIH7jL0w1i9eFg== 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=aj9XYBvc1umDA4dSHKq8Dgaza9nvmhLjC3NH0H6MDKA=; b=aUzUQGyg5EnH8vjtgyBJAwTFTKpP8JVQMdO3Yy3dSjqEZh3DZd7VrXnQMNqzhOkb76Noc6etKyvTgJR6foOYt0kPaMvhy3emBNzZ6+lPo2+lCQgFSYlBCAKCUkNyRwkKbTMuWUYXcAekuLOdSM/aU8dr+3Fy5P1Qchh5geaqa7SEWIOtG3YE/c1mSykPviionqdaqE6M0TrBf4UR+KtgGdpX0zplreWy6IJYAssQyLKsoXzf3DlxFpJOAUKspZLeYSB6oNIqV/dgdwc8t4CuNEprcImc5YoLIRd3V7825QrdDIy10f4w8iHM+aesk9ToNpMJkVF61OKztggrrJ3TjA== 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=aj9XYBvc1umDA4dSHKq8Dgaza9nvmhLjC3NH0H6MDKA=; b=VcQCFtKW4NsanTqwEm6ZfCfG9AI1qkuivUrX4HA7zuVm+qMrQ7zIwDNGJem+9ADm83qZC0slUz2fIlBp089N6G/yrTneP0N4c+78LSSJSF+RoRtzZvNtyisWVDl74LKk4zJ+IVb8kx4P47pQkfhe3nGFjfxTSMqfEVg6pYnNxQw= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:20 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:20 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz , James Houghton Subject: [PATCH v8 1/8] hugetlb: optimize update_and_free_pages_bulk to avoid lock cycles Date: Wed, 18 Oct 2023 19:31:03 -0700 Message-ID: <20231019023113.345257-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR03CA0095.namprd03.prod.outlook.com (2603:10b6:303:b7::10) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: 3497091d-d510-4766-32d6-08dbd04b7a93 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sCBmrf6FWGXnnDYsdXozTxR5k4OK2ZxgIhBrJ3FW41L34aAa5ooKgOUAnrJ7StqROYXGkh13gqVVs+LYd92/kUpRkpTNdsu4/7F76TfA6+x/KeX47A1lFmqyPVAhAMskubQxKagE30MIzvavNrCbqNaMNy/7GCe1CQwkGT0TRYsKtH28SEoVyzR9dI1RRBbNt4Ah8nH81eV9O91w/E1nZ8BtXuFsTx48t/11qi0jhSF0ebbyBZ/MQ1FeQlCxrqi4+lWh0Qi/5trG6jabOUyLoKAzwVzyAs0WnR+1eVFQZMwy/70H0qQu6p6pgligr/ocPsijAh4pNLA9N/44qwxh1n3X1orTj1PDoNA9VHmUDcFD8P+KMaJa84tZX7tonForh689luxqWpzdf98ZquAb9w+vd8csxKKP/PTZMf/+CyNXUMMEKd3HFVTSfNMxLXb6os/ji33fZHQNKfQisyr5QBzh9I79NvN2k5q475a+TGiS3rd6T9kTSUAEXRnsvzwWNvkKH4Pybx+6nBDQPi75sQKdjhWBxO+1BKSlGzX8I29XY2OeKHCSMoMQWUrANjfy X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(6512007)(8936002)(2906002)(4326008)(15650500001)(8676002)(7416002)(44832011)(41300700001)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fDX8WngwI5tItkRa0jsEXfz2RznQjt4vANh2q3dj8ewmTU7d/aj6aB9CNdRgmmCgenBkSxEY/elEnJh0faJBn/w1RUZkG+evHtHcLCPAcAJ/RZdAfOqctvUCEpg0wmUhY7ME/RocfUb0Y2KmPLfMODXQ9KvAPhhvxiIYrCk7tNxjWYPBarOkHMte00sBQQ7BAA+jfeHw7v8Siplr0hZ8rvWr8Vi9cjXPNdlkASrQPTv4uW+a8SHr6ooS2gw32EHP01lOTfdqBHIReiRdu1PKav6aBLd0jr92GR1b+I1W6+0roLkxDDaLWHcDqxGmggR1HAYUxpZOfBnxe71KAx6ZcvoYAdTH3DRKPFufaWNczcCBX8wApPi2yO5gfqprAy3Zq/VqMCJE6tRWwcYuxge/yKz/Q7Y3i0w/1xddRnWdRUFwWfUae+FViDStOzSYtouXeNyJC4CI09XRA+FZlZ5Ku/w2Lm+kH4vEUFoBFFqP6cliwc3iwF3rzulGPfkCTM6/DEdLpfrUGaQp5EJyhQqSvCzhJc+bVQ92+tm5d+ybFQmYqKtYaLN0ug3ekjgo9IhMn0FYIED2z1ud5JIvM96RVC2TCBA39xDcKB+pbTU7eK4Hd15mb4Wb1afSsRqIyVaKDlgNA/RYFffLFbkK/WtvpKq4WM91RsmyO7IbyVpXxzIRCJOS/esReAMayde0PnWY1iMo8q6VyBvukbaEt3XkC2o3C7uKZxdJHugVDt06EFMsMbBg7HsYrXHBNVfTowYd/XtkJHCNvTS7/3h0DG1N39X4OLP/4PHQBxAoCSinZklAR230mJaYv+90YSrQ4+dX6nKwwA0FbeOLPYsp/jQJTvoPfPRK9BR1nbLWNga7Y4MgJc9z4FUA4lz2kpliEs8Zg1rB9vq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SiBYCvK20ERQAaV3oJ4p//EjbkYORNh1thw2/OYjev+WUIkStMAHILuwgZ0D8jfHNvSQHEkfjVs/KPDQmWjKBbUSZ5asg0d/FEmEzFBQX0Om6/AfkWCVjmRYroVPc59MhbFPHUC6YHaFRyVFfGd6EmdPSNqllRKi4KI8sHVq4IoX0sm6ePMbZoKkvvP6HbPMoT/TC2A/hYhzzcNIKd78pjZNLECabWQ/dXI+T4gpW34dS3lP7FmUP9DClrYeexkixlH8BgPuUfFCeSHCtNCEL/BDMXAW9lASYnT6Cg3VIPisIpFa9auAePZQYhL7qAayTSnHG3Pvjya9oH6BnMOBLpouONFTuabhcHrIC3EJlUfFev05RWBZu8jze7KOnYFmgfXWmYyTmZXDMMV8A2+d+4r+KYPp1PxEGjLPyq/brIDWMqrafgoKMdCX8r+lAzZFc0BnQaWCeaNQz3WqVnfttyBo5nH7v0hGrugTiVtdA/BFOUlvP6UwgpfVwCqIrI3Z0Iz1t7K5zunZhvdDIIDZ5jxoi6C+kb2Z4yN1lP480eNqx5N2W1BPR3Cw99OX32CSB+BQaJgYflXw+OzmiSYQ3a9qt61zNkd5+9z6oCaae5jQdBXDwcSFJQXLztg8SwpEQiyy2PBnp630JyjhMlUFIpxeVquVcnU5n9o+QB/ZyfgDiWgT34lKFtIwWDW+IhdYKiECqDauaq6+rAcBfSn3/8jtxxQQ4NsrF0xncITXzzDEGYcfdRRX769fjgVLnjRF198QqVO5Zqlsmfmseba0o0WM0nmZFy7FW39+8uwVFFs0isxpTXsBkWHx9b+At3qSMbf8vZHlC92q95qO1yvH2iPZ1nSq5GLYrhUIHPNAeqTKHzk26bqMS73uj3m01Pt5Tv1TcULYed8Gq3WMtyJ/juAYN09k X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3497091d-d510-4766-32d6-08dbd04b7a93 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:20.1867 (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: e0La7n9nhs6MV2VIaz83dp3QI3MlRcpJngx4sj4Et+DTJMf9+zb7beJJszoYD1PFOthBchx9vnrp7lARveidkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-GUID: eVSFDYN1w36MvDUeeE3XEksew9_kiHYQ X-Proofpoint-ORIG-GUID: eVSFDYN1w36MvDUeeE3XEksew9_kiHYQ X-Rspamd-Queue-Id: 8F67F40014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: wehrf9fm943gng5mmd5ewkj84n49b3nq X-HE-Tag: 1697682726-364137 X-HE-Meta: U2FsdGVkX18Ag9HBP8b1dQfkl2U0X1mj2b/fjc8RmfETSgpz1DmnH9gyEu433C41x6zupc1ZH1/xdkcrSNzAGw9Jl7QLFKnHlvcIq/s/qop9JMCz0vNBOCZMVPZkvJsA/pH6wCMK4CJRjN0BjUcrXI/OwWR4n4QpQ/M8CfsdSl4wgTwb2XmOSKldSlOXwljzNDkLP6MAmGXxh0iNnyXWiItwg9XZeUaV6DuMUCfi+Sa3uOZDhYFMdfbT24iJ5V6OCkGF/TfS/OnfGMBEVfzwHa6LlVqXkBm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rJt+kDM0l89HO1UE/uQ7I+Y6M327YMc2VCGg6T0GAlGBactpFNFj3MkwaycQMrF2MXZO4FY3bnmm4aNSh85RuZYz1+fIZXEEuv8Lcg2XPIJ9fUaN4Cq3uojvgyFLiaGXGMtoNn76gcR+d3R0fes7lyqk1anuggxOQKtIEhF3okny0sfUQlGUi7g8 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: update_and_free_pages_bulk is designed to free a list of hugetlb pages back to their associated lower level allocators. This may require allocating vmemmmap pages associated with each hugetlb page. The hugetlb page destructor must be changed before pages are freed to lower level allocators. However, the destructor must be changed under the hugetlb lock. This means there is potentially one lock cycle per page. Minimize the number of lock cycles in update_and_free_pages_bulk by: 1) allocating necessary vmemmap for all hugetlb pages on the list 2) take hugetlb lock and clear destructor for all pages on the list 3) free all pages on list back to low level allocators Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Acked-by: James Houghton --- mm/hugetlb.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index da6f85b7db88..b839080a2a6b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1862,7 +1862,46 @@ static void update_and_free_hugetlb_folio(struct hstate *h, struct folio *folio, static void update_and_free_pages_bulk(struct hstate *h, struct list_head *list) { struct folio *folio, *t_folio; + bool clear_dtor = false; + /* + * First allocate required vmemmmap (if necessary) for all folios on + * list. If vmemmap can not be allocated, we can not free folio to + * lower level allocator, so add back as hugetlb surplus page. + * add_hugetlb_folio() removes the page from THIS list. + * Use clear_dtor to note if vmemmap was successfully allocated for + * ANY page on the list. + */ + list_for_each_entry_safe(folio, t_folio, list, lru) { + if (folio_test_hugetlb_vmemmap_optimized(folio)) { + if (hugetlb_vmemmap_restore(h, &folio->page)) { + spin_lock_irq(&hugetlb_lock); + add_hugetlb_folio(h, folio, true); + spin_unlock_irq(&hugetlb_lock); + } else + clear_dtor = true; + } + } + + /* + * If vmemmmap allocation was performed on any folio above, take lock + * to clear destructor of all folios on list. This avoids the need to + * lock/unlock for each individual folio. + * The assumption is vmemmap allocation was performed on all or none + * of the folios on the list. This is true expect in VERY rare cases. + */ + if (clear_dtor) { + spin_lock_irq(&hugetlb_lock); + list_for_each_entry(folio, list, lru) + __clear_hugetlb_destructor(h, folio); + spin_unlock_irq(&hugetlb_lock); + } + + /* + * Free folios back to low level allocators. vmemmap and destructors + * were taken care of above, so update_and_free_hugetlb_folio will + * not need to take hugetlb lock. + */ list_for_each_entry_safe(folio, t_folio, list, lru) { update_and_free_hugetlb_folio(h, folio, false); cond_resched(); From patchwork Thu Oct 19 02:31:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428189 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 95069CDB47E for ; Thu, 19 Oct 2023 02:32:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 327D88007B; Wed, 18 Oct 2023 22:32:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D84180074; Wed, 18 Oct 2023 22:32:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DC9C8007B; Wed, 18 Oct 2023 22:32:00 -0400 (EDT) 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 F138E80074 for ; Wed, 18 Oct 2023 22:31:59 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CCBE9C1077 for ; Thu, 19 Oct 2023 02:31:59 +0000 (UTC) X-FDA: 81360635958.09.7FA3950 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf13.hostedemail.com (Postfix) with ESMTP id 751C52001E for ; Thu, 19 Oct 2023 02:31:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=EO6vk6+n; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dEq+5mg7; spf=pass (imf13.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682716; 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=4c5IqZK42Vm4yM8Bv7kR1mooPI8YiFYT1J97EnWLS/s=; b=Gu7N4bH5vhVmDpiEFptOMG5nTOnNAY0OU091aFvg+5DePq9uR93FClMu61wPLpal/SHGPQ /DOvlvvPvmRo6cbrh3ggAbDEzqxm4LbWHyoVOoqZuw6cOVIQtrgc9gf3H5d7ZhZYgvkPmV fvgrbD8+io0mdqlyoNg91dW3m2FU9Lg= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682716; a=rsa-sha256; cv=pass; b=SJDgPkQKJC4r0Ae4yc3PKYgDsSfSfEk2IeY7oaYLS8Y6GSBbZweri4oNttZYfg4N9HGIOX rtjeM2+J0nGWD4/wGckHYxLqspGnJni+Z6dxZzbNlsl3MUM6Vhwm4g4aWYrgXaqmyV6zyY E+UDp5dItMeq736zN7Wz0b4mpCW9Ogg= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=EO6vk6+n; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dEq+5mg7; spf=pass (imf13.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IIn0SC011269; Thu, 19 Oct 2023 02:31:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=4c5IqZK42Vm4yM8Bv7kR1mooPI8YiFYT1J97EnWLS/s=; b=EO6vk6+nT+OVnb2cK7NRyIYUEN//yGWZkXom88RGvrSs3wNKw2Ncv7Py0aAF6d97Se7r 9yhmcD325I6WKslWcglpA8ZPfxyntyJoZS0dxrK6IlzMFScpMfDcT3a333xdT/es1w0R EpKpRTWx63jhK7ziglPPAcqQSPCOgSwbcrroWrWDZeN2Pwg9evdUqtOmqkc0TNY1FkAZ dc0l7way+yQ+NBCxy6QUJLJkwPjazTMm5rM8ddS5Y9ZP3Z+MSbU/KN4LJifgpUsU6YlM Z3jVFjcgyFfiQCkq1PvYcUZRRtT1tvkDT+E7VsMWyWpeKz8qsjFZ482yudfcDkD/dT6q HQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqk1chapk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:25 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J1Fj28040559; Thu, 19 Oct 2023 02:31:24 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3trfypjxhn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V/nhgas79P7pP71Nxgs0aUU1PQkE9YrVvyzTq97LRA1yUa9TNG5nSmpuR9hJmaDLqgIL0oz5e4SslC6Rl3gHNwIuiCDwc/uufwj2Vi5L7eFtBgGKIpbBF5i5Vs4H15CDF9LOnXY4WdIaSk2zqT1s4s94j00LbgcBbHCHPajLv0IxLQAxGygJw0IJwD9kEOcWW1WOa4UYBK0A0vhV35WTkLHQxd47ug3/BhW1ynfVuTUsWHGNNaLCX4bICb8amX0ynSzDhiNuToggSqTqGwCxoriQ+jtNKxI8VIPZb9krUwfGPRMaqDL7cxKGV2WxtZ6YhyXtwfwH/MaB83wxrGpCRQ== 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=4c5IqZK42Vm4yM8Bv7kR1mooPI8YiFYT1J97EnWLS/s=; b=UOHHqA2BLD9KMdN3faPB5yOzQtzSByeIqM74Q6jJEZjwXl5/M38y22MAI+zuAFfKKzfRWVyVi7N0rwC+o8rgHDGCe5I37eOKneW41i25ARZE1F0SodS0drrVQfmuWz9ohawG0RjEjsariMzKvG6HydMvX+7pxVd435C3E+wcrTvU9dSpEf8PXwj2pWkEEh5rsLUl34AcD+QNPSZk0La6wIUfFHYHX/mhhIgE68qDnRYrHQuCPzAnpUiN/2nVunnj9ApQqkOLvGTXuFX01MVLU+IEw5Vk8njNAseqYfi1UM3fBr72zuVFw9zqkqyukylLF+CJsYLMqcAL5FIspuviXw== 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=4c5IqZK42Vm4yM8Bv7kR1mooPI8YiFYT1J97EnWLS/s=; b=dEq+5mg78AiS8N6cx4JtjHRAU5xjt6rEZG5Ca0fOl3hkRip5+XB7dZeerisXy+mk73jV3q3uwVzsjvYvt2TpFiVJL3vKi/D6QbnHjATxrmSeI9BjyM3+ke5a+/SeNqzHPJ15KAXCCGRGQRw5Ld41RVpsSKTTjgZhpUecCRRR52U= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:22 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:22 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz Subject: [PATCH v8 2/8] hugetlb: restructure pool allocations Date: Wed, 18 Oct 2023 19:31:04 -0700 Message-ID: <20231019023113.345257-3-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR03CA0141.namprd03.prod.outlook.com (2603:10b6:303:8c::26) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: 6512acbd-ea0c-436c-d4ed-08dbd04b7c0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ol85U+C30utmZk6axs3LWe3ZV+1SheXMaAwL/GXzh9Tnx6v3CzwWgcIlJv61w2etIyH5e0mJmVZkPWRSfxyiZ67SmYJwo+uXw2FKqOAzzp8GnpwwbHgX49bHfnm5k2e5RfZAnBGU7p0SKUV0cGYxMmhEfIY9fGEDADzHgvYA93yvTnGhrLNvNbFLKYWYbWYlDZz2hvv8xPF754Nk79CAeEmSr+8TmBvjsnPSsgNNoQs/GydDxT3ZBA+KeSu7WO2GLL4AWPegBz7BsqyGr47z38cn0EO0w4jh8xFvUhsQccnAaSD54spQIvog0SkHPCJT27nSliJnomiYtuwUDt5ruOoNT5UrB2DGrJEv34texTDNP0qa5x5S2RQS5ORy2Yx8tb3WKxddd8cHPYzCYXpEaD9oCfF06TS6J3Pz27WMarHkv8h1bz29kCUgtM0FgwRwFtbGLTh9gklmYScb6n6nHGMRVy5Z8GnMzwWzPy0cLat1ocr6ojfZcnFL+ckcLAK/9LKNBxYQDtYkLdK+H6bGk2nEV8lqHKRJLI3H7IMkJSOoBVmozaeRv4n2dD5VaJsb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(107886003)(6512007)(8936002)(2906002)(4326008)(8676002)(7416002)(44832011)(41300700001)(30864003)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zLKhoMdufj/dKhbKKHuCbeaa+NtT89uOFRPNwyTTokAiC9a/QTFDRyLmUVmqwt4djdy+PKweyBU2cbuzZ3AUVPqOZ75DlchxGuPKsWMdfUzbXrthmhd1G4gk6BAvSeitsM2GIm9yxQmZO8VaECw1hKzLgd+yOd9o9IVMRpnxBbgZlM/DJ28wpTDq/PGZnG4lYgTV3al4OHfBXJgCPCBP4A3BOc3Bme/dQbaFsCWS97n/UUK55WoWe9nqzgzMFPnoAzNlFAtd8LmMO9skAX8+bEyjNtxczgN/Y0G8N4ibfQzLPCnf/K2vykWNbn+nWHKeDuzDbaoSn2ujBQIYH8U7K3Fhx3wT0x+sh0GcrVhSXSjAE8yGeZStUNzrAq92yQEW0RNT7dkp4SZPTuPrzPeQctezDfBjwCHm491/oaNutOj7zRsnTD/gB6vVYh3cVG2cONHPkiMsfUfxgaWGZqYMYILqMG5rueaK0Xu0kYwu/Rh53IM3seXwtWgb0y/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9fgHYzJRvvANODG69WKavWOWeTewvYrNiaB0psF7GCEDM4HAd9xSYCdf12gb4+ktuypyN9UtZviMCM7fsbObFL89+XXgwlTKQlaicGVUAt49KgXxrzpedIq1S3hfwUK+XdKpr4GN58Asm3iT9Ik05/AiAcHBNYqnbbZTsM4c8nJPCmy1eodKOP8pPhqJD7e6X+VMpjJLWQMCtCzk0Uwl1ZKqfJmCNV4gfqcbuPuucS X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6512acbd-ea0c-436c-d4ed-08dbd04b7c0b X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:22.6696 (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: tk4ynaWvObqcydkrhGU2hFVuKGxNUWM6W2VTurn3eJGusykMsppbQ/fYlbLTTElTQkLAdx4LlvEha29cnIshpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-ORIG-GUID: QLupo6s24mFW_aaMYypAYrj67L93WNE2 X-Proofpoint-GUID: QLupo6s24mFW_aaMYypAYrj67L93WNE2 X-Rspamd-Queue-Id: 751C52001E X-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QV2zbCV /RFwF0DzhF3acIEyGXTF7BfqVcD5csm49OEpH6OWoaW0sFu+VrGeFLUTuys2pXFZqeL2sDdztbaEcmbjlgUd4SOc2dpjxPIIvlKnQMsiX6Y0+dKG3MVGX/N2ewfR9OVLj9fLSfkJLva598Pobf79j+Kv2aXKJgQXIRYAFZfgxBtajJx1WzO+Zc9bPCMzqeGHCbs+/+dcJj7Q1iikEWj51kdRBF6mRAyaQIP3y+6FWw+QMD05BBmhnjlAEhhHa+ipaeHtnOZvvcLywsIll7FEc4aZTpI3sDbPHjcOI5r2tn5p91fYSwk8ZZYS1E3V3WIhKhsJZpkTAUGntFHTxaz+o+dkje2AYTlfbvA/c64pTLX4JIR6bFrHetGNEwArRwTkTcMp1 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: Allocation of a hugetlb page for the hugetlb pool is done by the routine alloc_pool_huge_page. This routine will allocate contiguous pages from a low level allocator, prep the pages for usage as a hugetlb page and then add the resulting hugetlb page to the pool. In the 'prep' stage, optional vmemmap optimization is done. For performance reasons we want to perform vmemmap optimization on multiple hugetlb pages at once. To do this, restructure the hugetlb pool allocation code such that vmemmap optimization can be isolated and later batched. The code to allocate hugetlb pages from bootmem was also modified to allow batching. No functional changes, only code restructure. Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Tested-by: Sergey Senozhatsky --- mm/hugetlb.c | 180 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 141 insertions(+), 39 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b839080a2a6b..559f7c71c596 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1996,16 +1996,21 @@ static void __prep_account_new_huge_page(struct hstate *h, int nid) h->nr_huge_pages_node[nid]++; } -static void __prep_new_hugetlb_folio(struct hstate *h, struct folio *folio) +static void init_new_hugetlb_folio(struct hstate *h, struct folio *folio) { folio_set_hugetlb(folio); - hugetlb_vmemmap_optimize(h, &folio->page); INIT_LIST_HEAD(&folio->lru); hugetlb_set_folio_subpool(folio, NULL); set_hugetlb_cgroup(folio, NULL); set_hugetlb_cgroup_rsvd(folio, NULL); } +static void __prep_new_hugetlb_folio(struct hstate *h, struct folio *folio) +{ + init_new_hugetlb_folio(h, folio); + hugetlb_vmemmap_optimize(h, &folio->page); +} + static void prep_new_hugetlb_folio(struct hstate *h, struct folio *folio, int nid) { __prep_new_hugetlb_folio(h, folio); @@ -2202,16 +2207,9 @@ static struct folio *alloc_buddy_hugetlb_folio(struct hstate *h, return page_folio(page); } -/* - * Common helper to allocate a fresh hugetlb page. All specific allocators - * should use this function to get new hugetlb pages - * - * Note that returned page is 'frozen': ref count of head page and all tail - * pages is zero. - */ -static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h, - gfp_t gfp_mask, int nid, nodemask_t *nmask, - nodemask_t *node_alloc_noretry) +static struct folio *__alloc_fresh_hugetlb_folio(struct hstate *h, + gfp_t gfp_mask, int nid, nodemask_t *nmask, + nodemask_t *node_alloc_noretry) { struct folio *folio; bool retry = false; @@ -2224,6 +2222,7 @@ static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h, nid, nmask, node_alloc_noretry); if (!folio) return NULL; + if (hstate_is_gigantic(h)) { if (!prep_compound_gigantic_folio(folio, huge_page_order(h))) { /* @@ -2238,32 +2237,81 @@ static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h, return NULL; } } - prep_new_hugetlb_folio(h, folio, folio_nid(folio)); return folio; } +static struct folio *only_alloc_fresh_hugetlb_folio(struct hstate *h, + gfp_t gfp_mask, int nid, nodemask_t *nmask, + nodemask_t *node_alloc_noretry) +{ + struct folio *folio; + + folio = __alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, + node_alloc_noretry); + if (folio) + init_new_hugetlb_folio(h, folio); + return folio; +} + /* - * Allocates a fresh page to the hugetlb allocator pool in the node interleaved - * manner. + * Common helper to allocate a fresh hugetlb page. All specific allocators + * should use this function to get new hugetlb pages + * + * Note that returned page is 'frozen': ref count of head page and all tail + * pages is zero. */ -static int alloc_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, - nodemask_t *node_alloc_noretry) +static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h, + gfp_t gfp_mask, int nid, nodemask_t *nmask, + nodemask_t *node_alloc_noretry) { struct folio *folio; - int nr_nodes, node; + + folio = __alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, + node_alloc_noretry); + if (!folio) + return NULL; + + prep_new_hugetlb_folio(h, folio, folio_nid(folio)); + return folio; +} + +static void prep_and_add_allocated_folios(struct hstate *h, + struct list_head *folio_list) +{ + unsigned long flags; + struct folio *folio, *tmp_f; + + /* Add all new pool pages to free lists in one lock cycle */ + spin_lock_irqsave(&hugetlb_lock, flags); + list_for_each_entry_safe(folio, tmp_f, folio_list, lru) { + __prep_account_new_huge_page(h, folio_nid(folio)); + enqueue_hugetlb_folio(h, folio); + } + spin_unlock_irqrestore(&hugetlb_lock, flags); +} + +/* + * Allocates a fresh hugetlb page in a node interleaved manner. The page + * will later be added to the appropriate hugetlb pool. + */ +static struct folio *alloc_pool_huge_folio(struct hstate *h, + nodemask_t *nodes_allowed, + nodemask_t *node_alloc_noretry) +{ gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; + int nr_nodes, node; for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) { - folio = alloc_fresh_hugetlb_folio(h, gfp_mask, node, + struct folio *folio; + + folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, node, nodes_allowed, node_alloc_noretry); - if (folio) { - free_huge_folio(folio); /* free it into the hugepage allocator */ - return 1; - } + if (folio) + return folio; } - return 0; + return NULL; } /* @@ -3302,25 +3350,35 @@ static void __init hugetlb_folio_init_vmemmap(struct folio *folio, */ static void __init gather_bootmem_prealloc(void) { + LIST_HEAD(folio_list); struct huge_bootmem_page *m; + struct hstate *h = NULL, *prev_h = NULL; list_for_each_entry(m, &huge_boot_pages, list) { struct page *page = virt_to_page(m); struct folio *folio = (void *)page; - struct hstate *h = m->hstate; + + h = m->hstate; + /* + * It is possible to have multiple huge page sizes (hstates) + * in this list. If so, process each size separately. + */ + if (h != prev_h && prev_h != NULL) + prep_and_add_allocated_folios(prev_h, &folio_list); + prev_h = h; VM_BUG_ON(!hstate_is_gigantic(h)); WARN_ON(folio_ref_count(folio) != 1); hugetlb_folio_init_vmemmap(folio, h, HUGETLB_VMEMMAP_RESERVE_PAGES); - prep_new_hugetlb_folio(h, folio, folio_nid(folio)); + __prep_new_hugetlb_folio(h, folio); /* If HVO fails, initialize all tail struct pages */ if (!HPageVmemmapOptimized(&folio->page)) hugetlb_folio_init_tail_vmemmap(folio, HUGETLB_VMEMMAP_RESERVE_PAGES, pages_per_huge_page(h)); - free_huge_folio(folio); /* add to the hugepage allocator */ + list_add(&folio->lru, &folio_list); /* * We need to restore the 'stolen' pages to totalram_pages @@ -3330,6 +3388,8 @@ static void __init gather_bootmem_prealloc(void) adjust_managed_page_count(page, pages_per_huge_page(h)); cond_resched(); } + + prep_and_add_allocated_folios(h, &folio_list); } static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) @@ -3363,9 +3423,22 @@ static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) h->max_huge_pages_node[nid] = i; } +/* + * NOTE: this routine is called in different contexts for gigantic and + * non-gigantic pages. + * - For gigantic pages, this is called early in the boot process and + * pages are allocated from memblock allocated or something similar. + * Gigantic pages are actually added to pools later with the routine + * gather_bootmem_prealloc. + * - For non-gigantic pages, this is called later in the boot process after + * all of mm is up and functional. Pages are allocated from buddy and + * then added to hugetlb pools. + */ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) { unsigned long i; + struct folio *folio; + LIST_HEAD(folio_list); nodemask_t *node_alloc_noretry; bool node_specific_alloc = false; @@ -3407,14 +3480,25 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) for (i = 0; i < h->max_huge_pages; ++i) { if (hstate_is_gigantic(h)) { + /* + * gigantic pages not added to list as they are not + * added to pools now. + */ if (!alloc_bootmem_huge_page(h, NUMA_NO_NODE)) break; - } else if (!alloc_pool_huge_page(h, - &node_states[N_MEMORY], - node_alloc_noretry)) - break; + } else { + folio = alloc_pool_huge_folio(h, &node_states[N_MEMORY], + node_alloc_noretry); + if (!folio) + break; + list_add(&folio->lru, &folio_list); + } cond_resched(); } + + /* list will be empty if hstate_is_gigantic */ + prep_and_add_allocated_folios(h, &folio_list); + if (i < h->max_huge_pages) { char buf[32]; @@ -3548,7 +3632,9 @@ static int adjust_pool_surplus(struct hstate *h, nodemask_t *nodes_allowed, static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, nodemask_t *nodes_allowed) { - unsigned long min_count, ret; + unsigned long min_count; + unsigned long allocated; + struct folio *folio; LIST_HEAD(page_list); NODEMASK_ALLOC(nodemask_t, node_alloc_noretry, GFP_KERNEL); @@ -3625,7 +3711,8 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, break; } - while (count > persistent_huge_pages(h)) { + allocated = 0; + while (count > (persistent_huge_pages(h) + allocated)) { /* * If this allocation races such that we no longer need the * page, free_huge_folio will handle it by freeing the page @@ -3636,15 +3723,32 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, /* yield cpu to avoid soft lockup */ cond_resched(); - ret = alloc_pool_huge_page(h, nodes_allowed, + folio = alloc_pool_huge_folio(h, nodes_allowed, node_alloc_noretry); - spin_lock_irq(&hugetlb_lock); - if (!ret) + if (!folio) { + prep_and_add_allocated_folios(h, &page_list); + spin_lock_irq(&hugetlb_lock); goto out; + } + + list_add(&folio->lru, &page_list); + allocated++; /* Bail for signals. Probably ctrl-c from user */ - if (signal_pending(current)) + if (signal_pending(current)) { + prep_and_add_allocated_folios(h, &page_list); + spin_lock_irq(&hugetlb_lock); goto out; + } + + spin_lock_irq(&hugetlb_lock); + } + + /* Add allocated pages to the pool */ + if (!list_empty(&page_list)) { + spin_unlock_irq(&hugetlb_lock); + prep_and_add_allocated_folios(h, &page_list); + spin_lock_irq(&hugetlb_lock); } /* @@ -3670,8 +3774,6 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, * Collect pages to be removed on list without dropping lock */ while (min_count < persistent_huge_pages(h)) { - struct folio *folio; - folio = remove_pool_hugetlb_folio(h, nodes_allowed, 0); if (!folio) break; From patchwork Thu Oct 19 02:31:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428191 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 77110CDB483 for ; Thu, 19 Oct 2023 02:32:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9A5E8007D; Wed, 18 Oct 2023 22:32:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4A8080074; Wed, 18 Oct 2023 22:32:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4E528007D; Wed, 18 Oct 2023 22:32:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B466380074 for ; Wed, 18 Oct 2023 22:32:07 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8944314108D for ; Thu, 19 Oct 2023 02:32:07 +0000 (UTC) X-FDA: 81360636294.22.C825FDE Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 306A44000F for ; Thu, 19 Oct 2023 02:32:03 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=mNVJ2XFB; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=aQSKQ9mo; spf=pass (imf01.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682724; 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=8r2l1Or7Qj9qRoidjA9mZu05EoMF0cTpWPoXgE8Q2W4=; b=YxS4egY+hXZixo/GLxxWzOvC0k26oBdyQK4UvIcUnGvyz+7MUsAXo3jJGdQLgNjUsmJthV NXJE2T3sIL2jmwBB3wFX8skKOXSHapy+qVM0Q3TpyIsSNj4wY6Ae+UOifgAWuK6Syj48I2 7td1hgNqTiuFhmobLj5dunghGVmedGM= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682724; a=rsa-sha256; cv=pass; b=nNrOb0xOcOSvS+SunpCaNsr2ERjrTxRzVUU67yF4lDuAVKPomc5JZVDc/xpuzLvpfivpcf zYB2afgCD4X3RTsMHCjwqAWcNS/IBwN3rF8it8VOVFMjFJ+LRpHEofOEOCnG54yAUAEZ7Q H7G61OWh2lFGPOIu2Dk1pfV2A/m+ohI= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=mNVJ2XFB; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=aQSKQ9mo; spf=pass (imf01.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IIp68H019566; Thu, 19 Oct 2023 02:31:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=8r2l1Or7Qj9qRoidjA9mZu05EoMF0cTpWPoXgE8Q2W4=; b=mNVJ2XFBwfNoTmTbxzmvibG6lEp74QnqfHwO71GmtuPumdaUbCo/arLA28m73DEnbKX5 E9U2jT1HSmnQM++Ykbk4EMedsyBfWwBJBtkhp0hXF4tx2wVZHxpXDYZSktUonRsUmQsf Q6vv1bmYoqXMX+paJmlhbiwN5yWkNjpUAOXpeXl5ku0XMISvjVXxIihF2zjegHSwFDJo M8jPQhAjuJkmgYvrbCOIGdPP7+hNkB03nL5ylh0otJVX8RUSo39vKxvTTxu/21ws+6UI Yvn+lE4yAedqv6Bsq7l+MrJ/enXUbrqtQm/3qEOnuZG+JaS5IPQQAfNWBxBtRRGDvmfI pg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqjy1h57f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:28 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J1v2ei021568; Thu, 19 Oct 2023 02:31:27 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3trg539w05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QMTVGVYc+lUFA3ppGBDmczb0kuK/MAuJKFFcM/TZw5q6L9KpF865slyDve6xgRvGZ7C2fDP9OzE0o8+Qvv0lkmRYcNl2Isp2/vLdIXQaiQc25s1AgXQRMBxChsKL7X8Ss0STtTsrUL0+4ORaH2xIAdEdtCvM55TPpicC0eQsJl0337c4PMgaoJeZe9kDrdwlBjY+pGbfZueqNFEkbr8/nG4i/had85k0S1mVWFOO1MyjUAcqIAOSnDjhZ9v+l7co+WYYruTEPUbO81ogRPlmTHE0Ds+ylWMuiUGx2IExlDm7533lkYBTzWsBxAzWwue08TB3umzVjyqRbTAcDTzcvg== 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=8r2l1Or7Qj9qRoidjA9mZu05EoMF0cTpWPoXgE8Q2W4=; b=ipiWpJc4WWwTyJmV+cNH5JG/EEkq0HhHdMq3s3dNOYX3BojVTd2v5fnxW4XDw9ovAoxEUIylNfOdKgz+/T0sh3F3jzSckFSXR8SZh8u/87n7piNLcxp8NupaXonSW/axRfOvJrCGmphUU57xzqKSUwwfSd4w537uCAgPfdDX7tBSXlzLCLMeWD2g0xxzfXJ3bQvjRHgSLXjkuI/Lu1IJjrp+28sgUsRB2k2TENuZZRwiFW4v6tdO0SYNNqMTSe1yRxG8EHhIpK3xr+iwBVu/nuP7Wgkv4upwH8g36chU933zNVMW4ll5xpTssRQwS8Regxnu258LpRIj/UWJ/305bw== 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=8r2l1Or7Qj9qRoidjA9mZu05EoMF0cTpWPoXgE8Q2W4=; b=aQSKQ9mo8ZEdeNH5nZ1T7zrpw6WNL2c079P2GHNil0hS02qc8y3oTQgpnO2hOtLkW1GClusfoVlrjvXcWM4IkAkoDRqLWjPAb3pm21F3ZDAP8f99dhkxqw84A90OQA7jIGEGK4W5vCCea7GxpxiU+gEWW6XXN5czYz+7kTdCUr8= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:25 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:25 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz Subject: [PATCH v8 3/8] hugetlb: perform vmemmap optimization on a list of pages Date: Wed, 18 Oct 2023 19:31:05 -0700 Message-ID: <20231019023113.345257-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR04CA0322.namprd04.prod.outlook.com (2603:10b6:303:82::27) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: 25acd7a6-c705-4aca-d65d-08dbd04b7da5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4dBZAFNB3bSmlIzfck9KyqlwHScQhvOzLzbSYo4nTk8My5BNBMOgAcufArANNvufEqX9GUDVYlr56vcCKwm8JZuMc8+6d/sq4w4k1relyi1aekFdZYjFLbjvsuHljzWcbPGU0VUFvp7CjtHSmdW1z1NzIjFc+C+2hJUyPV/AqgFt4rONLycNgPfkoJ4Y4T6+aUTY2qB2VuJxwEzOPy0sMOVCAfIMdy8d+1t8m4ITAhnelaWr8UlZljnUzPEXTly5mQbVUaDyrw8lZxCJ/wBrNEB///ghKkKb5r2UVQ7niOOxSyhcYKFxJpCxMCjVaTlK2axpm9A3tmxyIIDmkB1pqYmZYY7AG9TqJ7GTnsnwYlIWuVCYGNxuPDedednSf6MaOMF4x79G3qGW9ewyFTQ/7ZvkxHcQ/oxKvtLV5brvGBAQ3J8hUziQkrDfy3/v8MhykKRyQmk4Tdc/60u793CkS8AS96dm++oCN4upwbgk7awBxsFyiBNs0+EHx2cBhdu8zdg0nWqKIXdn3xyZsf7a1rYh/vPu5Tmf5Q8T5pguis9KHf+KNCY+7IBfk9gU2Oyg X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(107886003)(6512007)(8936002)(2906002)(4326008)(8676002)(7416002)(44832011)(41300700001)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /EG/6gl6/mWFNXw0eiqCmPlHYfNUhG+MLrxZx6JTkM8fzDW4dgfkkB9PNPUvPtn8xp2vmlK22QlcPyN3xvUqBrMBvBk1y+EFOBxRzCQJRMqW4XYM4lkIy27OSaI1Ss2MFK6XP2uV5ZR35HhBbtfM7y0rU1rQfLvaEcJhrEZvvepa3XCSsH+K4EvhDWj2hWc3fDjGKuAivBwyE9kobjG8WBjlBayRcH/ce0zuU7MuX5NzzmwW/jiRm0hiYcsY2QJFbTEKF7fqy4wIUk198HGhGdy7LFIJSfVMUGaZU0h0yfyWM9mv+xHRFwXptbmmC0YaTfQ5BEcfBq0ZCs3dFOX3iC8vD33Bl966GP4I2MtcJFGHTIFb5PlzeHrNLtf/MZWwtNJ/ugKI8AOVrxGbLkQCz3VULTG+X1es0GFzOFX+oIF1PPZ9leheIEWuRAL1QqIYgbgM/S5DeKBOG7OkZYc3a4Nu4J8++Ogvc7AhpYXcq9ZKUbPwZ4t4EppfNm2EADPyxD5Hcby/yeW98TLzp12YLj2Q3hZavP+cTWp4mmtdgSjqz7KtI7Z/++lvjgCGy9pIMQpSkV424pXSznifaNJDfV1TblFNkGbEqdTZsx9OZcbv1DmhkK07izHl7H3JPY+0UQdfQeeqPIHfxSaDV6jR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YekglcpktP07g8WvhLkz+uFOyDvOBqo4CPigzDCjMBLlc/LGUPhgbnWf00+qSCZTFSV5vZ+AfxI5bzDm X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25acd7a6-c705-4aca-d65d-08dbd04b7da5 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:25.3289 (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: 913NOzdLuCmNHf9Cn7zKvVS643QaZsgmNYQPV4aMnT3yI8TZeBFsWBQOC+61rSqhImYtiZtNtbgH9NCB1vl7Jg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-GUID: _fw7hiRPovR_TVqvzHA3Wm3k3Mm_F8Ij X-Proofpoint-ORIG-GUID: _fw7hiRPovR_TVqvzHA3Wm3k3Mm_F8Ij X-Rspamd-Queue-Id: 306A44000F X-Rspam-User: X-Stat-Signature: gfhjs9q3ysi71xxqbgdobjwsd3hgjonq X-Rspamd-Server: rspam03 X-HE-Tag: 1697682723-982863 X-HE-Meta: U2FsdGVkX1/O42cHeSfMz5BY+0DRcGxl+m63xUcezD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zeejvZcNSJWOfo3h71ECG3CQ7w3SftmKIAhF16ZNn+O3TFPKwL+fnkMvC0C8Jk1xjErfqhixlXLpldGwTaTgVyl7UDOfOcQ8yRB372srH92u2sHdYfXZNjBlIMDMW7tKdvP2A5+l2mprFyi/S7J2XxW4yhTv/nTPYQLNyxUU7YUTLPKtSHNDbATr86rgCc6kbbwOE7YReVxZqf3Ublg8Bt4bhmFVhJnKuvrz+X7+F3rBw4k 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: When adding hugetlb pages to the pool, we first create a list of the allocated pages before adding to the pool. Pass this list of pages to a new routine hugetlb_vmemmap_optimize_folios() for vmemmap optimization. Due to significant differences in vmemmmap initialization for bootmem allocated hugetlb pages, a new routine prep_and_add_bootmem_folios is created. We also modify the routine vmemmap_should_optimize() to check for pages that are already optimized. There are code paths that might request vmemmap optimization twice and we want to make sure this is not attempted. Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb.c | 43 +++++++++++++++++++++++++++++++++++-------- mm/hugetlb_vmemmap.c | 11 +++++++++++ mm/hugetlb_vmemmap.h | 5 +++++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 559f7c71c596..8b171f866d0a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2282,6 +2282,9 @@ static void prep_and_add_allocated_folios(struct hstate *h, unsigned long flags; struct folio *folio, *tmp_f; + /* Send list for bulk vmemmap optimization processing */ + hugetlb_vmemmap_optimize_folios(h, folio_list); + /* Add all new pool pages to free lists in one lock cycle */ spin_lock_irqsave(&hugetlb_lock, flags); list_for_each_entry_safe(folio, tmp_f, folio_list, lru) { @@ -3344,6 +3347,35 @@ static void __init hugetlb_folio_init_vmemmap(struct folio *folio, prep_compound_head((struct page *)folio, huge_page_order(h)); } +static void __init prep_and_add_bootmem_folios(struct hstate *h, + struct list_head *folio_list) +{ + unsigned long flags; + struct folio *folio, *tmp_f; + + /* Send list for bulk vmemmap optimization processing */ + hugetlb_vmemmap_optimize_folios(h, folio_list); + + /* Add all new pool pages to free lists in one lock cycle */ + spin_lock_irqsave(&hugetlb_lock, flags); + list_for_each_entry_safe(folio, tmp_f, folio_list, lru) { + if (!folio_test_hugetlb_vmemmap_optimized(folio)) { + /* + * If HVO fails, initialize all tail struct pages + * We do not worry about potential long lock hold + * time as this is early in boot and there should + * be no contention. + */ + hugetlb_folio_init_tail_vmemmap(folio, + HUGETLB_VMEMMAP_RESERVE_PAGES, + pages_per_huge_page(h)); + } + __prep_account_new_huge_page(h, folio_nid(folio)); + enqueue_hugetlb_folio(h, folio); + } + spin_unlock_irqrestore(&hugetlb_lock, flags); +} + /* * Put bootmem huge pages into the standard lists after mem_map is up. * Note: This only applies to gigantic (order > MAX_ORDER) pages. @@ -3364,7 +3396,7 @@ static void __init gather_bootmem_prealloc(void) * in this list. If so, process each size separately. */ if (h != prev_h && prev_h != NULL) - prep_and_add_allocated_folios(prev_h, &folio_list); + prep_and_add_bootmem_folios(prev_h, &folio_list); prev_h = h; VM_BUG_ON(!hstate_is_gigantic(h)); @@ -3372,12 +3404,7 @@ static void __init gather_bootmem_prealloc(void) hugetlb_folio_init_vmemmap(folio, h, HUGETLB_VMEMMAP_RESERVE_PAGES); - __prep_new_hugetlb_folio(h, folio); - /* If HVO fails, initialize all tail struct pages */ - if (!HPageVmemmapOptimized(&folio->page)) - hugetlb_folio_init_tail_vmemmap(folio, - HUGETLB_VMEMMAP_RESERVE_PAGES, - pages_per_huge_page(h)); + init_new_hugetlb_folio(h, folio); list_add(&folio->lru, &folio_list); /* @@ -3389,7 +3416,7 @@ static void __init gather_bootmem_prealloc(void) cond_resched(); } - prep_and_add_allocated_folios(h, &folio_list); + prep_and_add_bootmem_folios(h, &folio_list); } static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 76682d1d79a7..4558b814ffab 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -483,6 +483,9 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) /* Return true iff a HugeTLB whose vmemmap should and can be optimized. */ static bool vmemmap_should_optimize(const struct hstate *h, const struct page *head) { + if (HPageVmemmapOptimized((struct page *)head)) + return false; + if (!READ_ONCE(vmemmap_optimize_enabled)) return false; @@ -572,6 +575,14 @@ void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head) SetHPageVmemmapOptimized(head); } +void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list) +{ + struct folio *folio; + + list_for_each_entry(folio, folio_list, lru) + hugetlb_vmemmap_optimize(h, &folio->page); +} + static struct ctl_table hugetlb_vmemmap_sysctls[] = { { .procname = "hugetlb_optimize_vmemmap", diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index 4573899855d7..c512e388dbb4 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -20,6 +20,7 @@ #ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head); void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head); +void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list); static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h) { @@ -48,6 +49,10 @@ static inline void hugetlb_vmemmap_optimize(const struct hstate *h, struct page { } +static inline void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list) +{ +} + static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h) { return 0; From patchwork Thu Oct 19 02:31:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428190 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 23A2BCDB47E for ; Thu, 19 Oct 2023 02:32:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB36A8007C; Wed, 18 Oct 2023 22:32:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B633980074; Wed, 18 Oct 2023 22:32:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B61C8007C; Wed, 18 Oct 2023 22:32:06 -0400 (EDT) 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 8B16C80074 for ; Wed, 18 Oct 2023 22:32:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5F099810A8 for ; Thu, 19 Oct 2023 02:32:06 +0000 (UTC) X-FDA: 81360636252.02.933B3A7 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf24.hostedemail.com (Postfix) with ESMTP id E6836180007 for ; Thu, 19 Oct 2023 02:32:02 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=0rn0oKPZ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=y7X0EuUq; spf=pass (imf24.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682723; 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=F7HOzsss5pD7Ha2I86cR52DxAyPm8ftvPm1KZ647UUc=; b=e70DI+GpU0jb630CWVL7H1IUhgsWL9J505JolW3SE229oMLsHGjgk6p5cOy83VCquDgj0U Yx1TcbQlJ3jv5MY8yW4fVfJkNf1hmFJP7CLWNfRpDFe+u1lVqYcSEFa+JwkojMWJSiRUrS TdzPWmI70Hm7q6NGNZBliq+bWRbNgpg= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682723; a=rsa-sha256; cv=pass; b=thSyW/AjxZWIrUM7+WZFH1iNZNg3bH1on+LwsRC+p+j61qY7jClvfiFw244f47RFXoNIvN SYox7Vcrt7Zegn+M0Vf9AawfdtoazjD8cXUSOMKmcbZa62WFUdRhNnkui+EH9KzETiDQqN awTUzLF3vNt4/75t8kEHqm+KEd50bYU= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=0rn0oKPZ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=y7X0EuUq; spf=pass (imf24.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IIp6nE018131; Thu, 19 Oct 2023 02:31:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=F7HOzsss5pD7Ha2I86cR52DxAyPm8ftvPm1KZ647UUc=; b=0rn0oKPZCd5LEFplhcFa+6zdjZCWGJtGUrUpAw+jP30KfjkM8l30lLfdXNihZ5fwVHj7 lDZ9NzpICfZff8Z76dt3UQq89B9VMRcsYTmVPi4yXbc2eSXdZER2SlUVT7dNok289Bb3 0KOqmBPQWOB9SEat8YAN6iqiIJoCDUj3yDMPIlu5RduCdwrDY1LH2dpRvWKGM8jdZvqN NSn46lrHuRiqHygHWXe8EW2p2AkmnGfaPOjRvOvc3agdmxNBiJlPTdEGqSqBFMuCTysX m38eEp4cvLhjDGz2Wd3YBUIgz8MDjhzOaYGHGvnDwWKLACXjjcfysHVVadTiaXGUAgGJ bg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqkhu993a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:33 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J0lDbK009825; Thu, 19 Oct 2023 02:31:31 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3trg0q30gr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dhtCihzeYcANU4Objz1xO03a1QTczQpsTqX1XfEvYEj18uDXAp/9lPPjkDtu7hqMrUmK3lbdOqyqZiVQiVSopeQMOLlb98Q3qNqf5U8ThXq3QiJujlytmz7sKAkcieDR8s/UD9ostJedkiqaqHZheaXrfKqqsALy7wboD0SxB/MRoRAm04JWQhitydcTZZjGScYEgTJsPs+VLsmBQ1Rg8mVZk5JKQRjo1EtO6eRZm+kAPJOYZroi3+q/2ZA9Tl6Ludir7w+LyKWtZwR6WncZiKv86pX91yLuZZdRdE/tBMen201Vw8XD2lGDpUziXsW7hOdwReD/SOY3tWlnsEDj+g== 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=F7HOzsss5pD7Ha2I86cR52DxAyPm8ftvPm1KZ647UUc=; b=XGIfBjqxOq59H5myVxxT8kSqsenHU9WaydgVDnte9XMcvZjWfWDlUEKUg7Z8rxvVKOHwxBYZ9GWGHziJcdP862bojI1EkbbDtfhBpyFXZiQKzEsrFigssSWWWNt796xNSniWPLBbQIb1gE5NFEZjlRD3CGbCpQ8uMAQ628vOIv82q11hUE9h1TzEoU/Tgz+w+chDZIL0dgeKVLFLNWSsx07eC7vKeaHc2VAQ0w+Kn86YDhnW+IDb7VNQa+LYpeSqTJCMjQWQ98cJ2ckLRgWnJC9G1biJQwpGmNkM22kI/99qa3Ozan1fvvCxcEuHBVXQfjDRv4iX4cN2zRxE8RF3Og== 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=F7HOzsss5pD7Ha2I86cR52DxAyPm8ftvPm1KZ647UUc=; b=y7X0EuUqT/0Jr2U4J/TR2wdC5/zgHRN9nA/Kmli1jCtM9cXxrzC/3MY0PnrldTpbah0ru1Jw/GeRBMWn/C/gABm4hf2Nf6SFnzBt3ZYsGi/3nhqOiORq0kQu8+XoPoy4mhfibnUO1q+kAyqNvd8GKYrNu2ZXaVIZNbL3k4KX4YY= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:29 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:29 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz Subject: [PATCH v8 4/8] hugetlb: perform vmemmap restoration on a list of pages Date: Wed, 18 Oct 2023 19:31:06 -0700 Message-ID: <20231019023113.345257-5-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR04CA0188.namprd04.prod.outlook.com (2603:10b6:303:86::13) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: ff2fed62-3252-440e-8b11-08dbd04b7ffe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wJDSH4W6/HwrGXXwlO43hqe2b0Q34iQctJ9S7FmovMQD1JTTzPE/mKSWCqSKLVMNmI2SKWVcox5BQVzwRoSSU8qsDwLzYKG8/s5Hk/sEsHH2Fofe/KrILtMzKLD6n9Kpwvi118QE/6ZL6VBReWAE4Jx+5LwozECwkwSA6vqeeRS4Hq9PNmnymF+atlNSlsmjqeRdwGzg7snlVTwv1e9D01A9mH7ujo+6N/1eKB/XPfX2QyzVx6QQjOfAIgQWksF/v3tlgAnF4yncjmvFESFiVZZm6VC+00hrFKKJHKrxVvK86vrJdLZAkl8hChNRAdoldGks6fFc/ViIo/IX9A6UjWL1VomjikTzoip6Zxky+oYyLQep3O5SVMkxvRDCAc6m/Nlf52jOfdRwDVmzAP+wQId9kgq0Dg4sCnZCvNTtVdnJUBOinO1XhBR4rjANvg6L9rWy7zVrsJUfbtP8JgBIXP/kSRl4q1TrnzDTNcTbG+FMKj/pmOeCNgEaDdbegko1oVnB+a6w/omWxBcFNXPO1TjZw4x+BGJM8rMVwjqpRQSiB1EtiC5S+yVdHIvtQjd/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(107886003)(6512007)(8936002)(2906002)(4326008)(8676002)(7416002)(44832011)(41300700001)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-Message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1TLeMP7Biw14F77BS0t4qDnNzRVvdd6vkPW/LZxusBeJ/4CBLNikeWra/fIsvAtIc65yjlrFsARtiW5zcvf0BZTJbC3sLzXLLJieg3Y3dsIIp7sA/d2fkr7ZQ+atEgGP11zKRVgmQrVCTFHIcsrWfWr0w5ofg0rbGa9pOxUt/x4HAM5y8yG4SS5eL9LFThTraHUdyANAYknX09uAZ03o3TLyMDEYwrshSofookSDrES83OMJOhOQ1I9vb9UdjkIQh9pUyfLQn15QvGCxE966Z+Q7bIyGuarRi2xmVkeyNiuGniloazahab7ZXLF19US33zNorqWgbomeisaRimy5QxvyLePrXATf7EQ9wD9nxdeNDE4GEmdCYLuYr5w57TRcfMYZhsIYv73YyDKTcqjC6R8sqfwiv9x/SsidZ3VVJUWd5Y/PEtCX9tXhtZMizTA30O9+JzXanDor9ZROr6Ny/j21MXog1NMFU8+vqrLgeqHxs5cbj0hBSvaPM/hJ7pSg3g3h+/jrtVzNSPvq/yM2UZwcThQwxR1+s3r3eFZzZnzO7xMb/xzQ+8hjnNhq+Kgw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: yAvtgVevPX6cv2jRFB/LDiomVPD3Mmk6t3JiUqepD74rAj+5eXQ8Mtkmm+4xv5YWcyVJaB/RfuwXHdJ35o158ZXPGyBv5+I2hDDif/niBbVkpmYRAdCpZ7dpXQH8otM5kFlhfi5fRDBNZrpgg7vtpxsksTU20dL6CKaD3+FoaR8vIQxJPOBbVs5TjmQBe43EfbXppordvMi7HcBfVNtqrnqggIJeoz89bW8aTadpGiezTXi/vrzN6qpPyjQJibaKs+OjBY4FofI+HMWCDW/WKxNqIvJoxv9LX1Zs1olVefwEFd2LxKZyiirhC8itFlG2CfuaTsG1CE38SR0l4PgsKx7rAG94+uDibliKnsCLl553bdXXTxXKcDCBCIew6uo6/rgiFy3aFjDj7CVLdHRxd4+63+ctPPz/XH74J9t5+oCLb6pu4tft1waYT1G4JoBEkpS9GQvVrgX4F5fMvvLdEW8P27pjJyQ1ZgKk7SNcmJiErELrEaKMRA2zvmLTkmMmdXFoijtHRhgCDeQKqxCRTDsFg4p92yUT/KSQ1FWyopb96K3SsN6JzyuUSUcGA6c+a0F7WyREf8P6Q85eZ9SuOeZrM+29b0UBRcLckQImPyOk9qbBgLv1VDRlEYqTf6hAzl5R0ynN9ISW8wtTGagO/Zxcu9zBr8xme9fQylzonw5KtqjUedaMSAlSc9yVDPyNkklRpN/vuouTQ92KQG4N1GrViL/rHQRr3kW0ydvbJ7Tz/QTi21UXiLbmKlvEglmocIDNmdb9XJoLz/aVcVBi3MfAf/D3HFhAAIzBeKvzQuYkU0yugXRmXclVDgyFCEt529RIHPlU1HoRsrJGl7zniL1CEvMSAr0GRmIkMellMQ6GDwc9YCPKkBLS20Wa4Fbe2SzVt5TYHDOfuIfck02Pi1iUTncVHyYPnbhVzK8ELrI4X1AD/UlaQ39lCtdJgwYv31isdT2a0OmV4aehYdU3I9DtTsAqs/ecfDjRS7a4WC3lfSd/2z2oECtNXqY9CMh3GdZ/JAGHqV2t4hdScxvtD1+l6PECXGiUeOQSlEp1ckeLBWe7sffLqw/Uv+j+JkgOYJm6kKD0F26voEQ38CU4QSQ+h2kPElgp+TXd+T8FPwaEPGt1H9ILNdTLBMyTjde1sL2QHK7YAGGzy5RUbZrBXDeBMd+1wW11zKGhLfkP2pPDbYLIzCZx0BGi7yQ/zH/y X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff2fed62-3252-440e-8b11-08dbd04b7ffe X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:29.2612 (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: Nmab/6qFqW3Wh+Bc2tpQw28muoJCUzd2aPOULvOT0uY1mhWj170DEqyftMuZCfHOV8i7J5xxS85BXLRjvV9P0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-GUID: Sn2pgpwYgNkYxnsJNThS7AaSogg-IlYB X-Proofpoint-ORIG-GUID: Sn2pgpwYgNkYxnsJNThS7AaSogg-IlYB X-Rspamd-Queue-Id: E6836180007 X-Rspam-User: X-Stat-Signature: wtaz3pozfropzn3yct6pbykeb36kxcyw X-Rspamd-Server: rspam03 X-HE-Tag: 1697682722-490314 X-HE-Meta: U2FsdGVkX1+K/O90ny+g/Lyk0d2SldOJbedo4qTwFORtyKu4vWc+ziOY4VVi6SjCpUzsdv5FVOrXO1S2SgG/DF0NZhaW1Bz4BL+tEuM1ULR4lAjzjJrHJq6+l6W9k5v2HyPsG1OHpUOvtJ914c5VXIRuP5gt4IlCosSxcxs7giZNVZG35ml3lO7fuJdday9S1tSfoOStC6x/nbtQp2zNhC8QhiOOZpiCYiWkLLvwCS/lpNwd7TBtu+rfrvbuwvBbcrn4kepGYyLSwjpKjTsOzZvfhNHsuEVuSEHwTEmjCWe1i4n4fzezv2/L3SbOvrU4PPygE0DPUK1DitTDqQV1ZETx8xKPZKguDEuORKaRmzYduuKqIg7eAuwvekIZ/EW/PbApO7GcIzX7vt0fseXKIJQs89YwREdtp7hfCII4YhOEhTNA5f6xqkRhtAHsn6mOK913w8+5LdaqNLeyBsinbTNr1itpERL0HQxxPbLOmfYnlBZz1v/oTy0/i//USthU3CHQ8Peb4/QOFFlsYffsd5P6NvOCZaLkpjuHkOMtVeR6Fu7tsirL1pICi0c6Ihm5x9FiHNXZngCzZFdlRHmq37HGubKBgYm2c88cxrIwj+ocgWeEi7OKaOYeA45zyAJ+xB6oJaEpius65Mex2CcY6MfIoZURAqYz2Q5UG3VbbJGejKjivSzWpvpPWfyXhGaTj36coDbk86mmH9j9+WTCWhHERASS1Xm1s7N8PIsMs/G3GyeeYRxEfOp9FWXu4mevGNucdjYCc3wAscvwln322oN6YPnDpMo71y2Y9AtzEfA0ZOFXX4FXfTQtPVlyUBVAH00ScqfBlkwFVKvkfuXJ1BkJ9M8qmWZ51fDYP9hyWWGyUMkdehab3HD+xPcjg7La7TER/i630Bhtt2DrkRdRY06LTSFBrVPCOvFUUcv0WHCNJKovcfVJu/0Fn3ryJzPXE31pqX/oBbuMBQaBBZN E7JyhZ6G dIdeyXGieUK51iHBk9yQw2OHeHAS1LrqlrYSVAJh8h0QcN0g1BIhWavCjwVWF+0nqG0671yqRciXvPIExCCNhotXNbVi/F22ZO4DC/6O0fC5mC90912ndhP/NRDDQZu1RvJDkZ7fTZhiFFIaaG43qyp27M5+00xIO0diUgmpl+4c+L41Ir26YRMhzPChOypA1lLVQ8M6n3WjTrP+qjW7zgZMuao+v2zE0dBiTPBJJPyf/gO43ZV/gVmv6Yeu5B4n7xVN5JQfPcUeOSkHCZfcH2Qb3uXOML4UT6T3lHFHOUGHZJY9SUBLbaV6wX4wpTKrgl9kvYaGtrI1zjj1FcfPsN8b8n7jFPP67kiZPykg1WDLefwqYPQVKec3XvNZmnSASBATo6eS0JFBrjYCAkMhI6gmwgAd3getR2lsLvFvxLAy4IpQsIs2MYgJOTA== 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: The routine update_and_free_pages_bulk already performs vmemmap restoration on the list of hugetlb pages in a separate step. In preparation for more functionality to be added in this step, create a new routine hugetlb_vmemmap_restore_folios() that will restore vmemmap for a list of folios. This new routine must provide sufficient feedback about errors and actual restoration performed so that update_and_free_pages_bulk can perform optimally. Special care must be taken when encountering an error from hugetlb_vmemmap_restore_folios. We want to continue making as much forward progress as possible. A new routine bulk_vmemmap_restore_error handles this specific situation. Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb.c | 99 +++++++++++++++++++++++++++++++------------- mm/hugetlb_vmemmap.c | 38 +++++++++++++++++ mm/hugetlb_vmemmap.h | 11 +++++ 3 files changed, 120 insertions(+), 28 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8b171f866d0a..cf834bb7f820 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1859,50 +1859,93 @@ static void update_and_free_hugetlb_folio(struct hstate *h, struct folio *folio, schedule_work(&free_hpage_work); } -static void update_and_free_pages_bulk(struct hstate *h, struct list_head *list) +static void bulk_vmemmap_restore_error(struct hstate *h, + struct list_head *folio_list, + struct list_head *non_hvo_folios) { struct folio *folio, *t_folio; - bool clear_dtor = false; - /* - * First allocate required vmemmmap (if necessary) for all folios on - * list. If vmemmap can not be allocated, we can not free folio to - * lower level allocator, so add back as hugetlb surplus page. - * add_hugetlb_folio() removes the page from THIS list. - * Use clear_dtor to note if vmemmap was successfully allocated for - * ANY page on the list. - */ - list_for_each_entry_safe(folio, t_folio, list, lru) { - if (folio_test_hugetlb_vmemmap_optimized(folio)) { + if (!list_empty(non_hvo_folios)) { + /* + * Free any restored hugetlb pages so that restore of the + * entire list can be retried. + * The idea is that in the common case of ENOMEM errors freeing + * hugetlb pages with vmemmap we will free up memory so that we + * can allocate vmemmap for more hugetlb pages. + */ + list_for_each_entry_safe(folio, t_folio, non_hvo_folios, lru) { + list_del(&folio->lru); + spin_lock_irq(&hugetlb_lock); + __clear_hugetlb_destructor(h, folio); + spin_unlock_irq(&hugetlb_lock); + update_and_free_hugetlb_folio(h, folio, false); + cond_resched(); + } + } else { + /* + * In the case where there are no folios which can be + * immediately freed, we loop through the list trying to restore + * vmemmap individually in the hope that someone elsewhere may + * have done something to cause success (such as freeing some + * memory). If unable to restore a hugetlb page, the hugetlb + * page is made a surplus page and removed from the list. + * If are able to restore vmemmap and free one hugetlb page, we + * quit processing the list to retry the bulk operation. + */ + list_for_each_entry_safe(folio, t_folio, folio_list, lru) if (hugetlb_vmemmap_restore(h, &folio->page)) { + list_del(&folio->lru); spin_lock_irq(&hugetlb_lock); add_hugetlb_folio(h, folio, true); spin_unlock_irq(&hugetlb_lock); - } else - clear_dtor = true; - } + } else { + list_del(&folio->lru); + spin_lock_irq(&hugetlb_lock); + __clear_hugetlb_destructor(h, folio); + spin_unlock_irq(&hugetlb_lock); + update_and_free_hugetlb_folio(h, folio, false); + cond_resched(); + break; + } } +} + +static void update_and_free_pages_bulk(struct hstate *h, + struct list_head *folio_list) +{ + long ret; + struct folio *folio, *t_folio; + LIST_HEAD(non_hvo_folios); /* - * If vmemmmap allocation was performed on any folio above, take lock - * to clear destructor of all folios on list. This avoids the need to - * lock/unlock for each individual folio. - * The assumption is vmemmap allocation was performed on all or none - * of the folios on the list. This is true expect in VERY rare cases. + * First allocate required vmemmmap (if necessary) for all folios. + * Carefully handle errors and free up any available hugetlb pages + * in an effort to make forward progress. */ - if (clear_dtor) { +retry: + ret = hugetlb_vmemmap_restore_folios(h, folio_list, &non_hvo_folios); + if (ret < 0) { + bulk_vmemmap_restore_error(h, folio_list, &non_hvo_folios); + goto retry; + } + + /* + * At this point, list should be empty, ret should be >= 0 and there + * should only be pages on the non_hvo_folios list. + * Do note that the non_hvo_folios list could be empty. + * Without HVO enabled, ret will be 0 and there is no need to call + * __clear_hugetlb_destructor as this was done previously. + */ + VM_WARN_ON(!list_empty(folio_list)); + VM_WARN_ON(ret < 0); + if (!list_empty(&non_hvo_folios) && ret) { spin_lock_irq(&hugetlb_lock); - list_for_each_entry(folio, list, lru) + list_for_each_entry(folio, &non_hvo_folios, lru) __clear_hugetlb_destructor(h, folio); spin_unlock_irq(&hugetlb_lock); } - /* - * Free folios back to low level allocators. vmemmap and destructors - * were taken care of above, so update_and_free_hugetlb_folio will - * not need to take hugetlb lock. - */ - list_for_each_entry_safe(folio, t_folio, list, lru) { + list_for_each_entry_safe(folio, t_folio, &non_hvo_folios, lru) { update_and_free_hugetlb_folio(h, folio, false); cond_resched(); } diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 4558b814ffab..77f44b81ff01 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -480,6 +480,44 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) return ret; } +/** + * hugetlb_vmemmap_restore_folios - restore vmemmap for every folio on the list. + * @h: hstate. + * @folio_list: list of folios. + * @non_hvo_folios: Output list of folios for which vmemmap exists. + * + * Return: number of folios for which vmemmap was restored, or an error code + * if an error was encountered restoring vmemmap for a folio. + * Folios that have vmemmap are moved to the non_hvo_folios + * list. Processing of entries stops when the first error is + * encountered. The folio that experienced the error and all + * non-processed folios will remain on folio_list. + */ +long hugetlb_vmemmap_restore_folios(const struct hstate *h, + struct list_head *folio_list, + struct list_head *non_hvo_folios) +{ + struct folio *folio, *t_folio; + long restored = 0; + long ret = 0; + + list_for_each_entry_safe(folio, t_folio, folio_list, lru) { + if (folio_test_hugetlb_vmemmap_optimized(folio)) { + ret = hugetlb_vmemmap_restore(h, &folio->page); + if (ret) + break; + restored++; + } + + /* Add non-optimized folios to output list */ + list_move(&folio->lru, non_hvo_folios); + } + + if (!ret) + ret = restored; + return ret; +} + /* Return true iff a HugeTLB whose vmemmap should and can be optimized. */ static bool vmemmap_should_optimize(const struct hstate *h, const struct page *head) { diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index c512e388dbb4..a0dcf49f46ba 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -19,6 +19,9 @@ #ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head); +long hugetlb_vmemmap_restore_folios(const struct hstate *h, + struct list_head *folio_list, + struct list_head *non_hvo_folios); void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head); void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list); @@ -45,6 +48,14 @@ static inline int hugetlb_vmemmap_restore(const struct hstate *h, struct page *h return 0; } +static long hugetlb_vmemmap_restore_folios(const struct hstate *h, + struct list_head *folio_list, + struct list_head *non_hvo_folios) +{ + list_splice_init(folio_list, non_hvo_folios); + return 0; +} + static inline void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head) { } From patchwork Thu Oct 19 02:31:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428194 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 260B0CDB47E for ; Thu, 19 Oct 2023 02:32:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 832868007F; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 745D680074; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 521E380081; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 26B188007F for ; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F0C3814026D for ; Thu, 19 Oct 2023 02:32:09 +0000 (UTC) X-FDA: 81360636378.09.BF8EA2D Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf08.hostedemail.com (Postfix) with ESMTP id 92D6916000C for ; Thu, 19 Oct 2023 02:32:06 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b="CWr//8Nb"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vn3UpKNC; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf08.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682726; 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=o8COXuu6/TtJ5IDPv6UZqVnZDWI+bSmwncS3etnX9L8=; b=ISb4+rTAQFCpUWJ/f6n1huptw9IldoK3kP5krxpFWDzAQBkKTEn94azTIbTa+p99AaYpOG xamiPCygUOiJeBSg2I0INA0eS8dY8C26/yrHK+O4XrMW4OOSOT9CxmnYy6PKBRY6Xtf/im V3jqzL3GWbbu2djwjI0l+imbRmIfXVM= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b="CWr//8Nb"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vn3UpKNC; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf08.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682726; a=rsa-sha256; cv=pass; b=4y27a2IvbRGsutFZ9FQ1EXm/xBxmVcp1KiXDAxaUU4RkdXHUubf1ALB/7nqVLLkFwA+pKz z1gwsCY/+iEDu+j5llrxq2QmErsd/03bif0+QXuajgQ/izUEaMBgSgsPsKFfMjQLDpwM/j CqWP49ck/EFZPO6ReCdIvXB5A1QoSDs= Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IInDF3013719; Thu, 19 Oct 2023 02:31:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=o8COXuu6/TtJ5IDPv6UZqVnZDWI+bSmwncS3etnX9L8=; b=CWr//8NbPtQ8BFSSPCDK5rLmVu+pweQzMh5trGMO4dOGK+a3EvJyWH7/5rPMDw3l2zJ0 yxPGkcGJrafwZUBY3zEE8X3u/g+qa1+uaWcW5D0zr61ssuW1KykiIoyvP4OOdaS40kNl huk2/05sEaFu5VyLoorWmU92kJWh8UoeoArYaHsrzyNjtfsQQpo1iBtawxPjLzxT1GE5 itJfDAUOFMATiSdXyNAGzFGSr+XSjNKMwr9FNaIuuOo+l5YtDugkzH3VQIVtm640IFCI jHTPBInmVfaU2qnvIkqZI9yyi1hbXv7zQGw2Nql3tkZKg2R/dBFe3/7ga46r4GZBtD0h 1Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqk1d167y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:35 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J14qq1021602; Thu, 19 Oct 2023 02:31:34 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3trg539w34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HNQaGVXTjSRwLWAF1sA3ar7VowNFGMkbZ8LJFSYIRwgzaGjn0cLN3G4KM68VTDJhfJDpmLBq8zHadiuUxIlAtuuSovwaVN9+bs5fMLc/OlOZoXq1GxHkkZUe+iHm6+k11atry/NZN2b2qdwJV5aWs5LxaTTprfAkG9NJ6YkXdwo2PYioiOKClB63HUKTiaNERCjewzug8DVFwWEyOXq30P63/1lGETAkemxiQiOyJWTXDYsJUlhdQut7yrQhAcwsFws3hdcvLsZszyAC/spDz/rdyv1h7598Pky26N8ETeJsml1QTx2VbodLKpz/XXQqDtCS4t72Ge6eqWXYgwjEyw== 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=o8COXuu6/TtJ5IDPv6UZqVnZDWI+bSmwncS3etnX9L8=; b=S3YMEV5Rgs3sAjHBJKtxjIp/wYEiPiSPgAOIvjCr2x4/iisHQfwUALR/bO+NnUwwT+ylGxJT/9XY/yokCaaMLBsBrWylNUvf37/rAqP7RM73VF+oeXphdJX8H6pDvYrAF/PNfljOG70y8CmDSVtIdBaH0adYvMsi07KY1k8m/m5WdJkcXWVV2CLXf/SLFmJAGRE0aRWAucHvpqDOInhcEe6Ae+r0tQbEH7qygFSjc2MfY3+LjZ0NUHSym/7ebk2vr856ETlYPAN+Ic3LVLA7XYtbvqPl9bq9HNJYpnoLSkzU6Vw/XutHT2qJ0u/1FPNum17y3jGinyVObDygRyd6Og== 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=o8COXuu6/TtJ5IDPv6UZqVnZDWI+bSmwncS3etnX9L8=; b=vn3UpKNCZYtYNYs6/3DLU8cDTqssB9F/LlBSND1e265nFSDGlNhxRtduL8WSrPFz2fJ0CUrNW911mP/3qedM7iFDPZfiXNYGnOnnf94bpvRoqJHDdDMqp19xWNtfIXfUYJOZDp+ZRPwbWTLFar1RlF4OloMtvGcPy72IgE4McJA= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:31 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:31 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz Subject: [PATCH v8 5/8] hugetlb: batch freeing of vmemmap pages Date: Wed, 18 Oct 2023 19:31:07 -0700 Message-ID: <20231019023113.345257-6-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR04CA0195.namprd04.prod.outlook.com (2603:10b6:303:86::20) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: b3e2d3c6-4fa0-4d09-56b4-08dbd04b815f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tumvawd7qTZvmZpu8YuvwP8PTfpDjhlpCQlIrTNJqRFmAy2DQFO7taA1JxCrcnYCPKE/RdKK9MQ0/wRsly7E6q69YhSHsH7fMIzFL4+b/IClAywGrpU8c7Md67dk20iPrIEvbjK+ty5nGUad8wuPioBN915oN35Z/6sXHwk8IRwM4ZztBlLSY6zIR6O9WcEzgeNI43Mj96e50sgqC/dS9Kvz3Vx+dV1rwaSnjK7RxRIoGB3xP+D6qM2Gj0ki1b1GrSKQYPITtYByaLUdPMMsIPHEEOhiZGwIFtX+3fNg5Ca/AMwfuGvn5lGu2s0ampuYUakrK/ts06CD941E6pDawQ+NmSea7CfenybUHxkPCrllX/NyWa58DMX9tEGCb+dm8x2Qyf7mkOrxVFPBO637TDN2cf0NSHZOmU224ZGyEmOfeNdJP1iQWG2hHbxjnLVYuTcYOlLXsWjMUvqlNm7+OgYTkWvT14eHIHL8XhbPWkhcpLU9Sf86kNvR87ZpAEg/da6gB2naQGMIRPfMRSTv6elj5ric1Qy2eiSBxKyp5PDcBESXFkykuhdifPoE0ywt X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(107886003)(6512007)(8936002)(2906002)(4326008)(8676002)(7416002)(44832011)(41300700001)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZZW5NNxkHWBabGOytlALlQEt+FutEFkn7+TxdJ1NMgGcAJ9kA4GlsR/78vvmj2UUsG2WFFJpMQhHkLNQPvFZF8YcmTzHimqs2sHTVtSr+jL1DWsVOjHjaqkK6nyR72DIM+lBnZrTJ18VvyO/Lwshgjv7LEWTjg/erUQ/FKtBr0UX8cad87me0MdfPlDUP0z+XimtqHVSTGcPuxEi/yxzXWEpQnPnGPfGXMjGfkn0GwjUMu+9velMibd37XKIyg0FHzBuoQ8JYn+E2TVsha+K7h6iFuvGLesADTD67ciPn4xMvZ50M9Lxf2deIYQ2OEz9eiW7fCUihNs4NecWF2LA6M+jnK3e3MCvwHXo/rcZma15AHkAh54+LXNh0JHQSSPSvSSCm2TeEWs+FYKgGjaS/yTzK/ZwA9BKLZTT/FmjZXfLTv19AJwPhQrSu/4ZBjcwTOSsfc/G9RTrt2GRpwIkOZI7ytFY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hLmuWtvjz5IDQfWyh80LPeO+qFNp92j24/41EoZA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: FElUXM4pZfVy/zUBleaWpQdiPGSIQhuOTX0AKDDOEZavDTvdbPjXkLKf1aDU1q6NSUpI50Tx71AGaCwPDom81/JaasjXvPl0WC49i0UlMXK4uulzWRkNOaVzgbDk0zxSOHYB9SEdbADHqH1eytUBY3f2vhBPcGm4DFcv1PvssSRyIUUAfDTVw6hlLNk8Bsqk6t8R4ERgCB0/rJqOFJfxW3xjcixF81SJPazRYX6BIOeRNeFaB+UcjpumoKKTxmtu/PM3pU7Md8eN8ehfFHOSTUqLYruyZMhKPCaBCH0zjMnOMto7PyQRx8ddasiQJ2K0xRmWJx046ZnuspzLoHcW3rlHF2ZErc3a0Bf57zl7YomPtISYwEKrwjZT92bC5z6CbHiOvssKDZZbcA8oj6eexP4F2sV09HeFNzlVgUe5AIeLmmFyBTaE3V7X1ChaMLOsvCdfVCykYl9jVn/epWDF+Br8CBISI7yBfVM91hf7og4bs2X3d0G/yeWcmczNv79lxqo1qz4gPO6t6Xw7czqIy8rrWSDstbLBK1mjEx0u/NgtYPAKZI9PJ1+qPWkmP2QhpBQtaBRsNo+0ptR1qZqaYZKZJoNx/SWTb3ZSA0sYlYaXfLzPJE8mXBbAT/2CjS1MQmrVAawg3oobfRnui/+z//8E29l0g5dFZl7flMT1swKwqSz/33rS4qLhS+r27HO43c4jVJhLDHFrB1N108zG0Plmbko4srD70uwqBxDU1KuWJQtfHncQtekgj4PsCVj7jtzWwt32r5ll9iRPdMpkXEMyClb3D6tMG/fZF1LntJi/T4UYd1lFf34kfGpYs/hqL3tJQa0dhmO5EVLe018QQQtyMImrSEfkhzCfc5Nf5CfcCZ8QA6S89cuXZdnQ8KNosxJf9UowvGgLywEHk1rhrnrY+CEmdc9RHgayXaNbRWPu8QeGzcssyzunNlwM6wmh2ruvoIPIRruTLWubqrBDYL788hcPxPP0en7/ZtljqtifV1HZGiDy1XiPiIYAOI4r3H4u9sJhQzIlm/Z5D57ZixTKo1PF9PBq2+aIm9U1Zm4S5WWi5fxk6eByMEMP0hPSs9j7gnDda+1Pmb18yB2mKLJG7ZEb4qu8XSum01aY5z3P5EtcmQvsC7w+u+QL8ZRE5VvRDGiCjmEbCdQtM1tLzlqzIHFuXgoGPLIArupshkXfyRnGUV3WzXHTEhFYKTF6 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3e2d3c6-4fa0-4d09-56b4-08dbd04b815f X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:31.6623 (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: IB6PUx/72yjRvJu8Yl40s53/JOvfphT1OGtNBDGGov6gUYQV4s4dy4DXdlu17v9gZQnCggOhYjjeDqNXBzHUVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-GUID: CbApSzPz9J45Fy7Qgb_BzFLvIhBy_Iuy X-Proofpoint-ORIG-GUID: CbApSzPz9J45Fy7Qgb_BzFLvIhBy_Iuy X-Rspamd-Queue-Id: 92D6916000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: q3i55hfsknab4u1yje6iyjtkw9hijj7w X-HE-Tag: 1697682726-461804 X-HE-Meta: U2FsdGVkX1/klIbMKTWAFQ9NbTWdxRydmETvzAa/pCp74aXR6qbg30udP2rdVdza4pC4pagI0AV8QQ4S5OK6lag0lHDTiBl/RmjwprH0B5UhwjA5851cKc5YXYNMeJgG1swbxRhWDPkal0BXef3PnpNytc7/N+pPFwZzSvME2olOWgDMf9hzJVIZe5+XCI7EYiLp5X4RYvir75WrrIMqPkpLJxHu8qwSW26ISE5x1dsU7YBQxqOgEsNmBNWY2jmIFetoID2nwdkFFbIpk1sVwxBdyY0uwn5JqRTOFg/zE+oNApCrW55v2PizUJHSPmwrWz4FNiObRkI8z/L77UFgBDM8wgiR73VhIwS1IUVSpnYdcFpmVPYOinIj6xeZK8TstLSvbD+lK737KzjcdWAkbIV9apTIfcfHRWokiPly+wGU/7qkaL3se5ezWRPZWYI1jxgAtcFJo0QTB4Yi0esdAmKQYRpHNS+8GGRZaQgvGS073myYT2G4RtcPM/Xz9txnCyLPpcDFAYPV6QDssrbxVLxUDcIbec57ko6fI+ASWW8YuuJT0YIcOlmoOU2ZGEOVUs0FMeKrHLYgZrFQwJD6XInvUx2m3oFF2jjpY8OgDMIw0HYN9kBlHr6EGu0yKGhU3sRw9Y3at2VqlTpjwTYeidprMPcmyfzz0pypUU/OoiTF8LHFbWzo1WqBKdmZA6pm0DBPuTeLCrAC0IwdXpsViwUNqPek/Mn4ul+aRHz8iavi8QC0hWWmuguy/FZI9uJVF7EBrZXDAFBT96Q1KbjiIFom0RADlUuusZDLOnthSRz+wVNrZrnya9OK1JGsjT8e77Lh7RHBi9b7UOtgDIXUmRT52rcBVMj58vG2+d364MfWfjk7EmQEwGJ56zU7CH1Qw7RyHpu8fW0j5SOIwv0dUVUJAr1ai3KWdfctySWRC9IkN5J+KotKOp9yq8ioB4tXGXLv+MTgbkpkAHoczCg QGYgQ1rr cxy4GCsRfTzPCwZ/0FNs7vT2NsyK1CRysX/POw6FCXkrIyGYmUOqzC9rIAobQknjw7HOXnbYHEIIZq6w8d3Qk7fcbS5MBEmg+LwTqhd9gUJmZY1q6g8xERn5FwJyOr6B9YAykrDmKfJS9cnExYYefcmr/7Z/5Ue4ZobqKuvtdPsdGyLbHwfRAlJEsLHFKm7UEZQZVwMSDPwHLgDaoMaNGHldICadVSM7os+o3slo0L71pciZmfiJkRcviupa5B+0/c+j7haYbosuGZ48bIvjsMQQyaIIL1n3xQvXrkjPX1Pc22sWx/NPCcV6/maTibBbM+Jzgl2XneLWkn4EFoJkfKwSa5l/haJGaBPVby3rarUHqvVWA+sITnrvKNVUnM1qCOA2S8IkN5ykRpYZGlU47sHchGi47tSn9ubdiwztBlr6pZl6BcNiQuqbM20kkVf8HVWRrHqwZSd3pqylbSO6XgqF5Xetw5lwuOeOF 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: Now that batching of hugetlb vmemmap optimization processing is possible, batch the freeing of vmemmap pages. When freeing vmemmap pages for a hugetlb page, we add them to a list that is freed after the entire batch has been processed. This enhances the ability to return contiguous ranges of memory to the low level allocators. Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb_vmemmap.c | 82 ++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 77f44b81ff01..4ac521e596db 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -251,7 +251,7 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr, } entry = mk_pte(walk->reuse_page, pgprot); - list_add_tail(&page->lru, walk->vmemmap_pages); + list_add(&page->lru, walk->vmemmap_pages); set_pte_at(&init_mm, addr, pte, entry); } @@ -306,18 +306,20 @@ static void vmemmap_restore_pte(pte_t *pte, unsigned long addr, * @end: end address of the vmemmap virtual address range that we want to * remap. * @reuse: reuse address. + * @vmemmap_pages: list to deposit vmemmap pages to be freed. It is callers + * responsibility to free pages. * * Return: %0 on success, negative error code otherwise. */ static int vmemmap_remap_free(unsigned long start, unsigned long end, - unsigned long reuse) + unsigned long reuse, + struct list_head *vmemmap_pages) { int ret; - LIST_HEAD(vmemmap_pages); struct vmemmap_remap_walk walk = { .remap_pte = vmemmap_remap_pte, .reuse_addr = reuse, - .vmemmap_pages = &vmemmap_pages, + .vmemmap_pages = vmemmap_pages, }; int nid = page_to_nid((struct page *)reuse); gfp_t gfp_mask = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; @@ -334,7 +336,7 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, if (walk.reuse_page) { copy_page(page_to_virt(walk.reuse_page), (void *)walk.reuse_addr); - list_add(&walk.reuse_page->lru, &vmemmap_pages); + list_add(&walk.reuse_page->lru, vmemmap_pages); } /* @@ -365,15 +367,13 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, walk = (struct vmemmap_remap_walk) { .remap_pte = vmemmap_restore_pte, .reuse_addr = reuse, - .vmemmap_pages = &vmemmap_pages, + .vmemmap_pages = vmemmap_pages, }; vmemmap_remap_range(reuse, end, &walk); } mmap_read_unlock(&init_mm); - free_vmemmap_page_list(&vmemmap_pages); - return ret; } @@ -389,7 +389,7 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end, page = alloc_pages_node(nid, gfp_mask, 0); if (!page) goto out; - list_add_tail(&page->lru, list); + list_add(&page->lru, list); } return 0; @@ -577,24 +577,17 @@ static bool vmemmap_should_optimize(const struct hstate *h, const struct page *h return true; } -/** - * hugetlb_vmemmap_optimize - optimize @head page's vmemmap pages. - * @h: struct hstate. - * @head: the head page whose vmemmap pages will be optimized. - * - * This function only tries to optimize @head's vmemmap pages and does not - * guarantee that the optimization will succeed after it returns. The caller - * can use HPageVmemmapOptimized(@head) to detect if @head's vmemmap pages - * have been optimized. - */ -void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head) +static int __hugetlb_vmemmap_optimize(const struct hstate *h, + struct page *head, + struct list_head *vmemmap_pages) { + int ret = 0; unsigned long vmemmap_start = (unsigned long)head, vmemmap_end; unsigned long vmemmap_reuse; VM_WARN_ON_ONCE(!PageHuge(head)); if (!vmemmap_should_optimize(h, head)) - return; + return ret; static_branch_inc(&hugetlb_optimize_vmemmap_key); @@ -604,21 +597,58 @@ void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head) /* * Remap the vmemmap virtual address range [@vmemmap_start, @vmemmap_end) - * to the page which @vmemmap_reuse is mapped to, then free the pages - * which the range [@vmemmap_start, @vmemmap_end] is mapped to. + * to the page which @vmemmap_reuse is mapped to. Add pages previously + * mapping the range to vmemmap_pages list so that they can be freed by + * the caller. */ - if (vmemmap_remap_free(vmemmap_start, vmemmap_end, vmemmap_reuse)) + ret = vmemmap_remap_free(vmemmap_start, vmemmap_end, vmemmap_reuse, vmemmap_pages); + if (ret) static_branch_dec(&hugetlb_optimize_vmemmap_key); else SetHPageVmemmapOptimized(head); + + return ret; +} + +/** + * hugetlb_vmemmap_optimize - optimize @head page's vmemmap pages. + * @h: struct hstate. + * @head: the head page whose vmemmap pages will be optimized. + * + * This function only tries to optimize @head's vmemmap pages and does not + * guarantee that the optimization will succeed after it returns. The caller + * can use HPageVmemmapOptimized(@head) to detect if @head's vmemmap pages + * have been optimized. + */ +void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head) +{ + LIST_HEAD(vmemmap_pages); + + __hugetlb_vmemmap_optimize(h, head, &vmemmap_pages); + free_vmemmap_page_list(&vmemmap_pages); } void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list) { struct folio *folio; + LIST_HEAD(vmemmap_pages); + + list_for_each_entry(folio, folio_list, lru) { + int ret = __hugetlb_vmemmap_optimize(h, &folio->page, + &vmemmap_pages); + + /* + * Pages to be freed may have been accumulated. If we + * encounter an ENOMEM, free what we have and try again. + */ + if (ret == -ENOMEM && !list_empty(&vmemmap_pages)) { + free_vmemmap_page_list(&vmemmap_pages); + INIT_LIST_HEAD(&vmemmap_pages); + __hugetlb_vmemmap_optimize(h, &folio->page, &vmemmap_pages); + } + } - list_for_each_entry(folio, folio_list, lru) - hugetlb_vmemmap_optimize(h, &folio->page); + free_vmemmap_page_list(&vmemmap_pages); } static struct ctl_table hugetlb_vmemmap_sysctls[] = { From patchwork Thu Oct 19 02:31:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428192 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 D5CADCDB47E for ; Thu, 19 Oct 2023 02:32:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 462638007E; Wed, 18 Oct 2023 22:32:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EC1080074; Wed, 18 Oct 2023 22:32:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12B2B8007E; Wed, 18 Oct 2023 22:32:09 -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 EFFE380074 for ; Wed, 18 Oct 2023 22:32:08 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C571B121041 for ; Thu, 19 Oct 2023 02:32:08 +0000 (UTC) X-FDA: 81360636336.16.F666692 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf28.hostedemail.com (Postfix) with ESMTP id 81B31C0008 for ; Thu, 19 Oct 2023 02:32:05 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=zIzRzaEF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Ts6a96pA; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf28.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682725; 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=3vbONjsZvravfMZFWf/jFmc0JqQCVqxQwTo9QP2uYlc=; b=q5pcI6gyFQwcbQiP/N6Cf+/J02PTKCt8/HpgU4tHBL+h9AhtIWHhJH6rLdG1G+Ew3zpH8S 0sKpQAUDTqFSLks2ateXF6dc5YeqmIYRWgK07H/WjwuzKDCLvebSujEMRasmTrsUjOwMwp D2ehf1M1qRxoskWlvcOcvVuDJZJUFng= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=zIzRzaEF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Ts6a96pA; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf28.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682725; a=rsa-sha256; cv=pass; b=vj3hRket80GEN/2fSPQYjGGGBjWoVTG8uPrkFwAVqfUiF/zG8FpnPCmWXp8i2vM/ikmAsl Ew6IEQqcUeTGpKhJ1Q5xvWLLMQ1JGEBX1dnv0l4E30fPnWENTWlvLOHJUOxxRzyqjmURq+ jouf1eZ8HINkEa//GBXjr4AEkzNDp1g= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IImvgx006156; Thu, 19 Oct 2023 02:31:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=3vbONjsZvravfMZFWf/jFmc0JqQCVqxQwTo9QP2uYlc=; b=zIzRzaEFJL3VttvyiJzJuePNjkl9xmkcG5Vgx47RGq9Oyk8IO6QiaIr7q1kGbPT3en75 bZ9FyjtBc/mZE5VLtdQEn6M1G+/TZoLd3x2jo0dRPyf19gk3fM2PybsQQHHSC2SNoKwb quMJo4aIsfJ5llP49wCs/8hdaLGwRDk/Zq42uZvYPLIS8VdFJuQRWgrcRolRdNQDsXxj 9orz8oriyVZZflsCEoFToW45f8CVQkfJv9O09+cjqGK6Q5/mujNaz0hXVfeD9ySdbHGZ bAR62paulj5wO2KWSE+AIlFw9tvZ2/Zsj6TX5slEuZoBrUwmatdznTvZtSbe+Ft5u9VI zA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqjynh6qq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:37 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J1XXA0028424; Thu, 19 Oct 2023 02:31:36 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3trfy5uuq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nwSXRct84p7n3qNmcCpXrgiXVwhWOM9oyE9HzBUyQ62z6IHYipGHSNjXe+Nqt8dX0CRKx0+sF1VXwqKK+SSR0epWi12efiTQdJe+zM2NRvvwszNxta4hlSBOgjmCu/JAARD4hROOsMDT25klxGSnnRN4juhI95w+L8wf2udOOhcf3Iiou23uZ9fj3Y0lMnrC+l8d1jpTp1VQ5tcDQSF3HmL79yO/kXNhxjNVdaWUwgDU6rPGkzDO1qSWJLnmGJ0JPDK771hXOjbYkLk2AnMxUGl1OMWJVZOqFlODeJlA1UIraQYAXhBhbDMwhi3Mo5gUbNu/qJDqF3IXACQog/PNbA== 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=3vbONjsZvravfMZFWf/jFmc0JqQCVqxQwTo9QP2uYlc=; b=gy8NHHJVKnRJXgT637IGI8p416sOAD7RTVxZu64gp6TWx/I6r6vZRj3C+mnLJdV6Blaw4xB0Yaw5COo5u/1Di3NA0axKJjqbD7v0PnwmnFzvL8G53GyS4PVaV6vdfpt+eqaHC3QhqU5/LS4JEpbVPbhpT4OpLTOKmpbO5s9R2JDMEuVEPVn2FjsdyrC2FAm1pMVKTDmWAu59IGMPSViCP4Jvs4RuHbCSOh6y0EMVfh/VxXKWTOhuh7apK1CPa99pQcKdgapQ8Dqw6iaScQ0qOvHj3z7FQ+Z8N8sc6ecRUJwQ0dwP22RQzv9+lZbDReDRito+R0bkD+KaM9M1sN4KQw== 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=3vbONjsZvravfMZFWf/jFmc0JqQCVqxQwTo9QP2uYlc=; b=Ts6a96pA8vZshVxeWlSNKv9+d4JA1ceBGvSEyy/3yr8QYK2p3AVIqIz0r7Bnjrz7YUjvuT0ZERBAx/05KBJe1rR/44Uou6xSXnG/wGwYExqtFENfXmg+h7A0UEqHduhim1pq1vAEt9S8eDHTjLs1jIA6hUrVOxw0FclRCGkD4rA= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:34 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:34 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz Subject: [PATCH v8 6/8] hugetlb: batch PMD split for bulk vmemmap dedup Date: Wed, 18 Oct 2023 19:31:08 -0700 Message-ID: <20231019023113.345257-7-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR04CA0047.namprd04.prod.outlook.com (2603:10b6:303:6a::22) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: 80db1915-49de-4ed0-a873-08dbd04b82e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mt4DXdd1O5jyJOJ6NHLOURIEQbLFAB5IWcJi8J+mthnWBPXuPX78mHGGwLOnXm+K9XR8IglLuMmC46idBYyXhiTIlLp/vkQ1fQABltzkVt71/8anIgu1IGzsA4Bgy6zeX+aTGrRaxJhZBQMITdzVDjdtlX9dDhzNUCtNRn6P73af7sgVQuFdHGNdIvOtNzzyc99c6duqc3lPl91uHh+ef4FFKBhBW0QB4z4N6zugK6WTeraAvvlcD7PIjGYEcm6NrWico57N9SnNfcAizDFAmenTy3azfRncyMpJwACM/7nzVAHQC0N3+NGd54s5+nssTbTf+idPpf9vF1ehCpCO8jS7/6dN55+i0zX9DKN4peRZNJ8noonag8LRZBrcclDXI0iasgsb9qd4jW9j5B7Qwf9EvzMPVHWG5m3GPApalL8osBEtX2H/9twuZLMJogTbNRIh9vZuOpYTwfpUo7Wv3hDGEzz2/N1gxBM6H1EANpO4hp+m7z6qyzpfk1ETdXTGsXJmvGgRvmX2ENQ/BBz81K0jl377VPVKvSrOh+gj/lbFoby1mLEuk8/nu66LuP/n X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(107886003)(6512007)(8936002)(2906002)(4326008)(8676002)(7416002)(44832011)(41300700001)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xPVPUeohT/zyE+rEBxPr7t11x/0f2Djjl1Yydnusi6N6moH6jfcM1H+unKZTAoxLTDtH082NcfkQVIf5huaXajnmPiaevsqpRCeAZT4UycGKAvumwVmiy6PPNy1hVS/6wvLpyMUwcC03OJOWLR9CfBLU4tlGAVH29ygt8N4U7z/vUSpAVLftKeZ0X4JfltrxMDuKnMOYrVAMEsG5+elYWgUjdKMrt/SlGvUGbwjrOj0jeQTg6u8MMd3emxcD3IoN8ojOUKZkT0iTnu3k6ii5gf0BcaHejTu1YzfT+oMzEntS+t+P+WjV802+XgOtLiIiKVjuTDWWpmVnM/BGA1oS8dFPHRQLlTfMlzGsfIrQkvoy8XJ+PsXZspFri6Bt0KBEMVRkvmbfRvGaXrZ6rvtXbiG2U9x6T0LoCvxUmJ5L/G8sue/8V7r4UPKisIjwEeIVD1b/QZ0lZmh1OUV+E0xZyyLKj2Qy+c5kdwK5EkzCnPQhlHhELU8yDktE2DCakI2PANQKD/gaIG0ysbuvlAEBKwYQTSClcN2wYxXU390+JI80U/FLD5dF6vpg7vaE1qOKUUcKl5lXp0hj8icftjs4g8uv4tsFPncQmk1TjOt+sMoFsMola+97YMzCxEAuUNG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R3URRQn6y4lnNJaYIOC76GAv5WIs8sLkMBi/2p5kWUDwoaCx/LazBi/HnNVQlEtgtOFKdI+WHaq7QFpPHJovR0xHkQYJYoQz28MRXF3RkDqg85H/4dEW X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80db1915-49de-4ed0-a873-08dbd04b82e8 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:34.1443 (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: RhIs/Kb3+DgxgGTivRYasvj4bwFrDrkTI3mOa7JV7MY1lbRfiJOUslW4Tw57YWhQA0D9nx+nK22fOAqbyfaZaw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-GUID: krOX7uT60MvIF-FgkVyfhW5EeydFm-ud X-Proofpoint-ORIG-GUID: krOX7uT60MvIF-FgkVyfhW5EeydFm-ud X-Rspamd-Queue-Id: 81B31C0008 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: o6ndaouoieqegjuaff7d3ikn534ee7cf X-HE-Tag: 1697682725-774713 X-HE-Meta: U2FsdGVkX19kPUuVMi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/lddmdQRjA9Js1rka9UlQCja0nvMU4VSqlnbgW0+9HHI2Mhv36fhqa+EOnT5IUjeShQOxoCSVUPvJJD9q222VTZAlc/8mytfrXeychivTLChKZUELZ4TTxcthgq8ocwJBuHRHdcgY1dSGeIwOT9W2urtLwWhb/Tj7effmrZ8RsGDLPCRwTkt/iamzOLqGmAqtiZ/P1/PrwQ3Hp28VDYx+7jZHbUg745hzVAWk/F2KZ52TCCE5jK/jzRUxClnLVRA8Hhoca00keCtHuq65cH7ssMwUzalxQTseuHIShbS5K5+7RmxbPmojDTlOBZJ8cGncpF7gRwmAX1YDoJNm3vNsNKi7EQmcsqvGUWB0BAld6YTNKTc/sJ0/+DHZYo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Joao Martins In an effort to minimize amount of TLB flushes, batch all PMD splits belonging to a range of pages in order to perform only 1 (global) TLB flush. Add a flags field to the walker and pass whether it's a bulk allocation or just a single page to decide to remap. First value (VMEMMAP_SPLIT_NO_TLB_FLUSH) designates the request to not do the TLB flush when we split the PMD. Rebased and updated by Mike Kravetz Signed-off-by: Joao Martins Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb_vmemmap.c | 92 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 4ac521e596db..10739e4285d5 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -27,6 +27,8 @@ * @reuse_addr: the virtual address of the @reuse_page page. * @vmemmap_pages: the list head of the vmemmap pages that can be freed * or is mapped from. + * @flags: used to modify behavior in vmemmap page table walking + * operations. */ struct vmemmap_remap_walk { void (*remap_pte)(pte_t *pte, unsigned long addr, @@ -35,9 +37,13 @@ struct vmemmap_remap_walk { struct page *reuse_page; unsigned long reuse_addr; struct list_head *vmemmap_pages; + +/* Skip the TLB flush when we split the PMD */ +#define VMEMMAP_SPLIT_NO_TLB_FLUSH BIT(0) + unsigned long flags; }; -static int split_vmemmap_huge_pmd(pmd_t *pmd, unsigned long start) +static int split_vmemmap_huge_pmd(pmd_t *pmd, unsigned long start, bool flush) { pmd_t __pmd; int i; @@ -80,7 +86,8 @@ static int split_vmemmap_huge_pmd(pmd_t *pmd, unsigned long start) /* Make pte visible before pmd. See comment in pmd_install(). */ smp_wmb(); pmd_populate_kernel(&init_mm, pmd, pgtable); - flush_tlb_kernel_range(start, start + PMD_SIZE); + if (flush) + flush_tlb_kernel_range(start, start + PMD_SIZE); } else { pte_free_kernel(&init_mm, pgtable); } @@ -127,11 +134,20 @@ static int vmemmap_pmd_range(pud_t *pud, unsigned long addr, do { int ret; - ret = split_vmemmap_huge_pmd(pmd, addr & PMD_MASK); + ret = split_vmemmap_huge_pmd(pmd, addr & PMD_MASK, + !(walk->flags & VMEMMAP_SPLIT_NO_TLB_FLUSH)); if (ret) return ret; next = pmd_addr_end(addr, end); + + /* + * We are only splitting, not remapping the hugetlb vmemmap + * pages. + */ + if (!walk->remap_pte) + continue; + vmemmap_pte_range(pmd, addr, next, walk); } while (pmd++, addr = next, addr != end); @@ -198,7 +214,8 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, return ret; } while (pgd++, addr = next, addr != end); - flush_tlb_kernel_range(start, end); + if (walk->remap_pte) + flush_tlb_kernel_range(start, end); return 0; } @@ -297,6 +314,36 @@ static void vmemmap_restore_pte(pte_t *pte, unsigned long addr, set_pte_at(&init_mm, addr, pte, mk_pte(page, pgprot)); } +/** + * vmemmap_remap_split - split the vmemmap virtual address range [@start, @end) + * backing PMDs of the directmap into PTEs + * @start: start address of the vmemmap virtual address range that we want + * to remap. + * @end: end address of the vmemmap virtual address range that we want to + * remap. + * @reuse: reuse address. + * + * Return: %0 on success, negative error code otherwise. + */ +static int vmemmap_remap_split(unsigned long start, unsigned long end, + unsigned long reuse) +{ + int ret; + struct vmemmap_remap_walk walk = { + .remap_pte = NULL, + .flags = VMEMMAP_SPLIT_NO_TLB_FLUSH, + }; + + /* See the comment in the vmemmap_remap_free(). */ + BUG_ON(start - reuse != PAGE_SIZE); + + mmap_read_lock(&init_mm); + ret = vmemmap_remap_range(reuse, end, &walk); + mmap_read_unlock(&init_mm); + + return ret; +} + /** * vmemmap_remap_free - remap the vmemmap virtual address range [@start, @end) * to the page which @reuse is mapped to, then free vmemmap @@ -320,6 +367,7 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, .remap_pte = vmemmap_remap_pte, .reuse_addr = reuse, .vmemmap_pages = vmemmap_pages, + .flags = 0, }; int nid = page_to_nid((struct page *)reuse); gfp_t gfp_mask = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; @@ -368,6 +416,7 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, .remap_pte = vmemmap_restore_pte, .reuse_addr = reuse, .vmemmap_pages = vmemmap_pages, + .flags = 0, }; vmemmap_remap_range(reuse, end, &walk); @@ -419,6 +468,7 @@ static int vmemmap_remap_alloc(unsigned long start, unsigned long end, .remap_pte = vmemmap_restore_pte, .reuse_addr = reuse, .vmemmap_pages = &vmemmap_pages, + .flags = 0, }; /* See the comment in the vmemmap_remap_free(). */ @@ -628,11 +678,45 @@ void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head) free_vmemmap_page_list(&vmemmap_pages); } +static int hugetlb_vmemmap_split(const struct hstate *h, struct page *head) +{ + unsigned long vmemmap_start = (unsigned long)head, vmemmap_end; + unsigned long vmemmap_reuse; + + if (!vmemmap_should_optimize(h, head)) + return 0; + + vmemmap_end = vmemmap_start + hugetlb_vmemmap_size(h); + vmemmap_reuse = vmemmap_start; + vmemmap_start += HUGETLB_VMEMMAP_RESERVE_SIZE; + + /* + * Split PMDs on the vmemmap virtual address range [@vmemmap_start, + * @vmemmap_end] + */ + return vmemmap_remap_split(vmemmap_start, vmemmap_end, vmemmap_reuse); +} + void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list) { struct folio *folio; LIST_HEAD(vmemmap_pages); + list_for_each_entry(folio, folio_list, lru) { + int ret = hugetlb_vmemmap_split(h, &folio->page); + + /* + * Spliting the PMD requires allocating a page, thus lets fail + * early once we encounter the first OOM. No point in retrying + * as it can be dynamically done on remap with the memory + * we get back from the vmemmap deduplication. + */ + if (ret == -ENOMEM) + break; + } + + flush_tlb_all(); + list_for_each_entry(folio, folio_list, lru) { int ret = __hugetlb_vmemmap_optimize(h, &folio->page, &vmemmap_pages); From patchwork Thu Oct 19 02:31:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428195 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 D39D6CDB47E for ; Thu, 19 Oct 2023 02:32:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC4CE80074; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E238180081; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDBCF80074; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A1BB280081 for ; Wed, 18 Oct 2023 22:32:10 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7D7651A108C for ; Thu, 19 Oct 2023 02:32:10 +0000 (UTC) X-FDA: 81360636420.07.700FD19 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf25.hostedemail.com (Postfix) with ESMTP id 35D67A0005 for ; Thu, 19 Oct 2023 02:32:06 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=rQpgErTt; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=deC0BAFX; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf25.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682727; 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=Tsc70UZvKWYWI+spZQiVZ3u2z8ZAo9dlRTusEOzzs6g=; b=1PQz01a4wpy5HxU349Kxxf2ZUNbFOm4WieOAhuYwZ0p4iGwTUKWQnexZQixqefwu7XRw4L Zw0po2lJ81cG21/qPMgNQy8g4qEyBKN1Ch+jpe2TcRqwMLJddX4jFpG5iOX9BW5mGLTsSo ddaUtgSOmLhsDHoL0dMD90MGQaBeNVY= ARC-Authentication-Results: i=2; imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=rQpgErTt; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=deC0BAFX; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf25.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682727; a=rsa-sha256; cv=pass; b=s1OxT/1DANBi931N1tml7A7dua1IcGV+fSK6efltUyAvAtDEwhgG0CbZjWc8WhrqNJINZ0 wPau9Pi0vncTZX5evoHL1y6o2EktJTKWSLSi7hYY4hFv+7F6Ny/2wFi6aFkBY2mtW+FsyK 8D43RVIbqKDMdh0NNtXE2qGnwZoM5sU= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IIn3im027703; Thu, 19 Oct 2023 02:31:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=Tsc70UZvKWYWI+spZQiVZ3u2z8ZAo9dlRTusEOzzs6g=; b=rQpgErTtmdABXRMhNGQQlgg2mX9haPcDZ0EFYfKahihSaYXFLxHX/NS35+lzk81MfcOs FRMxamzwB3sxd69ZvQ2XDeUpNwznTrFIDMuXYOW73F7Dwnw9Zdar51isKl3rBLG0pYav kbijrBFpSCsA/ab9G6wxYDhTk2tdX8Jyk8Kn+Ru0SftYqzKDf8zG00BUWxIiHT8wc8Yg ZX+hpETt/BN8jLpfsx59m+85S1CIZBXiew6jvMM5f24JH7gvwk33r8UPzxmZT41JU4+0 CJp62bS/3Ev9BdA32QT9KnYPzg7mbs5BZvRQS6jjhHZ0hD/thn2MHxidZWcXRFf4GQEa Qw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqk1bs38n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:39 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J2GJ34021964; Thu, 19 Oct 2023 02:31:38 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3trg539w5m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nxjOzwliXpJ3e6gfqvgLcy9YtSOFEt/tQATGpXR/vBEcoX1jJJUK5GU92e0HpViDd/OmBx1ontByJKoMkgYs0Q5aXZ31e4weCHJjh3lr7Gu0rf9ci2zPyDhilMF54s/TO46S7sI60tY09eUJn+U5Fwk/m3W1X+JueCsN8mgTdQEnyKnta0goIp8//fzyHlmZq/n7vvlkq6pDxS74mx2ZsHsVq2V6/Fpr4fuYZfNpBkqcG3IBPsQUGKUSkW9NKrBKwEgBb3WJtWRbvY1pcfsHHPD2A3rlYK2jhz3ydMUIlnCGn0lBB1gqczxpEk1K6lTsERkVeB9rY8y3dv2F8v2t5Q== 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=Tsc70UZvKWYWI+spZQiVZ3u2z8ZAo9dlRTusEOzzs6g=; b=NmvNZE0JZjMeBJKSoQI/L2/HdaP1Z/xg9u/p7FjOcrCRRwDiASjT2gKFcBpeL8xYVhjAQjpi+pXeFnIRnAKNwymkOXAxXp83ZGChWdMJ/he6JG921Ys7g2/zRm8PjhAPVHLIVKerGlxyX4/yZPCC0LGiQxYEQ1gw/nOo195BeHvvkw/V4SHHJiqWqEcYWb6BXrhMywCwlcyYhcJmoKc0iw2oTo5MgqUK5ESVtpLlKbPGVWBrquwJK9col5tlI4ipo+f2k/ZNDL00w2HkqD5naMZHBTrS2dkCnQqXucc4V7Aq3g5s+RHj7uorXOBlW0KbIRJM7Nlv8iTbhIyYpz4z8g== 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=Tsc70UZvKWYWI+spZQiVZ3u2z8ZAo9dlRTusEOzzs6g=; b=deC0BAFXrqeOQZfQnHetFtYnVMGxKglo5r5RWLakj69BHUhg8rKeL2Fock4ArMy9G1PtkXUf2CrGCta34vqTld8q+Q01bLy7tabLOfhVjf3LlIliqlDY5nXVKVJJ4H06VH/QyMnfO4tQhn84re3yCOEFXeTnRf0zwAqGY/n8/Ik= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:36 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:36 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz Subject: [PATCH v8 7/8] hugetlb: batch TLB flushes when freeing vmemmap Date: Wed, 18 Oct 2023 19:31:09 -0700 Message-ID: <20231019023113.345257-8-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR04CA0242.namprd04.prod.outlook.com (2603:10b6:303:88::7) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: 09962dbe-d9c1-4a59-c18b-08dbd04b8457 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xgms/ZLaft5gG7asQJn6ysNtVgual/rNiT4vGufADxJVbTJPtKs7JLZLKG3ZbvnT2KrDKaeOmP8jdXGlN3wlkYhRABTxT3LgF4P8Fb1XAczMWW8junqSqvdMWbjOG4SOw/GaM44PGRzoCVs36mCXDugS5prvCASfrvi3XZOwgB+gDUVJ9stjQLutc59jB/INmcCUGWNaQFwscpKiCAWwrDnA38CRj2IeaIeo576IBA2kWN8B3iuQ5crQ6BLQiQAEEWqllPidKHlEX92jXvs7lrTwYLvfEeDPaVUvpI9NzuaSC0qav5iDoHO7oeB7Z3Az9H9kYaeduizv1u1tMqGHUq6jsIwZ9QLWQH1YX99BgXH1/U/QNoICtf7gNLWbuLOvOMqi2S3eIWCHa6VfhLcsbqqVXDwNNUYOAPJ2TaIrm1wD+tHnchbGB+I4tG75E+EQnXSVQ0S2VV8ZlOwObwH3gX+qQShdR8QFIAwnXfTIFKHYOVUMLYDgAAHi+x8k5zl94rW0+f76KzmCPB5o0Rc59eEalSnxtpAk94oPpN6Fg7FlhDfsIK2akvYtglPEeeoZ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(107886003)(6512007)(8936002)(2906002)(4326008)(8676002)(7416002)(44832011)(41300700001)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dhCmC2lRuBxv4R9mgKc22HTaMfDhfefEOMP9tQtZ8VrXt0KE7BmzA+lzeYbVCm01BHb3UCRlHaj0ZNhnhXC6n3C+lTV0owMtn91sdu/MhD93AnGk7E0Pgi3aUpfemfquB2qOsv5AblF1sX0c0Xivc/2kaHSLpP3lNQ5R/dXE2bIJEKr3NaWQDBZY4jHVcmNUL0Q/6yQ+HgEc0zruMFFpzBCW/Xui6hrF5CUZKuArzEcSSpyDetb8j/Gz0qiDesp1w0O9IXftHje0usjEEspQWNyOZ2jQ1jwZTVjd9NjvBA+HyFQY+CVRKUObCQw8SnZQcP4vByg1h7suZo8zc6YMSo9PJi+s1eFpDV8qVUe21QtXkPkVvwPbzmv4UjVn4Khm8ztcBZ3pu0E/D57R0rpKQgIfuCdUyrjM1tQaPyezbF2sOsckHLq11js37mIi0wNEHdV5aNZYJrEIs/7mj7AGewjlR3gGbBAIWBCEa8c8E6Ymmha0mrv1JyuVoh/mfvYf2aqNuV5+JnRltHArB0UQgWLKfT1Wyj9kTt37MPZ1/bFyaIFj3Rq+RejAitQ3vDg++vU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ZG0tvYHb5/VxTcJ22uAABT1kzZnvgn1/kNTJ4Fk5auEP6RtPS0GmS3fHM6gb0TuP6VDo1ON2SzM/0YLfg7+vg8OGdv2MPSE0And/QYhlmkdRzcMkx6NtEI6drUNWZBylgF37v0ULweK+pNJzKfPtD5APaLt8pLwa8cMxv3NcftMif0Xw/1zY9q X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09962dbe-d9c1-4a59-c18b-08dbd04b8457 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:36.5959 (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: Q5llty7HKPseEisi7ARisAks16gh5InH6MJJ1W/rkZp/lZDRa0+C5l5oxnmcRuqbZ2dDp2Kp/eERlUxnX9ZPXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 spamscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-GUID: _s8S4gi8IZCSJ0Jbh6r4D6-DbxfrMNyR X-Proofpoint-ORIG-GUID: _s8S4gi8IZCSJ0Jbh6r4D6-DbxfrMNyR X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 35D67A0005 X-Stat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auRuc5SLm1izqzayaJiTC4+esA+ToRy0hi+B1fKYm/aq8qDgTO6l/qoBVxGIroDZObWkfYwLPDUlH57H29sFbGw9f27FTVnZRNBZNohGDuCNN/cUEGAYQteG+lnHTJyHpkfFnYWWoIFrrTilMvdewpNCTWMPyJI6KsyMbIZzYg6Dj0pCxzXfWv+w88kFgBBChZaAFo616M7T+OiDlf/mhlSK1LZDg+m2AaDQMUqhJFov/4FlV1TMKgpAr4udKraFZXCcdBT3kFJUbqlFrT/Gufahrvlhw0Q8gtDIpK+/LgnT1sICky87oBAUrWKr524hMZUWDd27E648r44Pua4Ao8HLqAlXazky20AO9wDtqBFJULTuu//oEFopnrF7uMaPbfg3UKWJk44oAjrbQ+jU+lT9aLny3Tk/kMQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Joao Martins Now that a list of pages is deduplicated at once, the TLB flush can be batched for all vmemmap pages that got remapped. Expand the flags field value to pass whether to skip the TLB flush on remap of the PTE. The TLB flush is global as we don't have guarantees from caller that the set of folios is contiguous, or to add complexity in composing a list of kVAs to flush. Modified by Mike Kravetz to perform TLB flush on single folio if an error is encountered. Signed-off-by: Joao Martins Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb_vmemmap.c | 49 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 10739e4285d5..9df350372046 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -40,6 +40,8 @@ struct vmemmap_remap_walk { /* Skip the TLB flush when we split the PMD */ #define VMEMMAP_SPLIT_NO_TLB_FLUSH BIT(0) +/* Skip the TLB flush when we remap the PTE */ +#define VMEMMAP_REMAP_NO_TLB_FLUSH BIT(1) unsigned long flags; }; @@ -214,7 +216,7 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, return ret; } while (pgd++, addr = next, addr != end); - if (walk->remap_pte) + if (walk->remap_pte && !(walk->flags & VMEMMAP_REMAP_NO_TLB_FLUSH)) flush_tlb_kernel_range(start, end); return 0; @@ -355,19 +357,21 @@ static int vmemmap_remap_split(unsigned long start, unsigned long end, * @reuse: reuse address. * @vmemmap_pages: list to deposit vmemmap pages to be freed. It is callers * responsibility to free pages. + * @flags: modifications to vmemmap_remap_walk flags * * Return: %0 on success, negative error code otherwise. */ static int vmemmap_remap_free(unsigned long start, unsigned long end, unsigned long reuse, - struct list_head *vmemmap_pages) + struct list_head *vmemmap_pages, + unsigned long flags) { int ret; struct vmemmap_remap_walk walk = { .remap_pte = vmemmap_remap_pte, .reuse_addr = reuse, .vmemmap_pages = vmemmap_pages, - .flags = 0, + .flags = flags, }; int nid = page_to_nid((struct page *)reuse); gfp_t gfp_mask = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; @@ -629,7 +633,8 @@ static bool vmemmap_should_optimize(const struct hstate *h, const struct page *h static int __hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head, - struct list_head *vmemmap_pages) + struct list_head *vmemmap_pages, + unsigned long flags) { int ret = 0; unsigned long vmemmap_start = (unsigned long)head, vmemmap_end; @@ -640,6 +645,18 @@ static int __hugetlb_vmemmap_optimize(const struct hstate *h, return ret; static_branch_inc(&hugetlb_optimize_vmemmap_key); + /* + * Very Subtle + * If VMEMMAP_REMAP_NO_TLB_FLUSH is set, TLB flushing is not performed + * immediately after remapping. As a result, subsequent accesses + * and modifications to struct pages associated with the hugetlb + * page could be to the OLD struct pages. Set the vmemmap optimized + * flag here so that it is copied to the new head page. This keeps + * the old and new struct pages in sync. + * If there is an error during optimization, we will immediately FLUSH + * the TLB and clear the flag below. + */ + SetHPageVmemmapOptimized(head); vmemmap_end = vmemmap_start + hugetlb_vmemmap_size(h); vmemmap_reuse = vmemmap_start; @@ -651,11 +668,12 @@ static int __hugetlb_vmemmap_optimize(const struct hstate *h, * mapping the range to vmemmap_pages list so that they can be freed by * the caller. */ - ret = vmemmap_remap_free(vmemmap_start, vmemmap_end, vmemmap_reuse, vmemmap_pages); - if (ret) + ret = vmemmap_remap_free(vmemmap_start, vmemmap_end, vmemmap_reuse, + vmemmap_pages, flags); + if (ret) { static_branch_dec(&hugetlb_optimize_vmemmap_key); - else - SetHPageVmemmapOptimized(head); + ClearHPageVmemmapOptimized(head); + } return ret; } @@ -674,7 +692,7 @@ void hugetlb_vmemmap_optimize(const struct hstate *h, struct page *head) { LIST_HEAD(vmemmap_pages); - __hugetlb_vmemmap_optimize(h, head, &vmemmap_pages); + __hugetlb_vmemmap_optimize(h, head, &vmemmap_pages, 0); free_vmemmap_page_list(&vmemmap_pages); } @@ -719,19 +737,28 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l list_for_each_entry(folio, folio_list, lru) { int ret = __hugetlb_vmemmap_optimize(h, &folio->page, - &vmemmap_pages); + &vmemmap_pages, + VMEMMAP_REMAP_NO_TLB_FLUSH); /* * Pages to be freed may have been accumulated. If we * encounter an ENOMEM, free what we have and try again. + * This can occur in the case that both spliting fails + * halfway and head page allocation also failed. In this + * case __hugetlb_vmemmap_optimize() would free memory + * allowing more vmemmap remaps to occur. */ if (ret == -ENOMEM && !list_empty(&vmemmap_pages)) { + flush_tlb_all(); free_vmemmap_page_list(&vmemmap_pages); INIT_LIST_HEAD(&vmemmap_pages); - __hugetlb_vmemmap_optimize(h, &folio->page, &vmemmap_pages); + __hugetlb_vmemmap_optimize(h, &folio->page, + &vmemmap_pages, + VMEMMAP_REMAP_NO_TLB_FLUSH); } } + flush_tlb_all(); free_vmemmap_page_list(&vmemmap_pages); } From patchwork Thu Oct 19 02:31:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13428196 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 C5C33CDB47E for ; Thu, 19 Oct 2023 02:32:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AAE080082; Wed, 18 Oct 2023 22:32:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8301A80081; Wed, 18 Oct 2023 22:32:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6376980082; Wed, 18 Oct 2023 22:32:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4FA9E80081 for ; Wed, 18 Oct 2023 22:32:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 30B60B60C3 for ; Thu, 19 Oct 2023 02:32:20 +0000 (UTC) X-FDA: 81360636840.14.D0CB333 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf11.hostedemail.com (Postfix) with ESMTP id D894B40014 for ; Thu, 19 Oct 2023 02:32:16 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=AD36YTGe; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=NAW1kA7S; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf11.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697682737; 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=ts++G+BYdmdUFqdAtNKLn3GW8JSwEPzR7WlqhqbkpgY=; b=u7ILOWNhfthD3XTxWVfmyUWyiusi5qxIL9N+nPg1n3g2pw0ttgbZ9zTuapHF0EQxaeIgjb pblKso9AiXN2LSO1cR9kN2lwx+RkbamMBLkESD1whSxeIOCzFtuby94CCRXvKJwgv9hstb OqStVBoC7zEYksRORm+8+IFiXHMv24Y= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=AD36YTGe; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=NAW1kA7S; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf11.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697682737; a=rsa-sha256; cv=pass; b=xoJ6/o8uJaMvnUYCefZkpITofd9QUe9u6zyNrpofgIhJ/tXC5L9EM7gicFTqTQGj2KYM+T JZ7tU6DcEnPQCJYStKMqXN2w1HzaYOoO6OF7lC53Zpv03HcEl7Gg0osi2192n42a3mwGGU pBVDJoIDM2IRYsgW+HByvVmdrTsYLt0= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39IIp6k7018146; Thu, 19 Oct 2023 02:31:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=ts++G+BYdmdUFqdAtNKLn3GW8JSwEPzR7WlqhqbkpgY=; b=AD36YTGeiZWnEukAcKv0QYQWZZxxSHFOc3xkUPoH53ep9B7UFKGHdl4gKR+GO4cqdS1+ fthTbuTNMWGwrisGAWwQOmN1mvGG2U0e5pWUcKoflMQJrWdF4+nnH0vmzQD3Ob/brPp6 urBJAspsynyqCLu5oOUfc9HmA65uHWVoC9JHcGcgrZTYVyBP21mzMqJxK560yRo5yMih XSvyqExDHrOYmDUFXwpvsz7y/XOkFRk+pYcmdb5hqwv91em/Fp9ljnNSAcrvr/uNhKlE Jh0xVogF71GV93f3IwkLVQK1up2TCgvpHelsZz6HwHVnDJzZon8xvY+GZOtKNhJidByX Mg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqkhu993d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:42 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39J24XwW015185; Thu, 19 Oct 2023 02:31:41 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3trg1hah69-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Oct 2023 02:31:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A3NquWCZeno14c7qAxUMu9UErDakrtgLvYMlX8sof8frvJd8wEwzsV+De1gXtLd86Z1oecAR6YXQoJ8lkvn1u5h9Bziao3lcvbjuxiFfby8zNWLI2klZm8LKXcuq6wK/h5EZ5VR9vHUYFCULaXoSVyQMGSBQHs2u2rtRUJFsD5Vif1LtPC69edWA5ujqZkdxmXJ8ehWGvgXnxZpW8MYUOACUwcbVEsiZdvXEUOC2121mid+u+6hQcH78NEzgBW8X5PRAkvM6IT6JPSK/0PP1LNcSRDd8PfTmGyTkbMUt135CkczAtixTi/qj4TV/Aa2do6T6dPn25kjjNnd8IDg2dA== 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=ts++G+BYdmdUFqdAtNKLn3GW8JSwEPzR7WlqhqbkpgY=; b=SNq/KgM65DG37gPOdZVPafGGdUF8V3LjH0YFIsL9QYkQF8U7HggDayIf7BgrjhRaT3kVHBmHwz+UknUnS9D50RJ1NkHyPI6uSMfy+0YQ+MVsx02hngHXS1gm9zs/1JIYDYIkQhJ60QmUHkxb6l3x7qkamhZsJKKHPtl+uaU2Z2chZipvMWWJe2ryylTdcFZFNTko+CGVpkHMCkcRkX2BvzyiTx5svOKJpA0KsaSuMAWBeDHLQuUHx3cNAM4V+ATAW/CKr90Nd3LaTSadLa3tPxDV9XM7yyhFC5jRM4/UM44LEWzeC7mCaeYoMS5GC70dw98uFgNXatvc8rzQHRVGIw== 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=ts++G+BYdmdUFqdAtNKLn3GW8JSwEPzR7WlqhqbkpgY=; b=NAW1kA7Sygn7Y7GzHGBKKAeurvE1Ok36V75dzSZaXhzWu8xlhiKS7+M6z/PcAV3C0L2kt84AjuutZPG1Um+1CyURmJ1waUHJfwGrh83mzcn/UKTblufeeMRVDemkaBglAXeRz6/J97+39zjTQ0LryMoO8dkKH/yS8BjOvWvs62A= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CY8PR10MB7123.namprd10.prod.outlook.com (2603:10b6:930:74::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Thu, 19 Oct 2023 02:31:39 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::59f7:ec45:eb41:d8c2%6]) with mapi id 15.20.6863.032; Thu, 19 Oct 2023 02:31:39 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , Joao Martins , Konrad Dybcio , Oscar Salvador , David Hildenbrand , Miaohe Lin , David Rientjes , Anshuman Khandual , Naoya Horiguchi , Barry Song <21cnbao@gmail.com>, Michal Hocko , Matthew Wilcox , Xiongchun Duan , Sergey Senozhatsky , Usama Arif , Andrew Morton , Mike Kravetz Subject: [PATCH v8 8/8] hugetlb: batch TLB flushes when restoring vmemmap Date: Wed, 18 Oct 2023 19:31:10 -0700 Message-ID: <20231019023113.345257-9-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231019023113.345257-1-mike.kravetz@oracle.com> References: <20231019023113.345257-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR03CA0109.namprd03.prod.outlook.com (2603:10b6:303:b7::24) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|CY8PR10MB7123:EE_ X-MS-Office365-Filtering-Correlation-Id: 56c4f069-2e88-4c37-0167-08dbd04b85ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kQEOqk2kwcERpCV+is9Y9uHmqYaG27mSBtqqF0mIYojoA/zeXRFVlU0FNMtsWCzVpjU7qwOdosJXyWXmw8wzAWY7DzWTYZHdPton4e7AZuxH+4cSuZAyU4+eT1Ol6AqtkVypW8cRupCpfZP+turvy1PPTFcVR1VvD5tY3MXaPQHPGMIcRpNgHRUJOBCcT7dop0RaEWENdbJdSRRCJ6EncnrxWN64j3s4gYRkJ6BvJVvvA3Iu5bsgspZoZKsTAf37/BCS+rxDZJp2uScT9ilfUrZVbyenFHihlVGujviBRCsyFri1pT8HmvmrwCpwYCeLzhaNkhqBKQF2KnU5MgmC8WkVc3/a2IL+8hZRIL4+e94kiHYFsgiO28nwpjyKZXZECvoI9hJ1/qzwyzZYF36abJTHCpn+VN6AfwPtVXQyBHfC75tffnADXxqxmcpzKRPizxRwThAkV28C/enM7p5lgUliNB55M017SKMJttdfKkwmNDgwl0giCLFDDaYFfyE0D900zlGaqcBlfLgak0LH+0NV3QHPoTQNnCm4cfbKwMPVDVmbbG4N3eNeQmzpB5Kf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(376002)(136003)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(478600001)(54906003)(316002)(66946007)(66476007)(6486002)(66556008)(6666004)(1076003)(86362001)(2616005)(26005)(6506007)(36756003)(107886003)(6512007)(8936002)(2906002)(4326008)(8676002)(7416002)(44832011)(41300700001)(83380400001)(5660300002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nL2WEc6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fUSGTdD2kcFi5vkNY3aD1gtBsiWuobZbcRGvBUBaNifQn0l7DUSmHVXGu3cly91ZQ7RfQFULUXn7ThKZqblcZV2xmxhkZ0pNCYdZ4K0rXlT4BDEWNT6WHlj/3QiHds8JjxUG6scUaPD/pZ4U74obkavM/pQEjNB3bUcikG7CqzKK/lxMn2OVdaTVqE73N6RO0tRiIzsj3q10plHsRY0qwKaZn6WpqWqBvtFlYuVO47zR6S96kyJukqK/kn3sngVLGux3mqexMxzD5xTn8E+HshPj/UZlmd1+YW5kRF+sorrauyAZsXSRhAp5vSfT9GdKXQ+GgW3SeOUqRGY1ToeNTr9p5EgTLm19f9slyDH0qSa611R0vxY3IOjOa3/TVCw67gx+u8U8n5x/lLk0IpdEF6b+87wCYOBOP33u62RUbK1SsihReH9YNGew7Fs0PBvHUXCSG4H5AYVIXk85wsBmguweJVMw8N8VuFBnpU37mRexY8ATnt9jB68g8HQJ/s3OpNenVlJ4CkQ3Q7jSQ4IZWkJ0ihTr/U7XhkWpEK958HLOOBQqTr8GpfxFCYja/x7ETyUrJXwIG0hLj2lAfIcOJ1PgbQL7ZfQoDvJN+fdb/zGWryuRRd3GL2tZ90F2VSb2fMj34zK+hz+SXtbknCVdO/GcuAlJhfTpEi0CTINvRVWE2nmaLVY35mbgDUIozTVIOx8TlN3dIhovEPpYIO8y5OJgHqizB/SIk X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56c4f069-2e88-4c37-0167-08dbd04b85ce X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2023 02:31:39.1280 (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: /DIjKm6n+/qZUGSFLQpWEi6l34Opv7w9oG5bGqxbbFYQmN2mue9LDJzXbdnZKP3vt7Jt5DPIgVviAbMCi0DkAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7123 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190019 X-Proofpoint-GUID: jCP4Z08mt3Ti3JgrqwfzBLSAnPG0v9FG X-Proofpoint-ORIG-GUID: jCP4Z08mt3Ti3JgrqwfzBLSAnPG0v9FG X-Rspam-User: X-Stat-Signature: ewcr336zri8t77jgkn971m7sax4bj5yq X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D894B40014 X-HE-Tag: 1697682736-472432 X-HE-Meta: U2FsdGVkX1/h6ZppmvKHP9X8e8D4ZwXz/pa57oiVT2v29HTIWlb28I7H3Ge08XixPYz5b3keUgRjchJxksl6YmGhn57ykRLldneIXdECQd6mhLV/pqykMqKc3D9xt5wkzbCAaGMAEORuNcQy8tidXEYFDhCte7ea1oFwSPKxSaXHiUwm+pBG8zrbxSa5mNLFQ6cdxYbE2V/n2PsKhGoojHTXywdampgU0J+YCjhlppitt19rfskzFrseNkjgqPkClTYA/NgL1V4vyExNLJXBgG4TXQutAPfdXk72ct74BdL0L0adgpEIKUZysHHZ08XEXNmZej2PR7nM5BTSuUjOLozpdGPSquW48vLTb25yeIoCAEeMzUFVb+ny1+xoEPHZqyYqWRgGpbt2Pg+J1tJvQLhHmCiBowcTJ3l46ip6FUNJEvX5PyhZK33axnSzQSvJffHkuS9o4V97YUmcOlyp6OeUi0/XLNyLlQvefNNd1A75iwRexTc4/Jw8B14gkBdawnkrKEJA2O/V8VV7KIshZJ2isEx92lEr7phdDG+OLPfwrqlE+sZ6/9u+23a7ZMw3myeZu4ET6W9aVLzjojY40tViSNuVvp2OUpmyvyX3y+TGTiphxACJrZdRecPgK9Dj6en8ORi29xXTIsmKIZqZUBEmKuVytU3bHiGMUd/4Fly5YueaQR4VeemkpkYCid/DxXN4PE2HwU/7oWpgPx133d+nhyGRHCTPIIHu9pSKgDUWKDat37u2n+rpCr7oFWdDqOFRHuPyVvwoDzsY+06egUZrDycCWjJBAkft8RtoAt12Z5YBJs1xPSZsJtU5UuHvo6CVA7GNu5iNbqs9JCuouisNpbpZ0elOPcqgN8CPdig2NCXdm3+xEn6eXCwAlxOkx2YOTh2FFgkXeSrDudPhdib420RUYKCSURX2+M/HetE+X62XQN++VtbD+iUxgfBtXPXC5uL657r7QbaCtr1 Bsk19JW4 A7eOP1cMS0fhjfTiq8nz5VxyzWJJ1Ybjy6J2nA66M0nUmxPgyB/pgXEdKZxJytB3tYa86wKyU5FoHNhYJvJt6OH5QGZxAjy15HAiI2OYG5q6Pk6bwM7/u7iZA9J4NjQaWGNksb4Qf89iG3CPcpfVhdJnGXlIQtak1yIfVdUfH5TTfljvOkJi6nAZLYdOz6XA4jPVAZZn6/rdQu7iq3+5EhGJhSfCDaaC0AVJpE1smpp+2IFYIsqBO731D7sfUH/Qe6MTXt5lHFy5WSfOsQouJDkUMuKs3hjFBzar5aBGVH8pBGDzxuA7enGWAu4BBbDQeohfAHposqsiHHeGtcGVzIgZsEltMK/9DWs+ziOZBvl4u2R+lVZcXeVtF4Eg6gSU+2FtQcYaotT06JCkO0ZRzQLLDZotMWN6Kbq4ILfhT8C5h3jW+9wKPi3+2JBkHqSBCrCpBG7EpRB4FS7QHkITahFmj1qtezW69n2KF 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: Update the internal hugetlb restore vmemmap code path such that TLB flushing can be batched. Use the existing mechanism of passing the VMEMMAP_REMAP_NO_TLB_FLUSH flag to indicate flushing should not be performed for individual pages. The routine hugetlb_vmemmap_restore_folios is the only user of this new mechanism, and it will perform a global flush after all vmemmap is restored. Signed-off-by: Joao Martins Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb_vmemmap.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 9df350372046..d2999c303031 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -461,18 +461,19 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end, * @end: end address of the vmemmap virtual address range that we want to * remap. * @reuse: reuse address. + * @flags: modifications to vmemmap_remap_walk flags * * Return: %0 on success, negative error code otherwise. */ static int vmemmap_remap_alloc(unsigned long start, unsigned long end, - unsigned long reuse) + unsigned long reuse, unsigned long flags) { LIST_HEAD(vmemmap_pages); struct vmemmap_remap_walk walk = { .remap_pte = vmemmap_restore_pte, .reuse_addr = reuse, .vmemmap_pages = &vmemmap_pages, - .flags = 0, + .flags = flags, }; /* See the comment in the vmemmap_remap_free(). */ @@ -494,17 +495,7 @@ EXPORT_SYMBOL(hugetlb_optimize_vmemmap_key); static bool vmemmap_optimize_enabled = IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON); core_param(hugetlb_free_vmemmap, vmemmap_optimize_enabled, bool, 0); -/** - * hugetlb_vmemmap_restore - restore previously optimized (by - * hugetlb_vmemmap_optimize()) vmemmap pages which - * will be reallocated and remapped. - * @h: struct hstate. - * @head: the head page whose vmemmap pages will be restored. - * - * Return: %0 if @head's vmemmap pages have been reallocated and remapped, - * negative error code otherwise. - */ -int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) +static int __hugetlb_vmemmap_restore(const struct hstate *h, struct page *head, unsigned long flags) { int ret; unsigned long vmemmap_start = (unsigned long)head, vmemmap_end; @@ -525,7 +516,7 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) * When a HugeTLB page is freed to the buddy allocator, previously * discarded vmemmap pages must be allocated and remapping. */ - ret = vmemmap_remap_alloc(vmemmap_start, vmemmap_end, vmemmap_reuse); + ret = vmemmap_remap_alloc(vmemmap_start, vmemmap_end, vmemmap_reuse, flags); if (!ret) { ClearHPageVmemmapOptimized(head); static_branch_dec(&hugetlb_optimize_vmemmap_key); @@ -534,6 +525,21 @@ int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) return ret; } +/** + * hugetlb_vmemmap_restore - restore previously optimized (by + * hugetlb_vmemmap_optimize()) vmemmap pages which + * will be reallocated and remapped. + * @h: struct hstate. + * @head: the head page whose vmemmap pages will be restored. + * + * Return: %0 if @head's vmemmap pages have been reallocated and remapped, + * negative error code otherwise. + */ +int hugetlb_vmemmap_restore(const struct hstate *h, struct page *head) +{ + return __hugetlb_vmemmap_restore(h, head, 0); +} + /** * hugetlb_vmemmap_restore_folios - restore vmemmap for every folio on the list. * @h: hstate. @@ -557,7 +563,8 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h, list_for_each_entry_safe(folio, t_folio, folio_list, lru) { if (folio_test_hugetlb_vmemmap_optimized(folio)) { - ret = hugetlb_vmemmap_restore(h, &folio->page); + ret = __hugetlb_vmemmap_restore(h, &folio->page, + VMEMMAP_REMAP_NO_TLB_FLUSH); if (ret) break; restored++; @@ -567,6 +574,8 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h, list_move(&folio->lru, non_hvo_folios); } + if (restored) + flush_tlb_all(); if (!ret) ret = restored; return ret;