Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2286851rda; Tue, 24 Oct 2023 20:04:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMh8FethfQpyDEJzThxDBRKuXccLbJuA+kZ0oSkBmxokzAut0BfnBZc9P1GqgRLG2rPk4x X-Received: by 2002:a81:a046:0:b0:5a7:da36:4d33 with SMTP id x67-20020a81a046000000b005a7da364d33mr12930766ywg.25.1698203077711; Tue, 24 Oct 2023 20:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698203077; cv=none; d=google.com; s=arc-20160816; b=m9oNtrZQYH+IEEzFNf+xq7KcOGhu3J1mZhaMkq6MSz4EKu+CMsxqfJ/bHkd8mE9+YF 0VrPU+9E66bTc8KtT9p3eNnxOfukPrfVxs7lZEpYmhveBZMWzFwNtlQiPiFN3rZiXx/r hNTJ8bbLbDHB31fBbjqVJIxnPxXQkmBHswyxH79X1wv9se7+r3Hb2zLFvGJrXZpFgZmQ 298OGlKfb2GKKR9BY1RSkBiJpEmxbrB88aPs7a+SszAhw7UByCFJXAdRqMn/EOTMKAfM gut4VRsAi47t/QEzOlkdWL+PGKsAXHcNGHwGGWWI0z/5XTCnX/pJHjX7hZ/LBzaqtwBS i4mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=11ZBSFhv8iZRVFuc1xG37hcmJ+cZEuJDw5XliwFpFWg=; fh=zFoL1jKuytof8HqO1dn2JEhGWmwAXl09E0f/OkpZx5Y=; b=mIJQW9K3aWgDSyoHllrHbqwMX3Se3LlKhKfB0Aa5dXm/TmBCBp8/NM/2WDEwpQjhsd eZN6JvkZyXnMhWXK40kQIinawyl8K6QY7UmV6A2/rWFJFHGbonI1Jay6lO8Fv7r1wmxn kSMSF2CErH+riJ4VqpB391BLc1ZgZu4kfwldwa9D9QfNesYbieQ8MunpOuBVxIuwhpwG Hlqju0BegQeH+oMg1lohYIoyFehTGAV4Q905hEhbYC5mW/A70ZR6FkGWxXAB9EYjKQPH r7rz62Ung0gJfYwYScyK8fShxVP18LHLI0EtwrT1KkQBLhYUWk3XcVKS03HaBjxmVN2C rP5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j5-20020a0dc705000000b0058cc7adcbe6si10102673ywd.526.2023.10.24.20.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 20:04:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 77890807C860; Tue, 24 Oct 2023 20:03:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232176AbjJYDC7 (ORCPT + 99 others); Tue, 24 Oct 2023 23:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjJYDC6 (ORCPT ); Tue, 24 Oct 2023 23:02:58 -0400 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91FA7116 for ; Tue, 24 Oct 2023 20:02:55 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R651e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VusnLLH_1698202969; Received: from 30.97.48.63(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VusnLLH_1698202969) by smtp.aliyun-inc.com; Wed, 25 Oct 2023 11:02:50 +0800 Message-ID: Date: Wed, 25 Oct 2023 11:03:06 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] arm64: mm: drop tlb flush operation when clearing the access bit To: "Yin, Fengwei" , Barry Song <21cnbao@gmail.com> Cc: 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 References: <44e32b0e-0e41-4055-bdb9-15bc7d47197c@intel.com> From: Baolin Wang In-Reply-To: <44e32b0e-0e41-4055-bdb9-15bc7d47197c@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 24 Oct 2023 20:03:07 -0700 (PDT) On 10/25/2023 9:39 AM, Yin, Fengwei wrote: > >>> 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(struct vm_area_struct *vma, >>> static inline int ptep_clear_flush_young(struct vm_area_struct *vma, >>> unsigned long address, pte_t *ptep) >>> { >>> - int young = 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 entry 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 the TLB >>> - * invalidation. >>> - */ >>> - flush_tlb_page_nosync(vma, address); >>> - } >>> - >>> - return young; >>> + /* >>> + * This comment is borrowed from x86, but applies equally to ARM64: >>> + * >>> + * 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); >>> } > From https://lore.kernel.org/lkml/20181029105515.GD14127@arm.com/: > > This is blindly copied from x86 and isn't true for us: we don't invalidate > the TLB on context switch. That means our window for keeping the stale > entries around is potentially much bigger and might not be a great idea. > > > My understanding is that arm64 doesn't do invalidate the TLB during > context switch. The flush_tlb_page_nosync() here + DSB during context Yes, we only perform a TLB flush when the ASID is exhausted during context switch, and I think this is same with x86 IIUC. > switch make sure the TLB is invalidated during context switch. > So we can't remove flush_tlb_page_nosync() here? Or something was changed > for arm64 (I have zero knowledge to TLB on arm64. So some obvious thing > may be missed)? Thanks. IMHO, the tlb can be easily evicted or flushed if the system is under memory pressure, so like Barry said, the chance of reclaiming hot page is relatively low, at least on X86, we did not see any heavy refault issue. For MGLRU, it uses ptep_test_and_clear_young() instead of ptep_clear_flush_young_notify(), and we did not find any problems until now since deploying to ARM servers.