Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7947175rwd; Tue, 20 Jun 2023 08:13:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5iGXEwJ0G2U9cZxh18ib0XmwgJsqZqVYP06z3FiFw+TrEvsLPmUAj+83ZsxWalNtNYgmE4 X-Received: by 2002:a17:90a:4ec3:b0:25b:ec3d:b687 with SMTP id v3-20020a17090a4ec300b0025bec3db687mr12303966pjl.37.1687274028702; Tue, 20 Jun 2023 08:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687274028; cv=none; d=google.com; s=arc-20160816; b=C8pbd/uywyLeEKB8X18/LRsaZvHQ66v3LSbljGInUtMPsIgvqRNTlfY6neQPLNk7z2 qvLT8UpBzapR/VhPDXCNldqS1++1aP3wom6/HYU5tAgqMfzb1lUPPIIXAM7ipWNGhTvW dRg+NTdgrWTKNpHn1Xq/MnmjcG+SZMHJVlTF2XcHvCdI0oWa/TeT4gpkJFHGx4SD+gSL 46r7REzJ1UcY+QrctLNW5VaZfnD7eckXPqJzt3gjGPOUowmNEIIQzXwfVFEyXjX5w3Zq dV00LbSL765m5HXTte3j+20WQoHQJIGDxxsyYfBOfqqcHaAmKONT289+TLN6cUXK1Nxa 1iXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IMVWP9uUwreYp41lBQlzx9rQqv8YUX+d+4RkZ35R+cQ=; b=gYvDUhs415Zxy+5O/OBnxt+Uta4MB0+D+nZyNq0CQW7r2JPCeEBEhD5CekHU+m/uyp EwEs0eB2JmUC0cTkQVPdvJDGIIctRSwGmt34n/j6tKNbvRBZaSlW/jB+WWL6QaVJGKOO nsK/q8G44NV+t1+Rc+ABip0K/xL7MP+sH2uA84WpGlxZr3ykwBhr3X9poomk4D+/v92c 8p6jVOZ3fF3UmpbloKmKa20SdJodZg07rDYa09h6/emrO2T7IOA5LGLOmW/oIkhB4+8u lHMDACk7A4ZCdFUO6gSAdfzFH3BD4AUVUDqRxKSlq6oUxbt3UH5gWhM+Z1yijw+N5tY9 LDyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hFw8/GzN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q9-20020a17090a2dc900b0025bf6078049si9923649pjm.5.2023.06.20.08.13.35; Tue, 20 Jun 2023 08:13:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hFw8/GzN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233533AbjFTPA1 (ORCPT + 99 others); Tue, 20 Jun 2023 11:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233660AbjFTPAM (ORCPT ); Tue, 20 Jun 2023 11:00:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35E7A1FF1 for ; Tue, 20 Jun 2023 07:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IMVWP9uUwreYp41lBQlzx9rQqv8YUX+d+4RkZ35R+cQ=; b=hFw8/GzNB7kssB9QN9tLq2iYmCxib3cQUPccbUZeyIA4OSQ3xtfmNkqHgr9SxpTfQ19pXB T5PZ0z5vPqoyRRwePxOXPu7IOjHf/xhPC8E1KwHZ9R+bUpyWElbv7suACLnbVoQTMWdvqe Nq/K/WKt4jWrq7iIOJFKhr/PByBaabM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-PGZ8P0JHPzaSP3c_R985HA-1; Tue, 20 Jun 2023 10:54:43 -0400 X-MC-Unique: PGZ8P0JHPzaSP3c_R985HA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AFAFA18E0072; Tue, 20 Jun 2023 14:46:51 +0000 (UTC) Received: from ypodemsk.tlv.csb (unknown [10.39.195.147]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E04889E9C; Tue, 20 Jun 2023 14:46:42 +0000 (UTC) From: Yair Podemsky To: mtosatti@redhat.com, ppandit@redhat.com, david@redhat.com, linux@armlinux.org.uk, mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, keescook@chromium.org, paulmck@kernel.org, frederic@kernel.org, will@kernel.org, peterz@infradead.org, ardb@kernel.org, samitolvanen@google.com, juerg.haefliger@canonical.com, arnd@arndb.de, rmk+kernel@armlinux.org.uk, geert+renesas@glider.be, linus.walleij@linaro.org, akpm@linux-foundation.org, sebastian.reichel@collabora.com, rppt@kernel.org, aneesh.kumar@linux.ibm.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: ypodemsk@redhat.com Subject: [PATCH v2 2/2] mm/mmu_gather: send tlb_remove_table_smp_sync IPI only to MM CPUs Date: Tue, 20 Jun 2023 17:46:18 +0300 Message-Id: <20230620144618.125703-3-ypodemsk@redhat.com> In-Reply-To: <20230620144618.125703-1-ypodemsk@redhat.com> References: <20230620144618.125703-1-ypodemsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the tlb_remove_table_smp_sync IPI is sent to all CPUs indiscriminately, this causes unnecessary work and delays notable in real-time use-cases and isolated cpus. This patch will limit this IPI on systems with ARCH_HAS_CPUMASK_BITS, Where the IPI will only be sent to cpus referencing the affected mm. Signed-off-by: Yair Podemsky Suggested-by: David Hildenbrand --- include/asm-generic/tlb.h | 4 ++-- mm/khugepaged.c | 4 ++-- mm/mmu_gather.c | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index b46617207c93..0b6ba17cc8d3 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -222,7 +222,7 @@ extern void tlb_remove_table(struct mmu_gather *tlb, void *table); #define tlb_needs_table_invalidate() (true) #endif -void tlb_remove_table_sync_one(void); +void tlb_remove_table_sync_one(struct mm_struct *mm); #else @@ -230,7 +230,7 @@ void tlb_remove_table_sync_one(void); #error tlb_needs_table_invalidate() requires MMU_GATHER_RCU_TABLE_FREE #endif -static inline void tlb_remove_table_sync_one(void) { } +static inline void tlb_remove_table_sync_one(struct mm_struct *mm) { } #endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6b9d39d65b73..3e5cb079d268 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1166,7 +1166,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, _pmd = pmdp_collapse_flush(vma, address, pmd); spin_unlock(pmd_ptl); mmu_notifier_invalidate_range_end(&range); - tlb_remove_table_sync_one(); + tlb_remove_table_sync_one(mm); spin_lock(pte_ptl); result = __collapse_huge_page_isolate(vma, address, pte, cc, @@ -1525,7 +1525,7 @@ static void collapse_and_free_pmd(struct mm_struct *mm, struct vm_area_struct *v addr + HPAGE_PMD_SIZE); mmu_notifier_invalidate_range_start(&range); pmd = pmdp_collapse_flush(vma, addr, pmdp); - tlb_remove_table_sync_one(); + tlb_remove_table_sync_one(mm); mmu_notifier_invalidate_range_end(&range); mm_dec_nr_ptes(mm); page_table_check_pte_clear_range(mm, addr, pmd); diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index ea9683e12936..692d8175a88e 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -191,7 +191,13 @@ static void tlb_remove_table_smp_sync(void *arg) /* Simply deliver the interrupt */ } -void tlb_remove_table_sync_one(void) +#ifdef CONFIG_ARCH_HAS_CPUMASK_BITS +#define REMOVE_TABLE_IPI_MASK mm_cpumask(mm) +#else +#define REMOVE_TABLE_IPI_MASK cpu_online_mask +#endif /* CONFIG_ARCH_HAS_CPUMASK_BITS */ + +void tlb_remove_table_sync_one(struct mm_struct *mm) { /* * This isn't an RCU grace period and hence the page-tables cannot be @@ -200,7 +206,8 @@ void tlb_remove_table_sync_one(void) * It is however sufficient for software page-table walkers that rely on * IRQ disabling. */ - smp_call_function(tlb_remove_table_smp_sync, NULL, 1); + on_each_cpu_mask(REMOVE_TABLE_IPI_MASK, tlb_remove_table_smp_sync, + NULL, true); } static void tlb_remove_table_rcu(struct rcu_head *head) @@ -237,9 +244,9 @@ static inline void tlb_table_invalidate(struct mmu_gather *tlb) } } -static void tlb_remove_table_one(void *table) +static void tlb_remove_table_one(struct mm_struct *mm, void *table) { - tlb_remove_table_sync_one(); + tlb_remove_table_sync_one(mm); __tlb_remove_table(table); } @@ -262,7 +269,7 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table) *batch = (struct mmu_table_batch *)__get_free_page(GFP_NOWAIT | __GFP_NOWARN); if (*batch == NULL) { tlb_table_invalidate(tlb); - tlb_remove_table_one(table); + tlb_remove_table_one(tlb->mm, table); return; } (*batch)->nr = 0; --- v2: replaced no REMOVE_TABLE_IPI_MASK REMOVE_TABLE_IPI_MASK to cpu_online_mask -- 2.39.3