Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1402076rdb; Tue, 30 Jan 2024 18:40:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtuwnwB9HMPpGZ/47/DUt6/qBJd5xUKxkZHg1vwfAG6OTkSB2GAXh5X8o2iXs3wXrKIOZI X-Received: by 2002:a05:6a20:6d15:b0:19c:6746:7ddf with SMTP id fv21-20020a056a206d1500b0019c67467ddfmr351652pzb.29.1706668810682; Tue, 30 Jan 2024 18:40:10 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVdR/wzVURM6PmqrUXvfjCDaVtvc5oL9rCwHWOBR7n+tXynrlxaCY+LD+VeIRmy7teU8teOpGRZIT9tBx5VbCY2JSECL78liCgI9XAWiQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u2-20020a656702000000b005cdff1f4816si6936730pgf.424.2024.01.30.18.40.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:40:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fd6cUGVE; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-45679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AF9B28FBF3 for ; Wed, 31 Jan 2024 02:30:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1CD9FBE1; Wed, 31 Jan 2024 02:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fd6cUGVE" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF0A1D294; Wed, 31 Jan 2024 02:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.15 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706668216; cv=fail; b=LhSdA5I0zW0FTT7l3d5wYrxbea68BJ/tz48O3jvQHe9FzImABdE+IIog2DcEJ/o6IccitkPy+Bn/zkdvhUg0cwnD7ndpIein9aaBhSqE7d9dszpaWXh1XS9BxnIj/ndMEsNZZHpRZ6fVuHgHAeEDJGkfKykGtfTkWUNjRVzdEZc= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706668216; c=relaxed/simple; bh=M+NlpYgEHYf/7JvKivCxjYq7mfp5ZNo1tlSFaQiE43Y=; h=Message-ID:Date:Subject:To:CC:References:From:In-Reply-To: Content-Type:MIME-Version; b=dP1GJzpW00JFx4hJHo+ZmO6iwPPSOhPF6nv6vcVZBFn69BBo1maO/VPAv57u3l+J0eKUO6M6K90kgCXzsJtsL1Xhz0+vSZf23i2LgUteiYmwo3ZlQK0ktasrvANnIqNTqKBUf1RLLVTCksAo+Y5vOma9B80sPuJtLtJwFAMnXE0= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fd6cUGVE; arc=fail smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706668215; x=1738204215; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=M+NlpYgEHYf/7JvKivCxjYq7mfp5ZNo1tlSFaQiE43Y=; b=fd6cUGVEqHrpSmu9j4U2qU8oiVKzBV8byvSqGkYF9pKz9WPvV0EUNia6 0h5R9BgN3c6nvW4xpxnnziTvt6tRBcsuDGDn884o1k7ekCUyv4oswspBu jTehrLkusTlPlRXNAYsZnnMp+7mu5ARsdoc3zad6jlI1uG6uwFZbSPZW2 CQwD6PXs38YcSu72VtkrJm4aQRksphKh1VRHFrNHLHjHSyKPJpIz0nfJd nY7ok83xfi226EQNRmW8StlE5BmMVltboQzIJZ0NOnFGRHjwLRfU9i+gu IAZdDU9Qjs0zhSDVpPPmiXezkWUF/P85bjS7KlH3GwbKu0ZBxDj7MHx+n w==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3321210" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3321210" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 18:30:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="30337978" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmviesa001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 30 Jan 2024 18:30:14 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 30 Jan 2024 18:30:13 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 30 Jan 2024 18:30:12 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Tue, 30 Jan 2024 18:30:12 -0800 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.169) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 30 Jan 2024 18:30:12 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FoFDuwJ1f8Ufb8bPxKYP6Lt0cg24n4S3NM++C68l+qeyNTp8NCm6ODLxVLzrMtAd8cIyLC3eOcoGUGJ5Xah9xsdrulMYqEnmazH/1wYG3rLlEEATzDFvBum7bLLSJDMieg7Rz/XxphRZH9qzguNxeB+7nOV3MOmCdpTxp9o3T1tAt8UGNno9OCoRwuy9m6XbA7yH2tfEg3bINrNhCn8sXQ/c3gNudp/R6iod6+HIAu32/1/5R+kGuuqyhL21E/ehzWG4Xv4V7vDdN5nH6/yDfgRs1ZNvlXF6Wo1ptQ1c58O1cotyacIfkkVeLM5t/efryKzmE4dwKWs4mgImHJJV7w== 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=J0J+b2j8VobSmZK9V4h4YAebBuE5q1n5FyidWXKlB4g=; b=Hn5374h/Sk4I06eUxeyQk1Tn2u7aIYzub07DQ7kkgDneqvLJSg2pWz0EbLMF0YMOzxg4ArEneTiB2+O2g2kgUnl+dr3T1V7iWwH+gJH78Cr1lNwY5Im48vk6XSV8ADcgdyrHMn9qjFpnCGMGHzyW2lj3OqqqQQrryFgHNNqnijUchmRQpgR5AMmj1YQmS+zP7QFK/+yaTG6qqdCcfLwNSAxjUrLkQv1d9J8ev5mQDR4XLQqJpQbFsm1A26ia7J/2dn/U824RQ8cq2kO3swAzrrgWz/s9V82ygmf4GmT1+i6c2iJ4MQq4KzcEX2BA/uo/uwaASvEcG9z24ACSVDplxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from CO1PR11MB4820.namprd11.prod.outlook.com (2603:10b6:303:6f::8) by PH0PR11MB4917.namprd11.prod.outlook.com (2603:10b6:510:32::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34; Wed, 31 Jan 2024 02:30:11 +0000 Received: from CO1PR11MB4820.namprd11.prod.outlook.com ([fe80::4647:3802:133d:8fc]) by CO1PR11MB4820.namprd11.prod.outlook.com ([fe80::4647:3802:133d:8fc%6]) with mapi id 15.20.7249.017; Wed, 31 Jan 2024 02:30:11 +0000 Message-ID: <2375481c-9d61-4f06-9f96-232f25b0e49b@intel.com> Date: Wed, 31 Jan 2024 10:30:00 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 9/9] mm/memory: optimize unmap/zap with PTE-mapped THP Content-Language: en-US To: David Hildenbrand , CC: , Andrew Morton , "Matthew Wilcox" , Ryan Roberts , "Catalin Marinas" , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , "Vasily Gorbik" , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , , , References: <20240129143221.263763-1-david@redhat.com> <20240129143221.263763-10-david@redhat.com> From: Yin Fengwei In-Reply-To: <20240129143221.263763-10-david@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SI2PR02CA0007.apcprd02.prod.outlook.com (2603:1096:4:194::23) To CO1PR11MB4820.namprd11.prod.outlook.com (2603:10b6:303:6f::8) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR11MB4820:EE_|PH0PR11MB4917:EE_ X-MS-Office365-Filtering-Correlation-Id: 71c40ebe-37be-4ca8-4ed9-08dc22048c3a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wJS68JfGBcUMu73gnKcjgwaN24+YcQGGSGHb0f61RAScic8ZnyMhklzLvAuhPdsab955afP01BnuR7ml3IsSQodYSVqi0m2IBWjH3WiBwkzDdC/0bQuVe7diGW+C4pNFjaBW66rmtDi771YKjt9jddHt2au/THJEtCJ0TwJiaoSVmP4M0Ev5theVhus0gUuq/NM+HMpHtlvtaF+PSg+fUuJ0nIIEsGUfWxSMvcfpxSyKnWvdHY21YvL+3JD+wP7R//famU9KfrzVQWtqObbyq76057NlD26qyl5a5N7RteE8HoncMcMv/ZYGohjeaMTIHT563DlUTRX8PPfC1WdSHf9EA0m+Kx4oQII8DKB7HNsFMddfkjgK+SlY4tyA2BkyYitOqXQB25yjgaDVWrOZqSy5i/scTx9XxnXOVt/xMvPllzLuA2boCmKtXpluvoxpvVh50VT2ZJcGbSaV8bcGBmXYKq5EZMaYB9uoM2ycMVE5OuCkti7nic3B+RMCVM51QdZCvE5jUBmpFCZ+YwvVVa/IeoYiv65BCGSv3CpobpPaZ1kPA9MWxeIi9nrEWYxxAbmTmz/o8jCcP74rnzLjEW+m6f5qSpmnw0kB2Fp+F86t2DdFgTD0/C9tK4ZlmvghcdE0RZ/FJfJ4dUf5cB9Hsg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4820.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(136003)(376002)(346002)(366004)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(41300700001)(2906002)(4744005)(7416002)(5660300002)(36756003)(66476007)(6506007)(31696002)(66556008)(54906003)(6486002)(66946007)(6512007)(86362001)(316002)(2616005)(26005)(8936002)(6666004)(478600001)(53546011)(82960400001)(4326008)(8676002)(31686004)(38100700002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?S1lXb3MvMEJzaVJhUHB3Z3VDWitucHZGZHVPZ0VEeVBtM09TanB6RVR6M3N1?= =?utf-8?B?OStBUGE4My9MU1BpNEF0c3VxUVNIcC9yVjV0OFRVSXE2VU93d1M5eFIyMWFo?= =?utf-8?B?VDN0bEZwNzNIbm1Hc0xqZkdvRjRqZXNkNG9MU04rdlpJN3laeVM1V3pHVklk?= =?utf-8?B?OWxZZUgvTUFoTDZ1T1BlMWx4dk5wQkJpZThtQjh2Kzd5YXA0cHRJendBZmN1?= =?utf-8?B?S3E2WTFOOElnSW9tY0FlWVJuTnpjbktGeEVra1dMZjNFT3BXMjJCN0NGK3Nl?= =?utf-8?B?YVJoTTE5UVJYTFJUSn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UNETmVvR1Ar?= =?utf-8?Q?PsHzN0h06jD6cARL2vGdD23qZ?= X-MS-Exchange-CrossTenant-Network-Message-Id: 71c40ebe-37be-4ca8-4ed9-08dc22048c3a X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4820.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 02:30:11.0358 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: B3GSZYqiBY55mgZ8olLl33EIjUrGFQWojdeCSO+i/VHYl1g8yBO48HmTkItngUYqWF4FHnUAz9FRI/SKFyUX2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB4917 X-OriginatorOrg: intel.com On 1/29/24 22:32, David Hildenbrand wrote: > +static inline pte_t get_and_clear_full_ptes(struct mm_struct *mm, > + unsigned long addr, pte_t *ptep, unsigned int nr, int full) > +{ > + pte_t pte, tmp_pte; > + > + pte = ptep_get_and_clear_full(mm, addr, ptep, full); > + while (--nr) { > + ptep++; > + addr += PAGE_SIZE; > + tmp_pte = ptep_get_and_clear_full(mm, addr, ptep, full); > + if (pte_dirty(tmp_pte)) > + pte = pte_mkdirty(pte); > + if (pte_young(tmp_pte)) > + pte = pte_mkyoung(pte); I am wondering whether it's worthy to move the pte_mkdirty() and pte_mkyoung() out of the loop and just do it one time if needed. The worst case is that they are called nr - 1 time. Or it's just too micro? Regards Yin, Fengwei > + } > + return pte; > +}