From patchwork Mon Dec 14 06:53:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11971443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2048C1B0D8 for ; Mon, 14 Dec 2020 07:01:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 713F62078E for ; Mon, 14 Dec 2020 07:01:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 713F62078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B73E96B0036; Mon, 14 Dec 2020 02:01:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B22136B005C; Mon, 14 Dec 2020 02:01:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E9E66B005D; Mon, 14 Dec 2020 02:01:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 88F126B0036 for ; Mon, 14 Dec 2020 02:01:20 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4C11F8249980 for ; Mon, 14 Dec 2020 07:01:20 +0000 (UTC) X-FDA: 77590991520.01.camp27_6113e9827418 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 286621005114C for ; Mon, 14 Dec 2020 07:01:20 +0000 (UTC) X-HE-Tag: camp27_6113e9827418 X-Filterd-Recvd-Size: 9789 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Dec 2020 07:01:19 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id x12so7665468plr.10 for ; Sun, 13 Dec 2020 23:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MGjE6Oe6mVSK72UaRSxHAy5QAmJ4uKC6X/D55j0mgnM=; b=kav7cHCYxYQuP8L6G7ZPNKuglYUtblvdQ39I3dnJiAwNZgRQY2TsSzPWGCMwCWqqbb lyVHXwnCB19HUUWSPM+7iWZQz0OepzKgQfDd3n857+uXQgiU4NKMPcUDlyT/4sYEmFkB VmJnHhuKT1eOz8MrHCUwlh/f6XRrW25VPE1LLBcpRjD/VAD8cu0hPT5GbJj6OTQLJs1Z UaeHk1ogQBpVAao0lwAYzGsUDM6hWOv13AyjisgMVY4DffUUaDL6mf4XQOAUIJ3ymFf1 aaau/HcMhHWntY1Po3WpyQXFnY1E86dlvecwBVDhA/IYMqM2O1t7/p9lciMiUUMBthC5 zpjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MGjE6Oe6mVSK72UaRSxHAy5QAmJ4uKC6X/D55j0mgnM=; b=btqZqyVmVS4maa6/NmvYV0rU+JschNuT/p0W264zliu46srkFD9tLE4qrRjYaUoF+G fbvoQ9mb/AcBBT7DyvkJqM0Zrvn0JplkfkEdn0FdrJvQARDxPYfnFKvkwdIZhQXrJ+A0 JyTeeRnTk6V0s6frwYWID96HRspJFDnUrmF79a+3r3YGD6MGxtjqdZYvEIXvlR9dQj/V PMEMORcEQakx/LNvof1IC/4BeC0s79W9jxzYiVcbTmt+t+5kFyNRxNrfEqI+ziVOhomg 4IULZ+n72ofbLtqB4LPEUPaQcY6qtgsU9f8kPij9Z11yBO2tFyCxnBeaPUZtuZwXIsHP OOSw== X-Gm-Message-State: AOAM5318hSzuuf2l9PwOa0GH+/L+rME5hqxFEtD/Uph26coUhqmJOVP7 nuzXiDocvR8Wky260je79Nk= X-Google-Smtp-Source: ABdhPJxJOUrDaqX3qExF0UOrRm/OWxZCHdgQA3sDhREGOfNyDxgCR36pLLdlpYpGj+IZTqgueJG6wg== X-Received: by 2002:a17:902:d38b:b029:db:e003:3ff0 with SMTP id e11-20020a170902d38bb02900dbe0033ff0mr17491568pld.7.1607929278513; Sun, 13 Dec 2020 23:01:18 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.228.148]) by smtp.gmail.com with ESMTPSA id 84sm19570018pfy.9.2020.12.13.23.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Dec 2020 23:01:18 -0800 (PST) From: Nicholas Piggin To: linux-kernel@vger.kernel.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Anton Blanchard , Andy Lutomirski Subject: [PATCH v2 1/5] lazy tlb: introduce lazy mm refcount helper functions Date: Mon, 14 Dec 2020 16:53:08 +1000 Message-Id: <20201214065312.270062-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201214065312.270062-1-npiggin@gmail.com> References: <20201214065312.270062-1-npiggin@gmail.com> MIME-Version: 1.0 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: Add explicit _lazy_tlb annotated functions for lazy mm refcounting. This makes things a bit more explicit, and allows explicit refcounting to be removed if it is not used. Signed-off-by: Nicholas Piggin --- arch/arm/mach-rpc/ecard.c | 2 +- arch/powerpc/mm/book3s64/radix_tlb.c | 4 ++-- fs/exec.c | 4 ++-- include/linux/sched/mm.h | 11 +++++++++++ kernel/cpu.c | 2 +- kernel/exit.c | 2 +- kernel/kthread.c | 11 +++++++---- kernel/sched/core.c | 15 ++++++++------- 8 files changed, 33 insertions(+), 18 deletions(-) diff --git a/arch/arm/mach-rpc/ecard.c b/arch/arm/mach-rpc/ecard.c index 827b50f1c73e..1b4a41aad793 100644 --- a/arch/arm/mach-rpc/ecard.c +++ b/arch/arm/mach-rpc/ecard.c @@ -253,7 +253,7 @@ static int ecard_init_mm(void) current->mm = mm; current->active_mm = mm; activate_mm(active_mm, mm); - mmdrop(active_mm); + mmdrop_lazy_tlb(active_mm); ecard_init_pgtables(mm); return 0; } diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c b/arch/powerpc/mm/book3s64/radix_tlb.c index b487b489d4b6..74708aef333e 100644 --- a/arch/powerpc/mm/book3s64/radix_tlb.c +++ b/arch/powerpc/mm/book3s64/radix_tlb.c @@ -658,10 +658,10 @@ static void do_exit_flush_lazy_tlb(void *arg) if (current->active_mm == mm) { WARN_ON_ONCE(current->mm != NULL); /* Is a kernel thread and is using mm as the lazy tlb */ - mmgrab(&init_mm); + mmgrab_lazy_tlb(&init_mm); current->active_mm = &init_mm; switch_mm_irqs_off(mm, &init_mm, current); - mmdrop(mm); + mmdrop_lazy_tlb(mm); } atomic_dec(&mm->context.active_cpus); diff --git a/fs/exec.c b/fs/exec.c index 547a2390baf5..56fc23dcbe4d 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1028,9 +1028,9 @@ static int exec_mmap(struct mm_struct *mm) setmax_mm_hiwater_rss(&tsk->signal->maxrss, old_mm); mm_update_next_owner(old_mm); mmput(old_mm); - return 0; + } else { + mmdrop_lazy_tlb(active_mm); } - mmdrop(active_mm); return 0; } diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index d5ece7a9a403..94a117160083 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -49,6 +49,17 @@ static inline void mmdrop(struct mm_struct *mm) __mmdrop(mm); } +/* Helpers for lazy TLB mm refcounting */ +static inline void mmgrab_lazy_tlb(struct mm_struct *mm) +{ + mmgrab(mm); +} + +static inline void mmdrop_lazy_tlb(struct mm_struct *mm) +{ + mmdrop(mm); +} + /** * mmget() - Pin the address space associated with a &struct mm_struct. * @mm: The address space to pin. diff --git a/kernel/cpu.c b/kernel/cpu.c index 2b8d7a5db383..a54cdfa08d71 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -576,7 +576,7 @@ static int finish_cpu(unsigned int cpu) */ if (mm != &init_mm) idle->active_mm = &init_mm; - mmdrop(mm); + mmdrop_lazy_tlb(mm); return 0; } diff --git a/kernel/exit.c b/kernel/exit.c index 1f236ed375f8..3711a74fcf4a 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -474,7 +474,7 @@ static void exit_mm(void) __set_current_state(TASK_RUNNING); mmap_read_lock(mm); } - mmgrab(mm); + mmgrab_lazy_tlb(mm); BUG_ON(mm != current->active_mm); /* more a memory barrier than a real lock */ task_lock(current); diff --git a/kernel/kthread.c b/kernel/kthread.c index 933a625621b8..da189e0d26ed 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -1240,14 +1240,14 @@ void kthread_use_mm(struct mm_struct *mm) WARN_ON_ONCE(!(tsk->flags & PF_KTHREAD)); WARN_ON_ONCE(tsk->mm); + mmgrab(mm); + task_lock(tsk); /* Hold off tlb flush IPIs while switching mm's */ local_irq_disable(); active_mm = tsk->active_mm; - if (active_mm != mm) { - mmgrab(mm); + if (active_mm != mm) tsk->active_mm = mm; - } tsk->mm = mm; switch_mm_irqs_off(active_mm, mm, tsk); local_irq_enable(); @@ -1257,7 +1257,7 @@ void kthread_use_mm(struct mm_struct *mm) #endif if (active_mm != mm) - mmdrop(active_mm); + mmdrop_lazy_tlb(active_mm); to_kthread(tsk)->oldfs = force_uaccess_begin(); } @@ -1280,10 +1280,13 @@ void kthread_unuse_mm(struct mm_struct *mm) sync_mm_rss(mm); local_irq_disable(); tsk->mm = NULL; + mmgrab_lazy_tlb(mm); /* active_mm is still 'mm' */ enter_lazy_tlb(mm, tsk); local_irq_enable(); task_unlock(tsk); + + mmdrop(mm); } EXPORT_SYMBOL_GPL(kthread_unuse_mm); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e7e453492cff..c2f8ea43d29b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3629,13 +3629,14 @@ static struct rq *finish_task_switch(struct task_struct *prev) * rq->curr, before returning to userspace, so provide them here: * * - a full memory barrier for {PRIVATE,GLOBAL}_EXPEDITED, implicitly - * provided by mmdrop(), + * provided by mmdrop_lazy_tlb(), * - a sync_core for SYNC_CORE. */ if (mm) { membarrier_mm_sync_core_before_usermode(mm); - mmdrop(mm); + mmdrop_lazy_tlb(mm); } + if (unlikely(prev_state == TASK_DEAD)) { if (prev->sched_class->task_dead) prev->sched_class->task_dead(prev); @@ -3739,9 +3740,9 @@ context_switch(struct rq *rq, struct task_struct *prev, /* * kernel -> kernel lazy + transfer active - * user -> kernel lazy + mmgrab() active + * user -> kernel lazy + mmgrab_lazy_tlb() active * - * kernel -> user switch + mmdrop() active + * kernel -> user switch + mmdrop_lazy_tlb() active * user -> user switch */ if (!next->mm) { // to kernel @@ -3749,7 +3750,7 @@ context_switch(struct rq *rq, struct task_struct *prev, next->active_mm = prev->active_mm; if (prev->mm) // from user - mmgrab(prev->active_mm); + mmgrab_lazy_tlb(prev->active_mm); else prev->active_mm = NULL; } else { // to user @@ -3765,7 +3766,7 @@ context_switch(struct rq *rq, struct task_struct *prev, switch_mm_irqs_off(prev->active_mm, next->mm, next); if (!prev->mm) { // from kernel - /* will mmdrop() in finish_task_switch(). */ + /* will mmdrop_lazy_tlb() in finish_task_switch(). */ rq->prev_mm = prev->active_mm; prev->active_mm = NULL; } @@ -7206,7 +7207,7 @@ void __init sched_init(void) /* * The boot idle thread does lazy MMU switching as well: */ - mmgrab(&init_mm); + mmgrab_lazy_tlb(&init_mm); enter_lazy_tlb(&init_mm, current); /* From patchwork Mon Dec 14 06:53:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11971445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC366C4361B for ; Mon, 14 Dec 2020 07:01:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6EF5A22583 for ; Mon, 14 Dec 2020 07:01:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EF5A22583 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B4C356B005C; Mon, 14 Dec 2020 02:01:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B23CC6B005D; Mon, 14 Dec 2020 02:01:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A13136B0068; Mon, 14 Dec 2020 02:01:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 8349B6B005C for ; Mon, 14 Dec 2020 02:01:24 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 47C182C89 for ; Mon, 14 Dec 2020 07:01:24 +0000 (UTC) X-FDA: 77590991688.12.road65_160e4c327418 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 0E7DD18015DBF for ; Mon, 14 Dec 2020 07:01:24 +0000 (UTC) X-HE-Tag: road65_160e4c327418 X-Filterd-Recvd-Size: 9710 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Dec 2020 07:01:23 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id b5so6061383pjl.0 for ; Sun, 13 Dec 2020 23:01:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tTzD/PwVnUryCFsCtBkXOLSBdB20HGAb9puUxId4JVk=; b=IR9n6Xx3XA7TWORm+admowft3H2sA37sBIcd+GaFLOP0qFk15JB6uoOrHhMuzatwsC HQ26+f50MnEXp3JmLnlvTNWfB67/uTwwboaOXijLrWMS6goDqh1RGiVPj6YwHXedhuRY ONdoimeRGscvIVFc1AQRLCydCRLvZxavxCIVqjhlqtBuGaHa2ynhR8Y6wfovleCF/YR/ 8TzsXLnt+Plc6HEfBAzkyeRebiyMGgTwde7hSwzi50i/1jG056NrAeoOuUjU7F6IIrfA Pj80cWPZLza80QoJ00gbstNsZK2bmcjZeoCU3aGM10vTa0vfEgq5iccJ+843aJqUDBJn V/QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tTzD/PwVnUryCFsCtBkXOLSBdB20HGAb9puUxId4JVk=; b=cKkQqkPEWzAg2lEBY3iuv8U+Fhi4OFBDkvareIjitmslWE/bfzSAitGv2tdaR9Wtko Y0mktMU8qTuyTTyouRKtDGfIAOru1F7Eo9Ad9bHu9Pwbm51tvb7j8jaLn/XIa/07Ycig jUn9DyKojYQk/O+9kcw0BPENXKiDWB13tRxlkqAeoB3E+2cknYYV4JjYMqDWutewHsrq iFRZ6cRkIH/aAwzt7YG9Iq24NLVBvGEwkS0d7vqA4Q2a3tPjeT7Y22SvKKDVFd+pkIQz Y1wsk7G+8zEsW4YrQ6CQuMcTfJe42nCzbf7fFqZJTGENJ3Lxc5bspdOGtCzFb4GStlTZ 5uGQ== X-Gm-Message-State: AOAM532D8puOSWGhJ1Hp4PN2P++7s3+SF7Tlp51zxtuVhcp0Qs/tZ5Iy 7aORllOkmNmVYyZqyDhdQqM= X-Google-Smtp-Source: ABdhPJwxGbCiA5g+oFBRL0MsR3yqlxPJyXmC3pmGD+mzl4QTJz+fHRqE9o5Gyew/trGb6oI0bDkZuQ== X-Received: by 2002:a17:902:7887:b029:dc:20e:47ff with SMTP id q7-20020a1709027887b02900dc020e47ffmr2078675pll.65.1607929282651; Sun, 13 Dec 2020 23:01:22 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.228.148]) by smtp.gmail.com with ESMTPSA id 84sm19570018pfy.9.2020.12.13.23.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Dec 2020 23:01:22 -0800 (PST) From: Nicholas Piggin To: linux-kernel@vger.kernel.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Anton Blanchard , Andy Lutomirski Subject: [PATCH v2 2/5] lazy tlb: allow lazy tlb mm switching to be configurable Date: Mon, 14 Dec 2020 16:53:09 +1000 Message-Id: <20201214065312.270062-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201214065312.270062-1-npiggin@gmail.com> References: <20201214065312.270062-1-npiggin@gmail.com> MIME-Version: 1.0 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: Add CONFIG_MMU_LAZY_TLB which can be configured out to disable the lazy tlb mechanism entirely, and switches to init_mm when switching to a kernel thread. NOMMU systems could easily go without this and save a bit of code and the refcount atomics, because their mm switch is a no-op. They have not been switched over by default because the arch code needs to be audited and tested for lazy tlb mm refcounting and converted to _lazy_tlb refcounting if necessary. CONFIG_MMU_LAZY_TLB_REFCOUNT is also added, but it must always be enabled if CONFIG_MMU_LAZY_TLB is enabled until the next patch which provides an alternate scheme. Signed-off-by: Nicholas Piggin --- arch/Kconfig | 17 +++++++++ include/linux/sched/mm.h | 13 +++++-- kernel/sched/core.c | 75 ++++++++++++++++++++++++++++++---------- kernel/sched/sched.h | 4 ++- 4 files changed, 87 insertions(+), 22 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index ba4e966484ab..84faaba66364 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -430,6 +430,23 @@ config ARCH_WANT_IRQS_OFF_ACTIVATE_MM irqs disabled over activate_mm. Architectures that do IPI based TLB shootdowns should enable this. +# Should make this depend on MMU, because there is little use for lazy mm switching +# with NOMMU. Must audit NOMMU architecture code for lazy mm refcounting first. +config MMU_LAZY_TLB + def_bool y + help + Enable "lazy TLB" mmu context switching for kernel threads. + If this is disabled then switching to a kernel thread always + switches to init_mm. If mm switches are inexpensive or free + (in the case of NOMMU) then this could be disabled. + +config MMU_LAZY_TLB_REFCOUNT + def_bool y + depends on MMU_LAZY_TLB + help + This must be enabled if MMU_LAZY_TLB is enabled until the next + patch. + config ARCH_HAVE_NMI_SAFE_CMPXCHG bool diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 94a117160083..5edf8e942c84 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -52,12 +52,21 @@ static inline void mmdrop(struct mm_struct *mm) /* Helpers for lazy TLB mm refcounting */ static inline void mmgrab_lazy_tlb(struct mm_struct *mm) { - mmgrab(mm); + if (IS_ENABLED(CONFIG_MMU_LAZY_TLB_REFCOUNT)) + mmgrab(mm); } static inline void mmdrop_lazy_tlb(struct mm_struct *mm) { - mmdrop(mm); + if (IS_ENABLED(CONFIG_MMU_LAZY_TLB_REFCOUNT)) { + mmdrop(mm); + } else { + /* + * mmdrop_lazy_tlb must provide a full memory barrier, see the + * membarrier comment finish_task_switch which relies on this. + */ + smp_mb(); + } } /** diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c2f8ea43d29b..9c1dc9406e4b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3579,7 +3579,7 @@ static struct rq *finish_task_switch(struct task_struct *prev) __releases(rq->lock) { struct rq *rq = this_rq(); - struct mm_struct *mm = rq->prev_mm; + struct mm_struct *mm = NULL; long prev_state; /* @@ -3598,7 +3598,10 @@ static struct rq *finish_task_switch(struct task_struct *prev) current->comm, current->pid, preempt_count())) preempt_count_set(FORK_PREEMPT_COUNT); - rq->prev_mm = NULL; +#ifdef CONFIG_MMU_LAZY_TLB_REFCOUNT + mm = rq->prev_lazy_mm; + rq->prev_lazy_mm = NULL; +#endif /* * A task struct has one reference for the use as "current". @@ -3722,22 +3725,10 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev) calculate_sigpending(); } -/* - * context_switch - switch to the new MM and the new thread's register state. - */ -static __always_inline struct rq * -context_switch(struct rq *rq, struct task_struct *prev, - struct task_struct *next, struct rq_flags *rf) +static __always_inline void +context_switch_mm(struct rq *rq, struct task_struct *prev, + struct task_struct *next) { - prepare_task_switch(rq, prev, next); - - /* - * For paravirt, this is coupled with an exit in switch_to to - * combine the page table reload and the switch backend into - * one hypercall. - */ - arch_start_context_switch(prev); - /* * kernel -> kernel lazy + transfer active * user -> kernel lazy + mmgrab_lazy_tlb() active @@ -3766,11 +3757,57 @@ context_switch(struct rq *rq, struct task_struct *prev, switch_mm_irqs_off(prev->active_mm, next->mm, next); if (!prev->mm) { // from kernel - /* will mmdrop_lazy_tlb() in finish_task_switch(). */ - rq->prev_mm = prev->active_mm; +#ifdef CONFIG_MMU_LAZY_TLB_REFCOUNT + /* Will mmdrop_lazy_tlb() in finish_task_switch(). */ + rq->prev_lazy_mm = prev->active_mm; prev->active_mm = NULL; +#else + /* + * Without MMU_LAZY_REFCOUNT there is no lazy + * tracking (because no rq->prev_lazy_mm) in + * finish_task_switch, so no mmdrop_lazy_tlb(), + * so no memory barrier for membarrier (see the + * membarrier comment in finish_task_switch()). + * Do it here. + */ + smp_mb(); +#endif } } +} + +static __always_inline void +context_switch_mm_nolazy(struct rq *rq, struct task_struct *prev, + struct task_struct *next) +{ + if (!next->mm) + next->active_mm = &init_mm; + membarrier_switch_mm(rq, prev->active_mm, next->active_mm); + switch_mm_irqs_off(prev->active_mm, next->active_mm, next); + if (!prev->mm) + prev->active_mm = NULL; +} + +/* + * context_switch - switch to the new MM and the new thread's register state. + */ +static __always_inline struct rq * +context_switch(struct rq *rq, struct task_struct *prev, + struct task_struct *next, struct rq_flags *rf) +{ + prepare_task_switch(rq, prev, next); + + /* + * For paravirt, this is coupled with an exit in switch_to to + * combine the page table reload and the switch backend into + * one hypercall. + */ + arch_start_context_switch(prev); + + if (IS_ENABLED(CONFIG_MMU_LAZY_TLB)) + context_switch_mm(rq, prev, next); + else + context_switch_mm_nolazy(rq, prev, next); rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index df80bfcea92e..3b72aec5a2f2 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -950,7 +950,9 @@ struct rq { struct task_struct *idle; struct task_struct *stop; unsigned long next_balance; - struct mm_struct *prev_mm; +#ifdef CONFIG_MMU_LAZY_TLB_REFCOUNT + struct mm_struct *prev_lazy_mm; +#endif unsigned int clock_update_flags; u64 clock; From patchwork Mon Dec 14 06:53:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11971447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B2C0C4361B for ; Mon, 14 Dec 2020 07:01:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A8EC122583 for ; Mon, 14 Dec 2020 07:01:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8EC122583 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1AD856B005D; Mon, 14 Dec 2020 02:01:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 15F116B0068; Mon, 14 Dec 2020 02:01:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04BE16B006C; Mon, 14 Dec 2020 02:01:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id E4EF96B005D for ; Mon, 14 Dec 2020 02:01:27 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B4377181AEF3E for ; Mon, 14 Dec 2020 07:01:27 +0000 (UTC) X-FDA: 77590991814.07.house38_570fb2527418 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 9CAAD1803F9D1 for ; Mon, 14 Dec 2020 07:01:27 +0000 (UTC) X-HE-Tag: house38_570fb2527418 X-Filterd-Recvd-Size: 7460 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Dec 2020 07:01:27 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id t6so8144215plq.1 for ; Sun, 13 Dec 2020 23:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ErbENPowD2FhE1fb1KE1SS0KG3DGxAufvlmv8VFmkMA=; b=JvZByPsEXrHdPtVKtHVHGjkSpux7toHopC3Q55F7zTqqwwZ5PHppHHXxc6aXSO6GKB oyfie9gW09mQYPvCRKvx9HMxCB/osCbn29u7jDRUFzqv5IiRSR77KNbem7qfl7TQ7VUq C9p49cwE2Z6FNPa8ejWQnty9JN4XxkoGCm7S49R9NFlkO1txIrWjl5Z0FzqZO3U9viux 06U/I73Dqc+hEzgAZKfCwyUDsCgR7/YUn5DN4UjjGictkGOGay7x42N+o++kqKFggq9l nEnjpbRT8HjzsjpOspZdyeyToedAZplx5wUK8CINpXTu1fCREsOLVQFWrEo8h2bLGOKx zZ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ErbENPowD2FhE1fb1KE1SS0KG3DGxAufvlmv8VFmkMA=; b=AL+/vzumhgDhtDVbjAAp28eta/+OVb/4yD24dT/jVRLOEmdC6F/GdVBsRKhVM6TZGs LZQx0MpPYadJDKhKU+IvajP4RLxP38oLoiDlskKlMtNIOthwRsbH7M9BYfegRqGZ2Pkc TT6U7cMhV7VaUC2kXimh0wrjRIpzVZmApCLFiiAvetcRQQUrx0NDXu+Z1BKozPGic1nh 86NfRLA3P8uqniBC+sD3U/P/nEJaiZrxo4jEVB4PRJBO87UnrB7F/hUTWH2JJ1TzRBtx z821AuFU7h3BPF5pyX1wMZukIuRtVlzJGvDZU+mLasyFUBz/S+R/fPbViwGpQ7BIq4cQ IUEw== X-Gm-Message-State: AOAM530fQxKroaK46j8Dwwk2lLUF6aWcXkCNnwHil5BYG88EAFYDbMQh LD0l11FRZ8D2GKhRVEJY7Gw= X-Google-Smtp-Source: ABdhPJxblJXiLKkz13t9MjdDE/WHdnRvcf7rwmiGCqMnrUDtgxWEAmDxtkk08GCN+5bnN8Huo5IieQ== X-Received: by 2002:a17:902:b415:b029:d6:ec35:755b with SMTP id x21-20020a170902b415b02900d6ec35755bmr21304417plr.47.1607929286389; Sun, 13 Dec 2020 23:01:26 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.228.148]) by smtp.gmail.com with ESMTPSA id 84sm19570018pfy.9.2020.12.13.23.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Dec 2020 23:01:26 -0800 (PST) From: Nicholas Piggin To: linux-kernel@vger.kernel.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Anton Blanchard , Andy Lutomirski Subject: [PATCH v2 3/5] lazy tlb: shoot lazies, a non-refcounting lazy tlb option Date: Mon, 14 Dec 2020 16:53:10 +1000 Message-Id: <20201214065312.270062-4-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201214065312.270062-1-npiggin@gmail.com> References: <20201214065312.270062-1-npiggin@gmail.com> MIME-Version: 1.0 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 big systems, the mm refcount can become highly contented when doing a lot of context switching with threaded applications (particularly switching between the idle thread and an application thread). Abandoning lazy tlb slows switching down quite a bit in the important user->idle->user cases, so instead implement a non-refcounted scheme that causes __mmdrop() to IPI all CPUs in the mm_cpumask and shoot down any remaining lazy ones. Shootdown IPIs are some concern, but they have not been observed to be a big problem with this scheme (the powerpc implementation generated 314 additional interrupts on a 144 CPU system during a kernel compile). There are a number of strategies that could be employed to reduce IPIs if they turn out to be a problem for some workload. Signed-off-by: Nicholas Piggin --- arch/Kconfig | 17 +++++++++++++++-- kernel/fork.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 84faaba66364..e69c974369cc 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -443,9 +443,22 @@ config MMU_LAZY_TLB config MMU_LAZY_TLB_REFCOUNT def_bool y depends on MMU_LAZY_TLB + depends on !MMU_LAZY_TLB_SHOOTDOWN help - This must be enabled if MMU_LAZY_TLB is enabled until the next - patch. + This refcounts the mm that is used as the lazy TLB mm when switching + switching to a kernel thread. + +config MMU_LAZY_TLB_SHOOTDOWN + bool + depends on MMU_LAZY_TLB + help + Instead of refcounting the "lazy tlb" mm struct, which can cause + contention with multi-threaded apps on large multiprocessor systems, + this option causes __mmdrop to IPI all CPUs in the mm_cpumask and + switch to init_mm if they were using the to-be-freed mm as the lazy + tlb. To implement this, architectures must use _lazy_tlb variants of + mm refcounting, and mm_cpumask must include at least all possible + CPUs in which mm might be lazy. config ARCH_HAVE_NMI_SAFE_CMPXCHG bool diff --git a/kernel/fork.c b/kernel/fork.c index 6d266388d380..74b972d2d8a9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -669,6 +669,53 @@ static void check_mm(struct mm_struct *mm) #define allocate_mm() (kmem_cache_alloc(mm_cachep, GFP_KERNEL)) #define free_mm(mm) (kmem_cache_free(mm_cachep, (mm))) +static void do_shoot_lazy_tlb(void *arg) +{ + struct mm_struct *mm = arg; + + if (current->active_mm == mm) { + WARN_ON_ONCE(current->mm); + current->active_mm = &init_mm; + switch_mm(mm, &init_mm, current); + } +} + +static void do_check_lazy_tlb(void *arg) +{ + struct mm_struct *mm = arg; + + WARN_ON_ONCE(current->active_mm == mm); +} + +static void shoot_lazy_tlbs(struct mm_struct *mm) +{ + if (IS_ENABLED(CONFIG_MMU_LAZY_TLB_SHOOTDOWN)) { + /* + * IPI overheads have not found to be expensive, but they could + * be reduced in a number of possible ways, for example (in + * roughly increasing order of complexity): + * - A batch of mms requiring IPIs could be gathered and freed + * at once. + * - CPUs could store their active mm somewhere that can be + * remotely checked without a lock, to filter out + * false-positives in the cpumask. + * - After mm_users or mm_count reaches zero, switching away + * from the mm could clear mm_cpumask to reduce some IPIs + * (some batching or delaying would help). + * - A delayed freeing and RCU-like quiescing sequence based on + * mm switching to avoid IPIs completely. + */ + on_each_cpu_mask(mm_cpumask(mm), do_shoot_lazy_tlb, (void *)mm, 1); + if (IS_ENABLED(CONFIG_DEBUG_VM)) + on_each_cpu(do_check_lazy_tlb, (void *)mm, 1); + } else { + /* + * In this case, lazy tlb mms are refounted and would not reach + * __mmdrop until all CPUs have switched away and mmdrop()ed. + */ + } +} + /* * Called when the last reference to the mm * is dropped: either by a lazy thread or by @@ -678,7 +725,12 @@ void __mmdrop(struct mm_struct *mm) { BUG_ON(mm == &init_mm); WARN_ON_ONCE(mm == current->mm); + + /* Ensure no CPUs are using this as their lazy tlb mm */ + shoot_lazy_tlbs(mm); + WARN_ON_ONCE(mm == current->active_mm); + mm_free_pgd(mm); destroy_context(mm); mmu_notifier_subscriptions_destroy(mm); From patchwork Mon Dec 14 06:53:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11971449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCEB6C4361B for ; Mon, 14 Dec 2020 07:01:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 527122078E for ; Mon, 14 Dec 2020 07:01:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 527122078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E2F926B0068; Mon, 14 Dec 2020 02:01:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE1ED6B006C; Mon, 14 Dec 2020 02:01:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF7896B006E; Mon, 14 Dec 2020 02:01:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id B7C686B0068 for ; Mon, 14 Dec 2020 02:01:31 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7DF0A3644 for ; Mon, 14 Dec 2020 07:01:31 +0000 (UTC) X-FDA: 77590991982.23.dust09_4f0f69427418 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 60BE737604 for ; Mon, 14 Dec 2020 07:01:31 +0000 (UTC) X-HE-Tag: dust09_4f0f69427418 X-Filterd-Recvd-Size: 3674 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Dec 2020 07:01:30 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id 4so8134774plk.5 for ; Sun, 13 Dec 2020 23:01:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qp8PGJSLWU/dwswnH2/0kSDHsb+wln5XeqPaVW1B5Z8=; b=ah+DQFnviIYaiwW61xx/7aV1EqG6uLPtWc0d5mLXZjof3NJGVQvvrolW/w4GehwsgZ Kjz865XZJBwN7csGduekgiDndqDQMMkH63AuRBe60gEq1+3hlOynV/QU29ZZHZy1dmuh YqRxTfXSx5g3thhMEubi88ti01h4X/dvY+gl6HB5vRVVk6SEJFY/EpUIEzlpW+qFxvL1 6VFFiBv7G2JdHMZs/8xBYZm9YzaSgcsZobouuYIA4wRKopgoW2tqi62eQTCOoAhaLIT0 TK2G/9I2Juvg1hOJVBo51rMWp21v+CNQuh5UMCEp6vNrXNmhMcDRWV0pR3qyedE7yxgr oXIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qp8PGJSLWU/dwswnH2/0kSDHsb+wln5XeqPaVW1B5Z8=; b=j+pSvGOoWihU6Wwi8KQ2/5OlAJsdhzVNBzzz33mk8UQi04pK21Eiyu3F6tsH5fsa3x E4Gs6ZUIFH+oLWGaPNAJW+r1uGVDx2hTY5yPiOClYce7OQreh/sWO1OvWfj7G23d+WPH +zfC8BndrNCyc0CO6JCewjcZhgE5kISTjJidbRgP/ImUrf1M8aAuWri6llJVg1IrexQG KQIH3nHl9FDPc7Bg446B9Pg95Tx4sRaSUZzkJo/oXeV9A7Wnbn0MQw0GWuPEdMhZ2shm 5nLcRwjK96ajXOaPBr5ElwzmXMstbs6MwehY3ksFPuRavFDfB3aA1KbckTHC4zgIbaZZ k0lA== X-Gm-Message-State: AOAM53070hk2cRSrQIaH42cwlpRNG9mpMMDWKzlkMxdNmsCNQEm3Wgab EYK3WH89Rq3MzcNB+gpLfTu9NQvvS18= X-Google-Smtp-Source: ABdhPJxhvHk5cUvHX6rAbQVwgg8ik+gRYQYw+Z++uVUyjX085PL81mc1MQ6kNeatmpvgR9yE7EELWw== X-Received: by 2002:a17:90a:3841:: with SMTP id l1mr5029772pjf.3.1607929290263; Sun, 13 Dec 2020 23:01:30 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.228.148]) by smtp.gmail.com with ESMTPSA id 84sm19570018pfy.9.2020.12.13.23.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Dec 2020 23:01:29 -0800 (PST) From: Nicholas Piggin To: linux-kernel@vger.kernel.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Anton Blanchard , Andy Lutomirski Subject: [PATCH v2 4/5] powerpc: use lazy mm refcount helper functions Date: Mon, 14 Dec 2020 16:53:11 +1000 Message-Id: <20201214065312.270062-5-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201214065312.270062-1-npiggin@gmail.com> References: <20201214065312.270062-1-npiggin@gmail.com> MIME-Version: 1.0 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: Use _lazy_tlb functions for lazy mm refcounting in powerpc, to prepare to move to MMU_LAZY_TLB_SHOOTDOWN. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index 8c2857cbd960..93c0eaa6f4bf 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1395,7 +1395,7 @@ void start_secondary(void *unused) { unsigned int cpu = raw_smp_processor_id(); - mmgrab(&init_mm); + mmgrab_lazy_tlb(&init_mm); current->active_mm = &init_mm; smp_store_cpu_info(cpu); From patchwork Mon Dec 14 06:53:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11971451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2CF8C4361B for ; Mon, 14 Dec 2020 07:01:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4973B2078E for ; Mon, 14 Dec 2020 07:01:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4973B2078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D95A36B006C; Mon, 14 Dec 2020 02:01:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6B406B006E; Mon, 14 Dec 2020 02:01:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA71D6B0070; Mon, 14 Dec 2020 02:01:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id B5E966B006C for ; Mon, 14 Dec 2020 02:01:35 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7A94E181AEF3E for ; Mon, 14 Dec 2020 07:01:35 +0000 (UTC) X-FDA: 77590992150.18.whip66_2f14d6027418 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 51A61100ED0E0 for ; Mon, 14 Dec 2020 07:01:35 +0000 (UTC) X-HE-Tag: whip66_2f14d6027418 X-Filterd-Recvd-Size: 3900 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Dec 2020 07:01:34 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id p18so248578pgm.11 for ; Sun, 13 Dec 2020 23:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cxv1/xcoFyc0+rLkO7iNlzfTmTCUobsv0mf1a1fJaKs=; b=EBV8ywP4FdjYHK6Zs3pDMM/umySWWxUPltYnJrMBAcmSNSrWDQ9XMhWHy0oK/dZhkt mLuWcdPYgZ1T+rntAUck+SBWkw1wKlUH94Qr46nl4/BWhJw7PzgNFCdnq92WNA9BhoWB s8B9bP0O7v5R2B1SM/hMsaO1bfvOw7EJZu4ZBQi6Io0XQvfLxxp/ScAF6c5nl5Z4gxOY EqAy2QuVQUTiezdjMTmBwRk86RieavdiE+zX/OVFC/wJy1fiIcpfP12XwS8WErhncquo WlvMsM6ce4p/hs3r4DiLYkhtSooj48Kx8Zo4YtnHMIXxP3UmAA3IOmqOGzrTgI7cEb2+ dYQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cxv1/xcoFyc0+rLkO7iNlzfTmTCUobsv0mf1a1fJaKs=; b=NDOVYAhaZDrMfP/i8/XCK3sapesMwDWvAli6lv2UdxJUJeNobGS2kfnOvLqNVGtc6L IVPpLAo4rG3qCTTBxiVA20gUCkq9Pe8Pzuz+uQjtQaQJmW0wXJ73Cw8Fzqqlx7X9zVto rNCPfsSjhgNCwc/C3ssnuSN33D9ea16qn6lpQkNJEHeYc7gq84UGTLc+AwjxY6VbRMiL gtFjZW/N9yuiQShHnhZ59C2RFLYvqR4j9G6wFMT1CiGEI9kBsw0LpYTmTuXiJOtMCQPZ h/ZbuyHv4Nuzdi/0srZqbRkMpY1d3vKpjwAVnwutT30KJ74pcbqJpIAl4q0nnDbvdX9V mh4g== X-Gm-Message-State: AOAM5309x3J2R2x5o8TEJYPxfFwO9cT9+dVzUd1b+G0OKsSRoLGlnIVi 6X07DyVASQVA7Ib/1JWw0hg= X-Google-Smtp-Source: ABdhPJx5AmILXSD1xPGNVdPYIqA2jTn8bVniddzn968H7tbSxzitU/Hs0byrii/p6xSaJmriLmU4jw== X-Received: by 2002:a63:5418:: with SMTP id i24mr22887288pgb.165.1607929293976; Sun, 13 Dec 2020 23:01:33 -0800 (PST) Received: from bobo.ozlabs.ibm.com ([220.240.228.148]) by smtp.gmail.com with ESMTPSA id 84sm19570018pfy.9.2020.12.13.23.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Dec 2020 23:01:33 -0800 (PST) From: Nicholas Piggin To: linux-kernel@vger.kernel.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, Anton Blanchard , Andy Lutomirski Subject: [PATCH v2 5/5] powerpc/64s: enable MMU_LAZY_TLB_SHOOTDOWN Date: Mon, 14 Dec 2020 16:53:12 +1000 Message-Id: <20201214065312.270062-6-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201214065312.270062-1-npiggin@gmail.com> References: <20201214065312.270062-1-npiggin@gmail.com> MIME-Version: 1.0 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 a 16-socket 192-core POWER8 system, a context switching benchmark with as many software threads as CPUs (so each switch will go in and out of idle), upstream can achieve a rate of about 1 million context switches per second. After this patch it goes up to 118 million. Signed-off-by: Nicholas Piggin --- arch/powerpc/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 5181872f9452..356138bdb5bb 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -232,6 +232,7 @@ config PPC select HAVE_PERF_USER_STACK_DUMP select MMU_GATHER_RCU_TABLE_FREE select MMU_GATHER_PAGE_SIZE + select MMU_LAZY_TLB_SHOOTDOWN if PPC_BOOK3S_64 select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if PPC_BOOK3S_64 && CPU_LITTLE_ENDIAN select HAVE_SYSCALL_TRACEPOINTS