From patchwork Thu May 18 06:59:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 13246228 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 A5FDFC7EE30 for ; Thu, 18 May 2023 07:01:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DC9D900006; Thu, 18 May 2023 03:01:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01747900003; Thu, 18 May 2023 03:01:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD31E900006; Thu, 18 May 2023 03:01:02 -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 CEFED900003 for ; Thu, 18 May 2023 03:01:02 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1754680782 for ; Thu, 18 May 2023 07:01:02 +0000 (UTC) X-FDA: 80802478764.05.22295B7 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf12.hostedemail.com (Postfix) with ESMTP id 3AEB540011 for ; Thu, 18 May 2023 07:00:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of yangyicong@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=yangyicong@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684393260; 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=/FdQBoynq797h7AEzDerrzeJcLQqdQWoZ8pRd7Xhtkk=; b=iomS58Cg78yT0DLcNd41jennS3m5VvseDWiSmTiZnumlNcBCyC3MdYWfaK7rc4ja1IMJE3 IR8Paxistxej8S9QFc5k4jexw6OacPy0pseWfOE8/iSU6phwauJiLb3sdP51WJitMBYD1d MEN92AfDc8CVB+lJHQTAVkBxMwn6hPA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684393260; a=rsa-sha256; cv=none; b=ZHtPHkZbKN3cfp92lHUmPPRm1rbct7BAJuD+MnEj0JLXIrglK/DLixUw/e7sO5HVeeNavi +0LcF9A7aGQ0+fIwexVzYgl2hNrO5SUEm/rfiMBXOeWSZ4k0nojDMwF76mR9PiAopNKriI jBbv9cmLALrsyDnUM26JmDVDHGz8c4U= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of yangyicong@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=yangyicong@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QMLSM2gRqzLmLy; Thu, 18 May 2023 14:59:31 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) 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.23; Thu, 18 May 2023 15:00:52 +0800 From: Yicong Yang To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , Barry Song <21cnbao@gmail.com>, , , , , Anshuman Khandual , Barry Song Subject: [RESEND PATCH v9 1/2] mm/tlbbatch: Introduce arch_tlbbatch_should_defer() Date: Thu, 18 May 2023 14:59:33 +0800 Message-ID: <20230518065934.12877-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230518065934.12877-1-yangyicong@huawei.com> References: <20230518065934.12877-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 3AEB540011 X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: tyikrx6ibyxphcxzjh541mifb7puchu8 X-HE-Tag: 1684393258-51081 X-HE-Meta: U2FsdGVkX191GWYTLDzHTLovJvpnspdG0Umb0Gn7O1or+JnDDNCoC7jFi9Avb8SO6p1kjQf2zE3MP+j2t8icNPJz5mKcgilq4qSEdg4jR9vr+kwsfqhqbps6OobEAyFNknB8Y1IxVlq+g8URfIVBcorFpsfzczSIDsFAWEiipy9XdU3j8N69BEtedpLdLHlpD/0ktUKXYN/B17XmUA/B6/dChsj3HAMvB3JYi4DyNclWstsz0N5GOg3cI4jbo7FNmrW02xSXHca1UKDTJ7U+u2WO2WxUghWcZjuK9itE3xelyMxltOBnaRP1BX+eXzm0MIBg49U6tZhm0iHg/r7C8Sqqd61TFaCAMT8ubEvKDPAhLOLMpqJMNF3YzQPNYrnYOaYEE0rD9Sama5Qv6bL3OLm2NewaZKc1S57wiiJVqBL4H9P5PHZFuqMY5KGTO7X9PejNC7TIeFMWB34mkd0JJ3C9F8l57kJV55QB8iysbnkjUGrQkJc8rlCx2GwZvyTnkB+kL8SMCWy25U6O3Et2cCHb9kvkLLAfZktxsoBkb3WMihXA2Qb77Mb077GlYi3OfjLp6dfK+udh50WYSlyCPN47Blf71ze5V3IWHxBFll/AqhIEQIZFYf8PL5enWDvgH4G7afK45qBUqj3SwrrLz8g/N391mqTZM4ce1fC6KiJwG55Mrq8SYOyV49VfphQZRTGUjfsuk+cEo4BEKFSIaV03W/yvJavhiZRiGkmVCrye9AocXyaqc65BcM4kolvFBPF9iXDmMYz6x4bY1/sDBxH6OByWyzP7bCpuhQcNs0MD02P5awvNt6FYoIkAr3Cn1WtYbQEvHmvO9+LXYqkmLTMtO6xkKpm61IGxKl05X87BefDOxet18S3edMGuPMxvu/xUV6tjksdWae71dGjc23XeBbG0dpffFlJogaHDmsSYYzem/XUBAdlhcUGCiP20rG43YD+zGTZrBep+Bvm qEYEogf+ 8sNbi+Huu9UxyIv1aP5vEbxm+6pqvpnuvce/rPdW5U190RaBnlUghXnDk2YKBjgbAGMtYZ8OdF/n1uATrHN8N79kX694bl49i5w3erXvd8WVMHVLp1CARxAC4KLgwk9YKzybSzbxz1yac7XzcRlzglSBPc45afaD3tKNaum0Q+ZtGKG1MaUsjDtyQqqS4OfgBt5jAZBCMyzbk0ebtTtrvlJv3AvppTX7A72l7BbWX8ccwgXlx1uylLI712qC5tmKnb8/LNINKhtKsMiznmf7p71xc2JtBzDCenU5tNgcdD5AhzjpIt7QP7rXtQ185B+nboOMeAXYhSUtXHoNQl5R9MgwNS24GdvnMmtJH+/wKky65JCcZrGFScRnQluVsrstLmR/G7o1zvt3dQEvuJ2wPgaaHS1JwNR9dnMKpGoKUfLMr3IAgFTq7n27iuXJ8awTdST/0A4qytcx32WtiBZOGC3ZmJcwM2XXH9BMN 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: From: Anshuman Khandual The entire scheme of deferred TLB flush in reclaim path rests on the fact that the cost to refill TLB entries is less than flushing out individual entries by sending IPI to remote CPUs. But architecture can have different ways to evaluate that. Hence apart from checking TTU_BATCH_FLUSH in the TTU flags, rest of the decision should be architecture specific. Signed-off-by: Anshuman Khandual [https://lore.kernel.org/linuxppc-dev/20171101101735.2318-2-khandual@linux.vnet.ibm.com/] Signed-off-by: Yicong Yang [Rebase and fix incorrect return value type] Reviewed-by: Kefeng Wang Reviewed-by: Anshuman Khandual Reviewed-by: Barry Song Reviewed-by: Xin Hao Tested-by: Punit Agrawal --- arch/x86/include/asm/tlbflush.h | 12 ++++++++++++ mm/rmap.c | 9 +-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 75bfaa421030..46bdff73217c 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -260,6 +260,18 @@ static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long a) flush_tlb_mm_range(vma->vm_mm, a, a + PAGE_SIZE, PAGE_SHIFT, false); } +static inline bool arch_tlbbatch_should_defer(struct mm_struct *mm) +{ + bool should_defer = false; + + /* If remote CPUs need to be flushed then defer batch the flush */ + if (cpumask_any_but(mm_cpumask(mm), get_cpu()) < nr_cpu_ids) + should_defer = true; + put_cpu(); + + return should_defer; +} + static inline u64 inc_mm_tlb_gen(struct mm_struct *mm) { /* diff --git a/mm/rmap.c b/mm/rmap.c index 19392e090bec..b45f95ab0c04 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -688,17 +688,10 @@ static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval) */ static bool should_defer_flush(struct mm_struct *mm, enum ttu_flags flags) { - bool should_defer = false; - if (!(flags & TTU_BATCH_FLUSH)) return false; - /* If remote CPUs need to be flushed then defer batch the flush */ - if (cpumask_any_but(mm_cpumask(mm), get_cpu()) < nr_cpu_ids) - should_defer = true; - put_cpu(); - - return should_defer; + return arch_tlbbatch_should_defer(mm); } /*