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 4E400EB64D9 for ; Tue, 4 Jul 2023 14:36:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A280F280082; Tue, 4 Jul 2023 10:36:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FD36280076; Tue, 4 Jul 2023 10:36:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91C90280082; Tue, 4 Jul 2023 10:36:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 82B11280076 for ; Tue, 4 Jul 2023 10:36:41 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4F98E140576 for ; Tue, 4 Jul 2023 14:36:41 +0000 (UTC) X-FDA: 80974180602.07.93A883B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf23.hostedemail.com (Postfix) with ESMTP id 27C2D140022 for ; Tue, 4 Jul 2023 14:36:36 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of yangyicong@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=yangyicong@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688481398; 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; bh=dVPe1nmDPnC71AuLo0CRkXKZ29QA1/OBA3xkf6Uaxvo=; b=O635PiT59JlXp/rX2IQ4qGZZs3NyzTSCdUYtmHeKcTD1RSO0rm3OUD48qDZ0n+ufk+Sa1Q OABNo/ZPbsrx5rC2byFElRcrzwBbXJLo+SZ8mOch3MwRb8YrnALFLtSAx2yR8uOYXdJH7X WSPo5iB5sUJHwTemsBkJ+rhKpk+2aqg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of yangyicong@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=yangyicong@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688481398; a=rsa-sha256; cv=none; b=ngmHaq+DURMFcDuBKQX7tb8QgT2/XFOzByb623BaE3OFb4Iqioc8TdD/K7+cqwfTuxsVYG 9EOkeglUm+X8ke0vHhP38rKSAQ5fgubUhZgM9JnSQySCgxb7t92EGTK4BhHBH4Wyb3YgL2 obrQxpgRo1VYX14CbCbjHg6pqrnMQtg= Received: from canpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QwQMS40rSzqVXh; Tue, 4 Jul 2023 22:36:04 +0800 (CST) Received: from [10.67.102.169] (10.67.102.169) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 4 Jul 2023 22:36:29 +0800 CC: , , , , , , , , , , , , , , , , , , , , , , , , , , Barry Song <21cnbao@gmail.com>, , , , , Barry Song , Nadav Amit , Mel Gorman Subject: Re: [RESEND PATCH v9 2/2] arm64: support batched/deferred tlb shootdown during page reclamation/migration To: Catalin Marinas References: <20230518065934.12877-1-yangyicong@huawei.com> <20230518065934.12877-3-yangyicong@huawei.com> From: Yicong Yang Message-ID: <2f593850-797c-5422-2c80-ce214fac02bb@huawei.com> Date: Tue, 4 Jul 2023 22:36:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.169] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 27C2D140022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ezpiibzp3arwboxgo56ycuo5t485uo4a X-HE-Tag: 1688481396-675269 X-HE-Meta: U2FsdGVkX18Qrk9EYYhSrWQiaeL9At6938L/l4ujRh4oKqkahHQkyHm3IHS5XUSO+hMpEdtmVoB0iyqsXRLZqAeUqg7NfXwTRpjRQ6y+8L6lQ0jX6SwsVGW3YUfXQzyjtoV67b10L3LwRHWilRZqwgMvaCFy1LndXOsl+J//dnR2+qY7W1jkMO/ipKqJJSoJLpc6gLEC2f5dqZhOsA4ePJ3FCrLLScsDGhX+4uwOpC2VSbQsTyYexH4HH+VvSP05JoprZa0B6Fu+DB6/ldsVvFsw56peGw3uxTWyT/5uzaNJZtVZTo1RzMWUxGzdskuHJN/DYA0fRQDK2flOQkO0l5SuQambn7n0amXvV5VdSP6OqQl+d4NqgPgEulHlD346waGqpBxezxGWUv00mFKLgGNr7FnCICsIM9YGH+Qwo+k06CC2BZFrq4qsis+PbBFmzu/Y35gfl5tNMNMMdmbXICi2fVZCK6TXA7Xzh6ZFbOMfi4DVfdumP5WER2z/HdRTkO4jWsm0oQ9g5lgXdeQArG5tvD0fQM8IidbDg8EQrdutqSJvg2NJ5kOv3dUPO3XvhptZLdz7qjQVwuhrKTvg39/3ah7gL2sQOOH/cUVABGUfXKgxHIZ6zPilkt4s9WuLVwa6/KZNYPTOoaqm7XZxU0BYrkSVHmHDXqKNSiktEO9kFCQDuIVxCtDE8w+1SA7F/tztjCj8+N+iIGp4p6GABuDbnJUkj7sPiD/wg45qLacSSX2TRghCAXmG/g8IRN1vwvB0sIsutwt28HUAo5jFrxPYy7DJmyC5za5DABjxjOaGXpFUQqe578zauldxQi3gVFEdXgK8ouYNyn3a+5uGuoFG5/Em1QLRkW0H81Ce3ifwsojuERaFkAMdWaVdJ6SRMB/iIgLuwHxVueVSVZ8lqxXLp3GSV9NsdBtnXtdmW3ZuJZzmZ/ogS6Bk2GDVKdz0bSUKQwgRMqXLkkW2aB3 3C8kQ5oG qrblR7WDGqb2SP+t6lTXcg8xHV7ba4fMm5he9+95O4JT31hsZQRqbPGCw3cN/XWyMJbBYODnAcembQrvlvHb8vrlRlum6eBrodIsSbYMG3tuwpd6MZj/q9zyv6bM23RJaoRyhFjpP437fhXYjd96QqHWH7AjaOKaiOuqx9eo6MjieozXwNLPcqAzjvXK61ZhfiAvYZSKbbMqdwkeu3bOQnknoBDfpJYbCUHP752JxY0Mr/PcpB8tnjN+pyI6jFpbrvxFRnHCNLF7i40mptANowZ2K7l/hi5tpEDjFMw1GytQnwYDRdaybcG/HzBEpTzbENq14 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: On 2023/6/30 1:26, Catalin Marinas wrote: > On Thu, Jun 29, 2023 at 05:31:36PM +0100, Catalin Marinas wrote: >> On Thu, May 18, 2023 at 02:59:34PM +0800, Yicong Yang wrote: >>> From: Barry Song >>> >>> on x86, batched and deferred tlb shootdown has lead to 90% >>> performance increase on tlb shootdown. on arm64, HW can do >>> tlb shootdown without software IPI. But sync tlbi is still >>> quite expensive. >> [...] >>> .../features/vm/TLB/arch-support.txt | 2 +- >>> arch/arm64/Kconfig | 1 + >>> arch/arm64/include/asm/tlbbatch.h | 12 ++++ >>> arch/arm64/include/asm/tlbflush.h | 33 ++++++++- >>> arch/arm64/mm/flush.c | 69 +++++++++++++++++++ >>> arch/x86/include/asm/tlbflush.h | 5 +- >>> include/linux/mm_types_task.h | 4 +- >>> mm/rmap.c | 12 ++-- >> >> First of all, this patch needs to be split in some preparatory patches >> introducing/renaming functions with no functional change for x86. Once >> done, you can add the arm64-only changes. >> got it. will try to split this patch as suggested. >> Now, on the implementation, I had some comments on v7 but we didn't get >> to a conclusion and the thread eventually died: >> >> https://lore.kernel.org/linux-mm/Y7cToj5mWd1ZbMyQ@arm.com/ >> >> I know I said a command line argument is better than Kconfig or some >> random number of CPUs heuristics but it would be even better if we don't >> bother with any, just make this always on. ok, will make this always on. >> Barry had some comments >> around mprotect() being racy and that's why we have >> flush_tlb_batched_pending() but I don't think it's needed (or, for >> arm64, it can be a DSB since this patch issues the TLBIs but without the >> DVM Sync). So we need to clarify this (see Barry's last email on the >> above thread) and before attempting new versions of this patchset. With >> flush_tlb_batched_pending() removed (or DSB), I have a suspicion such >> implementation would be faster on any SoC irrespective of the number of >> CPUs. > > I think I got the need for flush_tlb_batched_pending(). If > try_to_unmap() marks the pte !present and we have a pending TLBI, > change_pte_range() will skip the TLB maintenance altogether since it did > not change the pte. So we could be left with stale TLB entries after > mprotect() before TTU does the batch flushing. > > We can have an arch-specific flush_tlb_batched_pending() that can be a > DSB only on arm64 and a full mm flush on x86. > We need to do a flush/dsb in flush_tlb_batched_pending() only in a race condition so we first check whether there's a pended batched flush and if so do the tlb flush. The pending checking is common and the differences among the archs is how to flush the TLB here within the flush_tlb_batched_pending(), on arm64 it should only be a dsb. As we only needs to maintain the TLBs already pended in batched flush, does it make sense to only handle those TLBs in flush_tlb_batched_pending()? Then we can use the arch_tlbbatch_flush() rather than flush_tlb_mm() in flush_tlb_batched_pending() and no arch specific function needed. Thanks.