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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9546C6FD1D for ; Fri, 17 Mar 2023 06:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229987AbjCQGeI (ORCPT ); Fri, 17 Mar 2023 02:34:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229962AbjCQGeC (ORCPT ); Fri, 17 Mar 2023 02:34:02 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DF711CBFA; Thu, 16 Mar 2023 23:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679034840; x=1710570840; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=pQNHJcVf/uqPXf6On3XrFhV0RhjTK2mejPRv9V1OOPE=; b=g3AgQj2XHLaWaQkfISf5RkgonAXn2FCn7kAtT77aDxxUZfqIwMI99Mv/ UzbawCfx7kmTxv4KBF9Da0bULCoqC48/N8KKhZGSDqUcIuTUF7jDa4wyo bqK+OHE63NNxJ16uE5Gq4VpolXRtgPldCiZEYiYcGQI148O1uPvXFnGTE 5hljkTJ/G0LrVCW40eJmRgkvZtiRiAEh1AhTH+QjFxsViLJpf6XxyzZ+C lbgv1fEHiwu+Sky1s4/k+nGh1IyQ6HTpMbFAQOKjwGDPUeatlYS8V569o ZAaMRwKuDwp4TrMBIZ3et8q7cgTJn6mEHoqLrAEx8RVoq6iThue3Z0fq2 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10651"; a="326558075" X-IronPort-AV: E=Sophos;i="5.98,268,1673942400"; d="scan'208";a="326558075" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2023 23:33:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10651"; a="1009527341" X-IronPort-AV: E=Sophos;i="5.98,268,1673942400"; d="scan'208";a="1009527341" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga005.fm.intel.com with ESMTP; 16 Mar 2023 23:33:58 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 16 Mar 2023 23:33:58 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) 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.21 via Frontend Transport; Thu, 16 Mar 2023 23:33:58 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.175) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.21; Thu, 16 Mar 2023 23:33:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a6Q6fxyh+3zuYpFNPEk0Umjzb88E1HW6xxd3BfJVQts8ermNytVZDaARElZyZzUIDJCf40yi8JCUQcFH3qFifKQvvJrla1hSclpcNyTURraXk8isQ62uVgUrat0G1lyRC8iUUdTUBJyxXTiOz9DRBCqZ7ZENbXxT34lgstd4zuFpP2jzzpY2Kj5HPKUJnUqolj3LF2YBhl8mgfak8IImvKKE3SauhGQ6xONnUXceQu1RTfeAc3lZCSv37YvDpSTB3hnZOc3n9g9OWt+bWHgWI5Mq+pBTZpLlcB6/uYrPAEHc5yW0nYfjifalwIXKIFfJ8FgX2n1jQfDFBhzHDuJQow== 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=QnHtt/MwzW2Sr8G2cOS9gx9BQ+7ygIJAkg6NilJ8JHw=; b=B1QkmEb42p4a91OXf003IrPWQ71cp032lrM4DvnqJsulAsFwixhz/LtZ5pACYR7u8lVyK6xU3ZTdrS+didhkCx3uYMk4cQqsNxJon6flUhFwGsBWbUICFgS3Y61fsg2d5H+K7UJtkwt4SL+wyrXshLF99usY9ot/ceZUy9SHJIH9B8bMKSyJpdUFM0lCqq8HytQ0kE3n2Ueigj4QLc5HF94p/3hItK1WtJz6o1oY3z1vHIKvKU59ByzRFp1EaNQ8ktViezl4gE3HCS5k0vDKj3V6nQvdADGC/6JQfz4maew7icW3UflGF8b8pBhMtPseVQmFFncAUaumTNNHFYHyQw== 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 BL1PR11MB5416.namprd11.prod.outlook.com (2603:10b6:208:319::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.35; Fri, 17 Mar 2023 06:33:56 +0000 Received: from CO1PR11MB4820.namprd11.prod.outlook.com ([fe80::8073:f55d:5f64:7c6]) by CO1PR11MB4820.namprd11.prod.outlook.com ([fe80::8073:f55d:5f64:7c6%8]) with mapi id 15.20.6178.026; Fri, 17 Mar 2023 06:33:56 +0000 Message-ID: <12d7564f-5b33-bdcc-1a06-504ad8487aca@intel.com> Date: Fri, 17 Mar 2023 14:33:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.8.0 Subject: Re: [PATCH v4 35/36] mm: Convert do_set_pte() to set_pte_range() Content-Language: en-US To: Matthew Wilcox CC: Ryan Roberts , , , , References: <20230315051444.3229621-1-willy@infradead.org> <20230315051444.3229621-36-willy@infradead.org> <6dd5cdf8-400e-8378-22be-994f0ada5cc2@arm.com> <2fa5a911-8432-2fce-c6e1-de4e592219d8@arm.com> From: "Yin, Fengwei" In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SG2PR01CA0151.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::31) To CO1PR11MB4820.namprd11.prod.outlook.com (2603:10b6:303:6f::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR11MB4820:EE_|BL1PR11MB5416:EE_ X-MS-Office365-Filtering-Correlation-Id: f38f76fc-e1bb-45c9-aac7-08db26b1955b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yGJ9ZF5yH/ALWHROtHRO0EROpobWXXiVbtft4rhw8AP3MhV8RCvhL8bsSjnu6s0R+XAypYXxfwTTgqL1ZxDL4/Z1EajQSh2BVSBA4Sk9KXp70oIoqYyPV+G8Cz8Jtx/xmyGiY/5RYoPa8WCVhJ+jco3gehSni7fZfXp3kOmj/pCWpHa9RpMQl0nX8v0Dq74aLyv2lP0g1cRWmL/O60m/F3grZkCG/lqkV+Gw7Pgxxsbh2xudip3K62YaDJf2JC4ntCqq1Khw0FuKdedI1GhcFGWTKuQocbmgj0Ev/t+WdSzXW/FOsPiodcXUlFEvS2YlwFtToJBQgYDxflir0ljn0HceMtdTsXxK2ydN6Z9jGb6+71OmFFOrRXizAXndoJTpkNM3pX97TKOsrD1DD74/wlyEFFceJXQCbS/SsBxbGHAAmdGCJetrwfX3FZ6qURQrLK+6KFPg845PRrK6fMf7RPiYzkEAtekwhZ3OgUeNV9/foJk44G1oN3ltPotlAIKds3VYTVsuZ1sSmu/Z7cPnATMMqDcsNzuQkl+6sRyr+mk+bxjGNroCi9LQX12DpMnul5GfmqHh7LhIo60Fr5vf0DRpNVk57Xzmb/EXpqOAiC0z1vyPba+0aBmD/1NSueAKX/HfEKpaiz8uAS5QAjJPXpmld7Zi78Rpuy91S7VWfg7ZDZrQ3Jdk1ZtwDdLTMyMCFyrht03gP/1zKgx83l0P2XD+80ecltuzTSJOuUUP4C4= 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:(13230025)(376002)(396003)(366004)(39860400002)(136003)(346002)(451199018)(8936002)(5660300002)(41300700001)(6916009)(4326008)(31696002)(86362001)(36756003)(38100700002)(2906002)(82960400001)(6486002)(6666004)(83380400001)(478600001)(186003)(2616005)(26005)(6506007)(6512007)(31686004)(53546011)(66556008)(66476007)(66946007)(8676002)(316002)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?N3dWYm1iYWdvNjR6dHFsK3BqSEdRZ0xBaXRBQ2RYV21mMjA5VkpxclhJWTM5?= =?utf-8?B?QWN5UEMxZHNGbmF4S2VDeGZwUWFOOWFMcVNVaGhrT1kxMVExSTVRV1U0T2ZU?= =?utf-8?B?Q2gwR1JadVFQbDh1SDByQjZiZG5UV0dWOWEvK2ZrS0h3emFCSTBDWVc0UGxh?= =?utf-8?B?ZEE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G5ZUXhNTzVqTm1WdlNtSThkQ2JId2RR?= =?utf-8?B?U1dIWWdvcGJ4M1UyVWw1cDVSWEZZUDZDRDl1QUxyc2ozakZQVzVkQkNmbGxI?= =?utf-8?B?ZDZvV2g5RlRwT0tmZFl3OFZ4R3BRelc0WDhrUDc0Y1AvaytaK05zVHp2dWY5?= =?utf-8?B?U3FocWpZMERONUxaNUJTQjg1TnZlbGIvamV3Wi9MWFh2M3M1TWV3bHpHbW43?= =?utf-8?B?Vmc9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: f38f76fc-e1bb-45c9-aac7-08db26b1955b X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4820.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2023 06:33:56.1655 (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: gmp5TLJefBBN8nVEAD/NWNJwuUj3D+xg9mR1CmiDelEsMVbSTsrl+o79CRshlulodtDVlFxoig4tbGMprndy8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB5416 X-OriginatorOrg: intel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/17/2023 11:44 AM, Matthew Wilcox wrote: > On Fri, Mar 17, 2023 at 09:58:17AM +0800, Yin, Fengwei wrote: >> >> >> On 3/17/2023 1:52 AM, Matthew Wilcox wrote: >>> On Thu, Mar 16, 2023 at 04:38:58PM +0000, Ryan Roberts wrote: >>>> On 16/03/2023 16:23, Yin, Fengwei wrote: >>>>>> I think you are changing behavior here - is this intentional? Previously this >>>>>> would be evaluated per page, now its evaluated once for the whole range. The >>>>>> intention below is that directly faulted pages are mapped young and prefaulted >>>>>> pages are mapped old. But now a whole range will be mapped the same. >>>>> >>>>> Yes. You are right here. >>>>> >>>>> Look at the prefault and cpu_has_hw_af for ARM64, it looks like we >>>>> can avoid to handle vmf->address == addr specially. It's OK to >>>>> drop prefault and change the logic here a little bit to: >>>>> if (arch_wants_old_prefaulted_pte()) >>>>> entry = pte_mkold(entry); >>>>> else >>>>> entry = pte_sw_mkyong(entry); >>>>> >>>>> It's not necessary to use pte_sw_mkyong for vmf->address == addr >>>>> because HW will set the ACCESS bit in page table entry. >>>>> >>>>> Add Will Deacon in case I missed something here. Thanks. >>>> >>>> I'll defer to Will's response, but not all arm HW supports HW access flag >>>> management. In that case it's done by SW, so I would imagine that by setting >>>> this to old initially, we will get a second fault to set the access bit, which >>>> will slow things down. I wonder if you will need to split this into (up to) 3 >>>> calls to set_ptes()? >>> >>> I don't think we should do that. The limited information I have from >>> various microarchitectures is that the PTEs must differ only in their >>> PFN bits in order to use larger TLB entries. That includes the Accessed >>> bit (or equivalent). So we should mkyoung all the PTEs in the same >>> folio, at least initially. >>> >>> That said, we should still do this conditionally. We'll prefault some >>> other folios too. So I think this should be: >>> >>> bool prefault = (addr > vmf->address) || ((addr + nr) < vmf->address); >>> >> According to commit 46bdb4277f98e70d0c91f4289897ade533fe9e80, if hardware access >> flag is supported on ARM64, there is benefit if prefault PTEs is set as "old". >> If we change prefault like above, the PTEs is set as "yong" which loose benefit >> on ARM64 with hardware access flag. >> >> ITOH, if from "old" to "yong" is cheap, why not leave all PTEs of folio as "old" >> and let hardware to update it to "yong"? > > Because we're tracking the entire folio as a single entity. So we're > better off avoiding the extra pagefaults to update the accessed bit, > which won't actually give us any information (vmscan needs to know "were > any of the accessed bits set", not "how many of them were set"). There is no extra pagefaults to update the accessed bit. There are three cases here: 1. hardware support access flag and cheap from "old" to "yong" without extra fault 2. hardware support access flag and expensive from "old" to "yong" without extra fault 3. no hardware support access flag (extra pagefaults from "old" to "yong". Expensive) For #2 and #3, it's expensive from "old" to "yong", so we always set PTEs "yong" in page fault. For #1, It's cheap from "old" to "yong", so it's OK to set PTEs "old" in page fault. And hardware will set it to "yong" when access memory. Actually, ARM64 with hardware access bit requires to set PTEs "old". > > Anyway, hopefully Ryan can test this and let us know if it fixes the > regression he sees. I highly suspect the regression Ryan saw is not related with this but another my stupid work. I will send out the testing patch soon. Thanks. Regards Yin, Fengwei