Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp111927ybk; Tue, 19 May 2020 17:01:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzACkdzPjFsUE13VH1CdBwS7PIQmibSYWJGMx8jC9uNe8ITbhgIaJe01v7N/2GSajZDoQUY X-Received: by 2002:a17:906:eda3:: with SMTP id sa3mr1639705ejb.253.1589932891689; Tue, 19 May 2020 17:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589932891; cv=none; d=google.com; s=arc-20160816; b=qFw6BZHFUAAypefM9PcO4XlGQX0JU8sIbVk7QvPqZ/WQWz9roBFHANGIcSp7xzBsMZ HpdKlZtaQbwqhe2XtwrkTkgv1vrC0ytpV92UqW48D6Dq0qr7+EzGYNitE61isEM7eOXl 43yjn3CqVOzwm7exnOyzmq18EnReCjAsMPjamwUmJxuSuX4kojiU5fVWEKFT/N7gzuuk hZGfedw9GcH9TwLFjopdEpLfSYYAyL4U7NeVQAU9r+8n8tyYtfBOKiGPuIxen6absr52 bBw8YQJuezmP5aL8LUbUR87otMT0Ul21Dj2e7CcjkKguAYMf46LLllJ6ZeFynLdksIYj sgoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=LhnlNfFImBO5QA70LAfsmautIX2OrNguDsLImZPkk1M=; b=OiREBW8SPak3mWI0X/xreEWF1jZICMLW+YJ5RlxX+9Kh8FIqJB6Gs9dURNaj9zmwQE j37cJDZ7WylRVW//l5U1bPpIWm+TGFUhiwfSueUMoDNlinA4zXn8TFa2a1/jFrsWF5rY ihyqFNYDgtJjS0fw8dFQTUGHJiMHosBn2fab9ZNSN9xQ/JMwJi9NgcJUeTThMAe5I9uN 6dkgZ2LDV/OeldH6ojQ8hMr4ZA5rw8RBuHMSqvvIq/SzLJXRD+ZaAIadHpqQ38Sv47bu mqTL/K9iA2uiWUk5mMvevysD7rO5sDR4D+PAYAEr9iYtsa8Cdd4SKxARuAS3aQ/3tsr9 4NXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2I06lgu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si784072ejy.575.2020.05.19.17.01.08; Tue, 19 May 2020 17:01:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2I06lgu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728188AbgESX6j (ORCPT + 99 others); Tue, 19 May 2020 19:58:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:51716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726344AbgESX6i (ORCPT ); Tue, 19 May 2020 19:58:38 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E6ACE20709; Tue, 19 May 2020 23:58:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589932718; bh=x77OGScDIde4TwlFEa+gPiHNd4pPSqVAZctmdtdQf+M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2I06lgu7e98/FtCn7fN7kQs4NOg0wiuoV2d61tLQ/OONM8ec7wot7wUuiAhhUEGjs u5CRjr33qLyVuX9TpXqy+2o5B5I3v8MQPgMxVBgKUvgsIYuxU1KdZbS+IkwVw3E1+Q hAIT0Ch2tMfGRaBUCiPtH97cFJs3gYfC3VEJ0uKU= Date: Tue, 19 May 2020 16:58:37 -0700 From: Andrew Morton To: Sebastian Andrzej Siewior Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Steven Rostedt , Will Deacon , Thomas Gleixner , "Paul E . McKenney" , Linus Torvalds , linux-mm@kvack.org Subject: Re: [PATCH 4/8] mm/swap: Use local_lock for protection Message-Id: <20200519165837.883035d3228c582b9bff1d77@linux-foundation.org> In-Reply-To: <20200519201912.1564477-5-bigeasy@linutronix.de> References: <20200519201912.1564477-1-bigeasy@linutronix.de> <20200519201912.1564477-5-bigeasy@linutronix.de> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 19 May 2020 22:19:08 +0200 Sebastian Andrzej Siewior wrote: > From: Ingo Molnar > > The various struct pagevec per CPU variables are protected by disabling > either preemption or interrupts across the critical sections. Inside > these sections spinlocks have to be acquired. > > These spinlocks are regular spinlock_t types which are converted to > "sleeping" spinlocks on PREEMPT_RT enabled kernels. Obviously sleeping > locks cannot be acquired in preemption or interrupt disabled sections. > > local locks provide a trivial way to substitute preempt and interrupt > disable instances. On a non PREEMPT_RT enabled kernel local_lock() maps > to preempt_disable() and local_lock_irq() to local_irq_disable(). > > Add swapvec_lock to protect the per-CPU lru_add_pvec and > lru_lazyfree_pvecs variables and rotate_lock to protect the per-CPU > lru_rotate_pvecs variable > > Change the relevant call sites to acquire these locks instead of using > preempt_disable() / get_cpu() / get_cpu_var() and local_irq_disable() / > local_irq_save(). > > There is neither a functional change nor a change in the generated > binary code for non PREEMPT_RT enabled non-debug kernels. > > When lockdep is enabled local locks have lockdep maps embedded. These > allow lockdep to validate the protections, i.e. inappropriate usage of a > preemption only protected sections would result in a lockdep warning > while the same problem would not be noticed with a plain > preempt_disable() based protection. > > local locks also improve readability as they provide a named scope for > the protections while preempt/interrupt disable are opaque scopeless. > > Finally local locks allow PREEMPT_RT to substitute them with real > locking primitives to ensure the correctness of operation in a fully > preemptible kernel. > No functional change. > > ... > > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include Could we please make these local_lock.h and local_lock_internal.h? Making the filenames different from everything else is just irritating! > + local_lock(swapvec_lock); It's quite peculiar that these operations appear to be pass-by-value. All other locking operations are pass-by-reference - spin_lock(&lock), not spin_lock(lock). This is what the eye expects to see and it's simply more logical - calling code shouldn't have to "know" that the locking operations are implemented as cpp macros. And we'd be in a mess if someone tried to convert these to real C functions. Which prompts the question: why were all these operations implemented in the processor anyway? afaict they could have been written in C.