From mboxrd@z Thu Jan 1 00:00:00 1970 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 8ECBFC07545 for ; Wed, 25 Oct 2023 01:18:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F220C6B02FE; Tue, 24 Oct 2023 21:18:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED2DC6B02FF; Tue, 24 Oct 2023 21:18:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D99D26B0300; Tue, 24 Oct 2023 21:18:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C94026B02FE for ; Tue, 24 Oct 2023 21:18:43 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A4756A0B86 for ; Wed, 25 Oct 2023 01:18:43 +0000 (UTC) X-FDA: 81382224126.28.E0771AC Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2046.outbound.protection.outlook.com [40.107.243.46]) by imf08.hostedemail.com (Postfix) with ESMTP id 8BEF3160018 for ; Wed, 25 Oct 2023 01:18:40 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=UzvbxWLT; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf08.hostedemail.com: domain of apopple@nvidia.com designates 40.107.243.46 as permitted sender) smtp.mailfrom=apopple@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1698196720; a=rsa-sha256; cv=pass; b=fADnuYMbWDywrrnzTNk4m2iOBVK9bae4+FJ8ILKFOmX4gr7TGIgniP74iIEGTozK/0eI/+ ByxvvhbY9un6qFzsYvBTbrdqlEtSlGsdduR0WoqG0k0ZkE1kM65j4eOVpEXlC41nXnEu7V RYmW7rzPxL62+9AbPrJO1uBLdKoLgwg= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=UzvbxWLT; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf08.hostedemail.com: domain of apopple@nvidia.com designates 40.107.243.46 as permitted sender) smtp.mailfrom=apopple@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698196720; 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=Krhv20skpHqThINaoi4QYu2+0eUGBalHOz7QmJJSVmc=; b=Ds3KYNE918yvldfq+Yb2NrUzCB6gY+0tRPPacUs6L06M27jqMtqPUb3v2drgAK13Y71ZA9 OMfFcEu06P6tmbrgUjaZdPZDwzdhdEwqCks1YHCAPgKpsSpOJSLHny25ywxqw5gt/cKOMo Pfw5AxaekmEVgjBwwzn1OtJ02ksThqY= 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== 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?Z051V2gvaW9WVGNJVmRwW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B?RTVRaUlRRDRuQW5BRmhQMHFvSEUzL05jd29yblVBUTdpQ3lvMExFLzB0cEhh?= =?utf-8?B?MFY0cld0R09vbng0Qk56bjk0YURNbVJDM3NHdnFiZWZMOWd3MEt3VTkvNm92?= =?utf-8?B?ZDZ2V29vZ0dNQWxOWlE0em9tVmFKZE9qM3p4cm03Mm9kK0tYdVp6by9ST3NP?= =?utf-8?B?MXdyTExQUElGVnA1WnF4b0xxNkt4RnI4UjBaY1ZEQzRNQWlKaDlDdHdiQWVP?= =?utf-8?B?L0tLelFQS1pQUzJVMDJtK1UxT3Z1NG80T2cyeE5hanRDbm9QcUNDOGdQY3Ri?= =?utf-8?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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8BEF3160018 X-Stat-Signature: w55reiunpoptgf7g71n11xzdgycb8n9q X-HE-Tag: 1698196720-241472 X-HE-Meta: U2FsdGVkX193FlXN2CY7Ip8bBCORyJ7WSY3bKyKUX5BYcFg06vsF7hXTGkkCIE09dDzben9KqKXcMhfJ3BrXHOkMTB+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Lu3LBfNqZXWZsBIHrD+48bHf+voi2toZ3ow9hJwjb+VQhTQFKkRExvWpJGHU8ZSFX0I+J7kn9RA4qZOleEiUGUhmT08PCpcQ6nJUk+n3HXM9pLhP+RWcg== 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: List-Subscribe: List-Unsubscribe: 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