From patchwork Tue Sep 21 16:13:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 12508157 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 0CB20C4332F for ; Tue, 21 Sep 2021 16:13:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ACD5B610A1 for ; Tue, 21 Sep 2021 16:13:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org ACD5B610A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 4D2236B007B; Tue, 21 Sep 2021 12:13:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 482EE6B007D; Tue, 21 Sep 2021 12:13:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D4DE940007; Tue, 21 Sep 2021 12:13:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0100.hostedemail.com [216.40.44.100]) by kanga.kvack.org (Postfix) with ESMTP id 1F1C36B007B for ; Tue, 21 Sep 2021 12:13:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D679B1813CB8D for ; Tue, 21 Sep 2021 16:13:42 +0000 (UTC) X-FDA: 78612076284.27.AAB2376 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 7F301801A8A7 for ; Tue, 21 Sep 2021 16:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632240822; h=from:from: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=Skz+wSCIMyvocC+cWmr1kqnk80+x9gFo8RgnyvxY9jI=; b=gAMB2NjgJr+vAF4dvhZslkQxSUgOsgAc4E+sxpR0VcJLbOOmkydb+hTLJX4BcO+T+EoMhQ tyvx5/GP/bPTDZwR4rG4eu9w1eiNYY4/FrQqS3BOTvSt/5TGGMYzJAYQ3q6se7tM0vJesM iGP0gPCNB9TkbuMpDVL3sXFKQOCPZrc= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-5x2JoL9ZNQKq_AHU7iDtLw-1; Tue, 21 Sep 2021 12:13:38 -0400 X-MC-Unique: 5x2JoL9ZNQKq_AHU7iDtLw-1 Received: by mail-wr1-f71.google.com with SMTP id c15-20020a5d4ccf000000b0015dff622f39so9243822wrt.21 for ; Tue, 21 Sep 2021 09:13:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Skz+wSCIMyvocC+cWmr1kqnk80+x9gFo8RgnyvxY9jI=; b=GbSueWdZC7XgHaRP5rZPCVvupLTomb1ANKifHgcKeJ24mF1ZYbEI39aC4DvKbKN0OW FtklEON/Xi6u0jWMg1JZutAxrtMBgBWlYzf3ZY68d9sj2v0WaSrFWJisFw2IJIrO54w+ uRxX2Rm0QRkrED+dQK6P0zsEtZ99DoBymSVcspedAqTDcYjkRUA1cnMM5B1h6Mc/UOpn ez8FQVNwA+G1vUSXvro95SmMnBqyJAVmf73oMQLtwspJeBd1UlsqYqVSfZfmUqk3kKmg uwtFpgy8u2sFoXmMVM9qqve2uHKfQ4K10lFAFQ7+bSfeCjFmnCd4kmjQRUTuJJzcVKud iXyg== X-Gm-Message-State: AOAM533NNGiPloPWlgQuigmpF6yNsJtDkJm5ZLvDvP3xuTGBBMqQfKPx G/LVr24MDRKZ69IN5aVlbdyNcqbWMooRm6rQds18MO0vdqas7Q8R5peKWaquaVZY+Ltgsl2+cuU +5ozoxvISex0= X-Received: by 2002:a05:6000:c3:: with SMTP id q3mr35713557wrx.361.1632240817400; Tue, 21 Sep 2021 09:13:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwc8lfAIXvvAGBd2lf3kHl9jl9Ma+SH7iopQjrQOmNgpGD7Dcwtktf6tIufdAsdVPxyyoBuiQ== X-Received: by 2002:a05:6000:c3:: with SMTP id q3mr35713524wrx.361.1632240817263; Tue, 21 Sep 2021 09:13:37 -0700 (PDT) Received: from vian.redhat.com ([2a0c:5a80:1d03:b900:c3d1:5974:ce92:3123]) by smtp.gmail.com with ESMTPSA id t1sm19786477wrz.39.2021.09.21.09.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 09:13:37 -0700 (PDT) From: Nicolas Saenz Julienne To: akpm@linux-foundation.org, frederic@kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, cl@linux.com, peterz@infradead.org, juri.lelli@redhat.com, mingo@redhat.com, mtosatti@redhat.com, nilal@redhat.com, mgorman@suse.de, ppandit@redhat.com, williams@redhat.com, bigeasy@linutronix.de, anna-maria@linutronix.de, linux-rt-users@vger.kernel.org, Nicolas Saenz Julienne Subject: [PATCH 3/6] mm/swap: Allow remote LRU cache draining Date: Tue, 21 Sep 2021 18:13:21 +0200 Message-Id: <20210921161323.607817-4-nsaenzju@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210921161323.607817-1-nsaenzju@redhat.com> References: <20210921161323.607817-1-nsaenzju@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gAMB2Njg; spf=none (imf06.hostedemail.com: domain of nsaenzju@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=nsaenzju@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7F301801A8A7 X-Stat-Signature: eykpykhf7bbt97rtmewoi5dgdnd45xxq X-HE-Tag: 1632240822-692683 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Some setups, notably NOHZ_FULL CPUs, are too busy to handle the per-cpu drain work queued by __lru_add_drain_all(). So introduce new a mechanism to remotely drain the per-cpu lists. It is made possible by using a more constraining locking scheme, which is disabled by default and can be enabled through the 'remote_pcpu_cache_access' static key. Regular users shouldn't see any functional or performance change. Upcoming patches will make use of the key. Based on previous work by Thomas Gleixner, Anna-Maria Gleixner, and Sebastian Andrzej Siewior[1]. [1] https://patchwork.kernel.org/project/linux-mm/cover/20190424111208.24459-1-bigeasy@linutronix.de/ Signed-off-by: Nicolas Saenz Julienne --- mm/swap.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index bcf73bd563a6..59e96a2520d5 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -915,19 +915,29 @@ inline void __lru_add_drain_all(bool force_all_cpus) WRITE_ONCE(lru_drain_gen, lru_drain_gen + 1); smp_mb(); - cpumask_clear(&has_work); - for_each_online_cpu(cpu) { - struct work_struct *work = &per_cpu(lru_add_drain_work, cpu); - - if (force_all_cpus || lru_cpu_needs_drain(cpu)) { - INIT_WORK(work, lru_add_drain_per_cpu); - queue_work_on(cpu, mm_percpu_wq, work); - __cpumask_set_cpu(cpu, &has_work); + if (static_branch_unlikely(&remote_pcpu_cache_access)) { + for_each_online_cpu(cpu) { + if (force_all_cpus || lru_cpu_needs_drain(cpu)) { + lru_cache_lock_cpu(&lru_pvecs.locks, cpu); + lru_add_drain_cpu(cpu); + lru_cache_unlock_cpu(&lru_pvecs.locks, cpu); + } + } + } else { + cpumask_clear(&has_work); + for_each_online_cpu(cpu) { + struct work_struct *work = &per_cpu(lru_add_drain_work, cpu); + + if (force_all_cpus || lru_cpu_needs_drain(cpu)) { + INIT_WORK(work, lru_add_drain_per_cpu); + queue_work_on(cpu, mm_percpu_wq, work); + __cpumask_set_cpu(cpu, &has_work); + } } - } - for_each_cpu(cpu, &has_work) - flush_work(&per_cpu(lru_add_drain_work, cpu)); + for_each_cpu(cpu, &has_work) + flush_work(&per_cpu(lru_add_drain_work, cpu)); + } done: mutex_unlock(&lock);