Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2253290rda; Tue, 24 Oct 2023 18:19:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJCyiiYDtXVzHN5Rw1G24ha+Le5Rsc23WrVYD7lCGWMsJ8zBQAt75SByj2k7yjTl+olrm7 X-Received: by 2002:a67:e09c:0:b0:457:78e0:b99f with SMTP id f28-20020a67e09c000000b0045778e0b99fmr12635197vsl.34.1698196740900; Tue, 24 Oct 2023 18:19:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698196740; cv=pass; d=google.com; s=arc-20160816; b=Xgofun3m7GxjM4BgDXTELxoH8cx2Ak3AKu0A0xKMjVeRv2i0yve0ovei+JOfRUYVAG zLcQ0WIemtvhyRnqdoEcKEqJXfZrDBoNd02alqwrhQvFX1s0l4rSmxfRE4vWYr0xga/L S3Nc1QxyNgUDLDpQR99YQDsva3KZlADO3jkyyPMH69eYNheWktwlsYYnRr8VOK/xu9Pt XpTgn1CnqpNtFq/Z6Y6FQNCOtJbRhIp7clkE2wVsytdrtQHZWoN15ykn71QzBcVkY5FC BWOTciYVJKDxZef6+zoPo3Osiaf0F0ajXxoDe5kKmP4AGerhFoHdLuZFRbKHXtJyw0uJ e4QA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:in-reply-to:date:subject:cc:to:from:user-agent :references:dkim-signature; bh=Krhv20skpHqThINaoi4QYu2+0eUGBalHOz7QmJJSVmc=; fh=y/IVp7u6gMKTlnucGy7UvNBltQCJJQk57y2K73+xVj8=; b=l+5Op4TICZyByJn846EVQVlpIjNDGZMZ+YFao68Sta7/xDNI6TeKo2pqwpy/tMB9St JQPSHiMHa0agBChsIsWWlwVrD5zu4jbnI6DdGuHvYy8CzKR0QopiDXERws3QnByfDBxF u0QKfoMvY7unvLBzO6cSCFw88Jo6OqNypw+HC3ovuef9qcuXcuRJbCVXGwIPecb1MfHX RV/62KTiv14Ee+6KC1pU0jxn7fZ2JRTOWesk/T74qQ5PszrYn8vIyumrZ5hEUDbnI3p/ xzLm4yehQw1bbILSC5FTPx6KYBroT5JWhdmmoGjGHYOvHKpIML0uXQcp/zs8ww8uXL1c vD1w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=UzvbxWLT; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id ed1-20020a05690c284100b0059f5be68e7asi2312575ywb.14.2023.10.24.18.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 18:19:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=UzvbxWLT; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 12813801D58D; Tue, 24 Oct 2023 18:18:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbjJYBSo (ORCPT + 99 others); Tue, 24 Oct 2023 21:18:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjJYBSn (ORCPT ); Tue, 24 Oct 2023 21:18:43 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2072.outbound.protection.outlook.com [40.107.243.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51C1999 for ; Tue, 24 Oct 2023 18:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BLREZYnBHTFhhueSLTdWrAbx41ns5ZjTpd81U6uY70jqjoGnAll3HlL25p9o+736LMKg/y4cY8nPC+sADtY/q/lGh78V6pSJOLwkoVMRalneTDLTIqYza4qfVKpJAYYJ8koDwnz/nlkqsqtCVFfu4GVVeDdnnu8F4z2RR4d9rC4EMdKksgbuqAcDKcnJ7fjzoGsjEi2FXA1SDmM2pe9hwzXh00G0mcjycVfAqIT+w9XsqP0mJxL0/tKColOMXpelKtNqCDBQtFo483CNU3GNWnPisszdQitKCm9gMsDM8knR2+Ht1HzClXjgVii7JjQ29xwBaj3NRPXmFh5y0WFYxw== 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=Krhv20skpHqThINaoi4QYu2+0eUGBalHOz7QmJJSVmc=; b=IYvg4eZA7p3o8OGgWZK36Fxhoz+O6Z4ozptWeHMdGxa7x20Q1oxwYDTGpJLsTrKivC8fCtJbsBdls00oBkqQS7hZE1FRM/ct840YtTFUsBx/37aBaFCg5slZqh9M9gNYWPVN2vaw5TIJm7QMpIZ90brHEfnqOg6J/gmToBmTStkVc3uGA5m/hLUZG1ZGbusBgsknt6W/DN3FXHZh/pUi1McBLG+z8FJe6lOugJfxeDJuHV0dtAO1YbksbwGBwE1BVJ9zyMzBVdMPYSRLB3oEIxLHlc6Vj9ONfMcgEWaB1t2gk1EduYhCFtA9TMfTXqbDBqdGyMSGObpp6Tb0sLOzZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Krhv20skpHqThINaoi4QYu2+0eUGBalHOz7QmJJSVmc=; b=UzvbxWLTBphNUCCSE9a0ZUyCGIuc0/beqiOEJzrGR4MsAimT4X/rNzXSJCkQSZrGkTDTvMHh0cN3VZFBu79SHLFLqKl3sdmLPF9yyksCUIM38zXpE+1Ln/21VsWYGdrbuIuexibVW7nQC9v7dDGsrYC4FM/7MmQh+tcdWiBJxzEuH0LANon1sDoC3Un/tP78z0qSfUPIvihvPaPlowrMhsd0wsUFj+kP6ESzuhv0KIJkL10QSKykiqMtAWDT94KZxNQgAQhUT8jkQ8+nDbcGgRoiVWOUqUtW6H/DhnKxj/MXDCeoYo8QqAFEE9Mb+MFiHO/CAP5suicNl3lfr0raVw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by PH7PR12MB5783.namprd12.prod.outlook.com (2603:10b6:510:1d2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Wed, 25 Oct 2023 01:18:37 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::d504:dd12:5218:c5d]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::d504:dd12:5218:c5d%4]) with mapi id 15.20.6907.032; Wed, 25 Oct 2023 01:18:37 +0000 References: User-agent: mu4e 1.8.13; emacs 28.2 From: Alistair Popple To: Barry Song <21cnbao@gmail.com> Cc: Baolin Wang , catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, v-songbaohua@oppo.com, yuzhao@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: mm: drop tlb flush operation when clearing the access bit Date: Wed, 25 Oct 2023 12:07:05 +1100 In-reply-to: Message-ID: <87y1frqz2u.fsf@nvdebian.thelocal> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY5P300CA0014.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:1fb::19) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|PH7PR12MB5783:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a4085dc-0da8-417a-ba4b-08dbd4f8508e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +URlexvnDZ+WUNzeA8t4oSh0zDfghlZfmbvZcQHyg3IQ5oC9lcji2bBAtp95dbensye7OJ2iwupoXAODy45jogyiajcWGahFORKx2k/LLL1vlSKM2EBPPvmNrq5//+nVoA1X04CazO3lWuieZIoKKO6qBM6VRlsYA8Fdllg7qSe9HqHYcEtlAjA8chKjeLfxiJDbhLCZwqBLfR3HUFU9z7g1AURAbKzqB+Ecgsf5D+YSB9s6aM2oYyopRreGx/IWiLRl1yGYzdo4T7EF39XzjIm+MS38wmiEmJrt7oykruIeCuh7TmPX9rS9b/P60VaNLkLhdD59oFHiHkbXoghSvrOzZoGTR4U2s0nNbzYXuy4+zTjIuD2seQ4IlnjFacBuY4JztMW65AO+tHoN22ivWPg5P58gZiLgIO2c/X18xFbmmkdIv6x+DPmjPpVPyBVbzWfkc8qJHrTDj2RNnQ+225SObBrrcGxxij/3oXBqOX4JMrkb3Z5ljnjeaUNR1F7iB88mfPmaviBFwGJEx+CRl7WB6Rpgvzn7MhA3LpyXLyOPrJKZH/AJcAXW1lAbGNvMsIsp8SxMybLxHKMIkqMUnBO3QGvtvwoWUbWXQOCeN0c= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(346002)(396003)(136003)(376002)(39860400002)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(41300700001)(2906002)(38100700002)(66476007)(6916009)(66946007)(66556008)(478600001)(6506007)(6486002)(966005)(53546011)(6666004)(6512007)(9686003)(83380400001)(5660300002)(86362001)(4326008)(8676002)(7416002)(316002)(8936002)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Z051V2gvaW9WVGNJVmRwWEthNUdKaWxESmxyeVB5eVpQN2tJU2tERWlkSjho?= =?utf-8?B?RXJWUXZWa1IrN0pYVUR1WUtBdEN4WkxabHhEVmVlUE1CYnZKOGhDNE14QnFH?= =?utf-8?B?RXp2RDBROU9uNTVLSzFteVNCSnliK3hQRHhYbzNUV25xVXFLUzdkNGppSjMv?= =?utf-8?B?SkdzRW1reXVYdTAzTlU0WjVXWnh5T3J2N2Y0UUViU0FkNWw4WjBzRnBCZmVC?= =?utf-8?B?UC9pczN3a1RLd29jL3VReFI1NWVuRTV4bXdFQnJOeTBJbEpheFZGK1FJTFk2?= =?utf-8?B?TDVrQWpuUVdKSlo2dGVkSUpiOEx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?Q?Dgh2+4hrJKRIyfA5Extj2TeLV?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a4085dc-0da8-417a-ba4b-08dbd4f8508e X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 01:18:37.3181 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7jk9isVUU6+O0BGXNv1D1jO07i4MCKTSlDwjAgzOLeWTuepN5piS9uDi/jtv+hkTpNHXvM5y9Wro7AWI2erHoA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5783 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 24 Oct 2023 18:18:57 -0700 (PDT) Barry Song <21cnbao@gmail.com> writes: > On Wed, Oct 25, 2023 at 7:16=E2=80=AFAM Barry Song <21cnbao@gmail.com> wr= ote: >> >> On Tue, Oct 24, 2023 at 8:57=E2=80=AFPM Baolin Wang >> wrote: >> > >> > Now ptep_clear_flush_young() is only called by folio_referenced() to >> > check if the folio was referenced, and now it will call a tlb flush on >> > ARM64 architecture. However the tlb flush can be expensive on ARM64 >> > servers, especially for the systems with a large CPU numbers. >> > >> > Similar to the x86 architecture, below comments also apply equally to >> > ARM64 architecture. So we can drop the tlb flush operation in >> > ptep_clear_flush_young() on ARM64 architecture to improve the performa= nce. >> > " >> > /* Clearing the accessed bit without a TLB flush >> > * doesn't cause data corruption. [ It could cause incorrect >> > * page aging and the (mistaken) reclaim of hot pages, but the >> > * chance of that should be relatively low. ] >> > * >> > * So as a performance optimization don't flush the TLB when >> > * clearing the accessed bit, it will eventually be flushed by >> > * a context switch or a VM operation anyway. [ In the rare >> > * event of it not getting flushed for a long time the delay >> > * shouldn't really matter because there's no real memory >> > * pressure for swapout to react to. ] >> > */ >> > " >> > Running the thpscale to show some obvious improvements for compaction >> > latency with this patch: >> > base patched >> > Amean fault-both-1 1093.19 ( 0.00%) 1084.57 * 0.79%* >> > Amean fault-both-3 2566.22 ( 0.00%) 2228.45 * 13.16%* >> > Amean fault-both-5 3591.22 ( 0.00%) 3146.73 * 12.38%* >> > Amean fault-both-7 4157.26 ( 0.00%) 4113.67 * 1.05%* >> > Amean fault-both-12 6184.79 ( 0.00%) 5218.70 * 15.62%* >> > Amean fault-both-18 9103.70 ( 0.00%) 7739.71 * 14.98%* >> > Amean fault-both-24 12341.73 ( 0.00%) 10684.23 * 13.43%* >> > Amean fault-both-30 15519.00 ( 0.00%) 13695.14 * 11.75%* >> > Amean fault-both-32 16189.15 ( 0.00%) 14365.73 * 11.26%* >> > base patched >> > Duration User 167.78 161.03 >> > Duration System 1836.66 1673.01 >> > Duration Elapsed 2074.58 2059.75 >> > >> > Barry Song submitted a similar patch [1] before, that replaces the >> > ptep_clear_flush_young_notify() with ptep_clear_young_notify() in >> > folio_referenced_one(). However, I'm not sure if removing the tlb flus= h >> > operation is applicable to every architecture in kernel, so dropping >> > the tlb flush for ARM64 seems a sensible change. >> > >> > Note: I am okay for both approach, if someone can help to ensure that >> > all architectures do not need the tlb flush when clearing the accessed >> > bit, then I also think Barry's patch is better (hope Barry can resend >> > his patch). >> > >> >> Thanks! >> >> ptep_clear_flush_young() with "flush" in its name clearly says it needs = a >> flush. but it happens in arm64, all other code which needs a flush has >> called other variants, for example __flush_tlb_page_nosync(): >> >> static inline void arch_tlbbatch_add_pending(struct >> arch_tlbflush_unmap_batch *batch, >> struct mm_struct *mm, unsigned long uaddr) >> { >> __flush_tlb_page_nosync(mm, uaddr); >> } >> >> so it seems folio_referenced is the only left user of this >> ptep_clear_flush_young(). >> The fact makes Baolin's patch look safe now. >> >> but this function still has "flush" in its name, so one day, one person = might >> call it with the understanding that it will flush tlb but actually it >> won't. This is >> bad smell in code. >> >> I guess one side effect of not flushing tlb while clearing the access >> flag is that >> hardware won't see this cleared flag in the tlb, so it might not set thi= s bit in >> memory even though the bit has been cleared before in memory(but not in = tlb) >> while the page is accessed *again*. >> >> next time, someone reads the access flag in memory again by folio_refere= nced, >> he/she will see the page is cold as hardware has lost a chance to set >> the bit again >> since it finds tlb already has a true access flag. >> >> But anyway, tlb is so small, it will be flushed by context switch and >> other running >> code soon. so it seems we don't actually require the access flag being i= nstantly >> updated. the time gap, in which access flag might lose the new set by ha= rdware, >> seems to be too short to really affect the accuracy of page reclamation.= but its >> cost is large. >> >> (A). Constant flush cost vs. (B). very very occasional reclaimed hot >> page, B might >> be a correct choice. > > Plus, I doubt B is really going to happen. as after a page is promoted to > the head of lru list or new generation, it needs a long time to slide bac= k > to the inactive list tail or to the candidate generation of mglru. the ti= me > should have been large enough for tlb to be flushed. If the page is reall= y > hot, the hardware will get second, third, fourth etc opportunity to set a= n > access flag in the long time in which the page is re-moved to the tail > as the page can be accessed multiple times if it is really hot. This might not be true if you have external hardware sharing the page tables with software through either HMM or hardware supported ATS though. In those cases I think it's much more likely hardware can still be accessing the page even after a context switch on the CPU say. So those pages will tend to get reclaimed even though hardware is still actively using them which would be quite expensive and I guess could lead to thrashing as each page is reclaimed and then immediately faulted back in. Of course TLB flushes are equally (perhaps even more) expensive for this kind of external HW so reducing them would still be beneficial. I wonder if there's some way they could be deferred until the page is moved to the inactive list say? >> >> > [1] https://lore.kernel.org/lkml/20220617070555.344368-1-21cnbao@gmail= .com/ >> > Signed-off-by: Baolin Wang >> > --- >> > arch/arm64/include/asm/pgtable.h | 31 ++++++++++++++++--------------- >> > 1 file changed, 16 insertions(+), 15 deletions(-) >> > >> > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm= /pgtable.h >> > index 0bd18de9fd97..2979d796ba9d 100644 >> > --- a/arch/arm64/include/asm/pgtable.h >> > +++ b/arch/arm64/include/asm/pgtable.h >> > @@ -905,21 +905,22 @@ static inline int ptep_test_and_clear_young(stru= ct vm_area_struct *vma, >> > static inline int ptep_clear_flush_young(struct vm_area_struct *vma, >> > unsigned long address, pte_t = *ptep) >> > { >> > - int young =3D ptep_test_and_clear_young(vma, address, ptep); >> > - >> > - if (young) { >> > - /* >> > - * We can elide the trailing DSB here since the worst = that can >> > - * happen is that a CPU continues to use the young ent= ry in its >> > - * TLB and we mistakenly reclaim the associated page. = The >> > - * window for such an event is bounded by the next >> > - * context-switch, which provides a DSB to complete th= e TLB >> > - * invalidation. >> > - */ >> > - flush_tlb_page_nosync(vma, address); >> > - } >> > - >> > - return young; >> > + /* >> > + * This comment is borrowed from x86, but applies equally to A= RM64: >> > + * >> > + * Clearing the accessed bit without a TLB flush doesn't cause >> > + * data corruption. [ It could cause incorrect page aging and >> > + * the (mistaken) reclaim of hot pages, but the chance of that >> > + * should be relatively low. ] >> > + * >> > + * So as a performance optimization don't flush the TLB when >> > + * clearing the accessed bit, it will eventually be flushed by >> > + * a context switch or a VM operation anyway. [ In the rare >> > + * event of it not getting flushed for a long time the delay >> > + * shouldn't really matter because there's no real memory >> > + * pressure for swapout to react to. ] >> > + */ >> > + return ptep_test_and_clear_young(vma, address, ptep); >> > } >> > >> > #ifdef CONFIG_TRANSPARENT_HUGEPAGE >> > -- >> > 2.39.3 >> > >> >> Thanks >> Barry