From patchwork Tue Oct 24 12:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13434356 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 C3F1FC07545 for ; Tue, 24 Oct 2023 12:57:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6156F6B0251; Tue, 24 Oct 2023 08:57:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C4BE6B0252; Tue, 24 Oct 2023 08:57:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B31A6B0253; Tue, 24 Oct 2023 08:57:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 391CB6B0251 for ; Tue, 24 Oct 2023 08:57:00 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0F350402D7 for ; Tue, 24 Oct 2023 12:57:00 +0000 (UTC) X-FDA: 81380355000.18.51AD28A Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf23.hostedemail.com (Postfix) with ESMTP id C5304140017 for ; Tue, 24 Oct 2023 12:56:54 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698152218; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=1hKI1M3lU5Y+7x/LGbv1N2Zep6rJt5Yw5SvegI+zkrM=; b=o5Fd+QGzVYU10vN3w9c4AXMGnw6/+kbhRgkYjGty8wZ4jbTGOWH2LHJsEHsGcNp0kEBwqt Eq4uGGBQQlKKbifHQ/FIsJE8F6VhkU868S5BukwImgF46lwblUM5blZj7LypRKscXmnQY/ tv5g38ngt+woN1bwYal+cYfjYnCTOYQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698152218; a=rsa-sha256; cv=none; b=bt5HLkz4xoUagMnvpwCUBsnxs0eI6sJ1CQACvaMEIwd/gGggpjrVeXFADuWbVdsgLdsgjC UO9/1Kzi5w1rozwyMfsda1P2ATQdilENUK3VBmhvyXr4gVJFuHOVnCrd7uqUOV+mT0Lrx8 +IVQFKa8CPwmz07pQhdli/9UFqVw60g= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VurM0Hm_1698152201; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VurM0Hm_1698152201) by smtp.aliyun-inc.com; Tue, 24 Oct 2023 20:56:42 +0800 From: Baolin Wang To: catalin.marinas@arm.com, will@kernel.org Cc: akpm@linux-foundation.org, v-songbaohua@oppo.com, yuzhao@google.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64: mm: drop tlb flush operation when clearing the access bit Date: Tue, 24 Oct 2023 20:56:35 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C5304140017 X-Stat-Signature: 3yzazbdmxtwg8uaojmjsgfzdrpowwzs3 X-Rspam-User: X-HE-Tag: 1698152214-363146 X-HE-Meta: U2FsdGVkX19EeYnaTy/dpB4ldeJV35BdjU1u2wdRq+OqhK5Zfr4xluYQGg5MV3bKow/E9oJeddW/ypwjShwCaMqV72FtB4ycUAcIWeO55lLAkhPHwDpjhXwi4tNDSL95kcKKNpCNt9oIpggNpuZsHw68kxMykLhPAFE+gKYbkJLjOSpWUdGovkqQiCsBycj1q5b9twe3p52/o1e0e7nFn2xjPXoPzX6NRe3hMl4myOsOb8ezymu9NpIVss5Icq6Dpi5j8rGnV0SRUup6fzbavfJMifY1PuKtMhY1WY7RC0bcuNSd3227/P8wzTAARY6et2rw18XhGvubopWJSpkJCtW+SJmzLVLe01AcHwAfMMSQmERtW6oY44ChqAIGtkUj6fo8wrZ88zG774Mxf+ynH8QMoJTzr2YeAtkmA9zuyEhaksFs/LBX+LvZyld3fZsOKHU52ScDtW5yIHth+5dhU8mB1xNBkdwBWkw/0NiIFQRjVrNQpQy707HNX1pCKDCK3gnoScTmtwhPD7ihLQcIRzNW/5pWY9EnL0n1KjUGATACnIbF+ctb8GnPv62yz7AIz1dyVWOPDhj3pH+K7ee6+9HHQWE0UlHX8HKOEXua0c23497dIfkF75ahQ5Pt6WLNL7aYuFE1DB9FVOvP9dafgBjJETlbIBuNacNIwdcG+Ld1gEx31r5QZ4kcvCqvIkI03AoOKg8rc8xTUMOBUTM7Sa3ascfthDEKYiisSdxahV+XLW4kOF3AzqdATDhYDJkAornCdLufot38J9vl6DWiJvazDJe3o8kcuE5HszS9X0frk6hjP/3H8R8yM9gl7Qcpr8ROa1YzXOyh3HcZj1w7tClFzZ7fPBat99dVTSZf5KrIgSES+liGYA77swWM3Yt4Y5gQKytTDYmaFrj8MfuATqZEHhxXtg/aSartKE3sFFOnHr2g/gg1qySa9dXXw9Pn4gk1FfprKj/gQuiaOPK 1mBjEA58 zKI75rYcqPgTmCnPv128y0mpUJLBGeoqCD9SquWLvNvx5lD6O+3fXYU/FNX671SBHBr+EjrkFRDZ0NiB5qOvS+i6kHhkPEpRD5baeKVK7LTftv5trp2eoSF6sJc/hQuqYqJ7CBID5tW1sVdKRpYgzRkWJNWmdzH4EhliglnIrHlBif48= 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: 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 performance. " /* 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 flush 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). [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(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); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE