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 X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 1CE5AC433F5 for ; Wed, 22 Sep 2021 11:37:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4C8CE60EE7 for ; Wed, 22 Sep 2021 11:37:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4C8CE60EE7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id CFA3E6B006C; Wed, 22 Sep 2021 07:37:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA91D6B0072; Wed, 22 Sep 2021 07:37:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B98356B0073; Wed, 22 Sep 2021 07:37:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id AACDE6B006C for ; Wed, 22 Sep 2021 07:37:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5A068181C0A46 for ; Wed, 22 Sep 2021 11:37:39 +0000 (UTC) X-FDA: 78615009438.08.429CEC7 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf02.hostedemail.com (Postfix) with ESMTP id 02F357001C83 for ; Wed, 22 Sep 2021 11:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=RwsCAE+OHhIYLCRUvjot7FXo3qXO/fM/QdTY3eoicBE=; b=pJ542YUkBGcydIoTtqmd5NyNP/ EusNxpYUYPclLz3WBCyHkVIrAxRjj1ZhyhZvgmcV1vVOGVLvBFb1sJ2nnPz9osrFFvmhH4nXGTSDc FJnSoeea20CodQVBmXGVBBmSFRcQVAmKEa0xkNzcxAuLbRmG4T4z0Vh/nXTwz6zlFnivqQaOvU3eR VY2yAhQhn96XWL+MwfqI1pbGVR9zb4VVQJ27oAQOJlwika0fNmTR2UfEnwxxueebX0eQMqnyH12qU cmtcjC/yYZ3zGgQHmlULgX8mOsHJ86oEvGNTo5xZsK/tBfoAVrPQ6LRWAJist4zXyNaPZCRDgJBvI h0722hNQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mT0ZF-004ynh-61; Wed, 22 Sep 2021 11:37:37 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id C9D879816EA; Wed, 22 Sep 2021 13:37:36 +0200 (CEST) Date: Wed, 22 Sep 2021 13:37:36 +0200 From: Peter Zijlstra To: nsaenzju@redhat.com Cc: akpm@linux-foundation.org, frederic@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, cl@linux.com, 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 Subject: Re: [PATCH 2/6] mm/swap: Introduce alternative per-cpu LRU cache locking Message-ID: <20210922113736.GP4323@worktop.programming.kicks-ass.net> References: <20210921161323.607817-1-nsaenzju@redhat.com> <20210921161323.607817-3-nsaenzju@redhat.com> <20210921220358.GN4323@worktop.programming.kicks-ass.net> <0ec733daf2daaf8a6f5b1fbf56676b9892d5bf73.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0ec733daf2daaf8a6f5b1fbf56676b9892d5bf73.camel@redhat.com> X-Stat-Signature: bzz5kctcukjoktuc3dzoj1ndi6h9fexd Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=pJ542YUk; dmarc=none; spf=none (imf02.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 02F357001C83 X-HE-Tag: 1632310658-695736 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000079, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Sep 22, 2021 at 10:47:07AM +0200, nsaenzju@redhat.com wrote: > On Wed, 2021-09-22 at 00:03 +0200, Peter Zijlstra wrote: > > On Tue, Sep 21, 2021 at 06:13:20PM +0200, Nicolas Saenz Julienne wrote: > > > +static inline void lru_cache_lock(struct lru_cache_locks *locks) > > > +{ > > > + if (static_branch_unlikely(&remote_pcpu_cache_access)) { > > > + /* Avoid migration between this_cpu_ptr() and spin_lock() */ > > > + migrate_disable(); > > > + spin_lock(this_cpu_ptr(&locks->spin)); > > > + } else { > > > + local_lock(&locks->local); > > > + } > > > +} > > > > > +static inline void lru_cache_unlock(struct lru_cache_locks *locks) > > > +{ > > > + if (static_branch_unlikely(&remote_pcpu_cache_access)) { > > > + spin_unlock(this_cpu_ptr(&locks->spin)); > > > + migrate_enable(); > > > + } else { > > > + local_unlock(&locks->local); > > > + } > > > +} > > > > *why* use migrate_disable(), that's horrible! > > I was trying to be mindful of RT. They don't appreciate people taking spinlocks > just after having disabled preemption. > > I think getting local_lock(&locks->local) is my only option then. But it adds > an extra redundant spinlock in the RT+NOHZ_FULL case. That doesn't make it less horrible. The fundamental problem you seem to have is that you have to do the this_cpu thing multiple times. If instead you make sure to only ever do the per-cpu deref *once* and then make sure you use the same lru_rotate.pvec as you used lru_rotate.locks, it all works out much nicer. Then you can write things like: struct lru_rotate *lr = raw_cpu_ptr(&lru_rotate); frob_lock(&lr->locks); frob_pvec(&lr->pvec); frob_unlock(&lr->locks); and it all no longer matters if you got this or that CPU's instance. After all, you no longer rely on per-cpu ness for serialization but the lock.