Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2392443pxb; Tue, 13 Apr 2021 00:18:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdVLgJSr7ZJBektQVGSOfk2kuQph3YdHBsjRTt46qOntq6hAUe+ZBfwBdkthE+J0tn+yM7 X-Received: by 2002:a17:906:c1c9:: with SMTP id bw9mr10270211ejb.239.1618298302048; Tue, 13 Apr 2021 00:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618298302; cv=none; d=google.com; s=arc-20160816; b=kypSiUNJY74bVCBNN0sG7x0Iw5zu22iEh+x9cR8r1MzD9k7uEfzXEl8wimAIGJUcJT Qw9EPxzpZQ0seOwkZ37RUtyXXmDxyHOCMWuMKJm9W9X90VB0PA1HNkOx4snjLygunPeT vQqq7kK2z58qTddx2F/SddF3hI5bzD9Z2PUtG+9Jb5ja2OSlXbJ9ClbRgS3MLct801Qf mtTuWQMbET5GIMyInJRXAD8Frwj18+sPZyDjLcwRlerqCB9WkuDnkHNuYsiyqE5Mhc97 tAf4QKRzI8zRCMnXdfpaEpq1Un3b0OsnKcgorFASFMxIMGr0guNNO4AA/+1G6kh0Zov1 1DHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=O3ghyb2W8BLIZ05yGXW2dF3hyTFm2kpNfuX26M7+CeU=; b=WARzmlzrVet8QHWjMXyoesawDLwS2dU7Vf/PJwxWmICF3bQ/0mBLj6I90rbxqusFEx jXEujzAGjSHVMEypNKaheumRGdozjVwasRmQrk+JaqkrKkyImOjU9ZvznTzNTsZU55F2 GCsI2Yy+k4l8evsf+rSptslKO+oUfKsA8fPgKSX9kIEo6XOJ4yHB1DBtcUV2M9UZtdjA v8YJIpLW/BD9h6rHlwdhZkb8rho2G8qDWVpmHYo37nVEFtAoOOvl6ydMqkpuogR9Ug4S Pxdy9OZqyDnPbnpOxZ+3XlKlqE/yrmSb98z1ik/1VucSdVzVy/EXEdfRqHhBXuClEzKT ODfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="0JND/f36"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rcxiLqbV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk1si9597245edb.396.2021.04.13.00.17.59; Tue, 13 Apr 2021 00:18:22 -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=@linutronix.de header.s=2020 header.b="0JND/f36"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rcxiLqbV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239427AbhDLVrV (ORCPT + 99 others); Mon, 12 Apr 2021 17:47:21 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:41804 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238172AbhDLVrU (ORCPT ); Mon, 12 Apr 2021 17:47:20 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1618264020; 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: in-reply-to:in-reply-to:references:references; bh=O3ghyb2W8BLIZ05yGXW2dF3hyTFm2kpNfuX26M7+CeU=; b=0JND/f36w2AlnIm7iCrU9za65squcC+wrt1Q3PvUa6fd/cgtTG6U+dk5ATJq2PwANl5VU0 nCRl1q4YyzBri2+HCWXlYHhS7Ow9z1OobM6ynvLMup6SS6i0Icg4I8/BFmE5uNBH/xY5eH l5GyYhl7/i2Mswr/70UimbZgyBB5qnlcoEFW1MFS1KSk39tlHH2ILhSM5bsjC7uxzr2X0p EMgE1XQprhYKLymJqLHI4JNLbBwvLqLDlV/LMDNjgg6YpcabDdnobIcgIxnq4M9Uj2BhpW e4aGx6QWPmGXSr6ICJr1+B3KJSvQlGF4kW+oo6AoCImjMSR9jcN6ewKfszb0Zw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1618264020; 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: in-reply-to:in-reply-to:references:references; bh=O3ghyb2W8BLIZ05yGXW2dF3hyTFm2kpNfuX26M7+CeU=; b=rcxiLqbVMct+y7fFhu/BCqI6vDfyqvCDbScwZAws9tJ0530I3iXq+ap64VCpHHWyCDnewO M0+6US2qb8rZYBCQ== To: Mel Gorman , Peter Zijlstra Cc: Linux-MM , Linux-RT-Users , LKML , Chuck Lever , Jesper Dangaard Brouer , Matthew Wilcox , Ingo Molnar , Michal Hocko , Oscar Salvador Subject: Re: [PATCH 02/11] mm/page_alloc: Convert per-cpu list protection to local_lock In-Reply-To: <20210412115612.GX3697@techsingularity.net> References: <20210407202423.16022-1-mgorman@techsingularity.net> <20210407202423.16022-3-mgorman@techsingularity.net> <20210408174244.GG3697@techsingularity.net> <20210409075939.GJ3697@techsingularity.net> <20210409133256.GN3697@techsingularity.net> <20210412115612.GX3697@techsingularity.net> Date: Mon, 12 Apr 2021 23:47:00 +0200 Message-ID: <87lf9nyy3v.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 12 2021 at 12:56, Mel Gorman wrote: > On Fri, Apr 09, 2021 at 08:55:39PM +0200, Peter Zijlstra wrote: > I'll update the changelog and comment accordingly. I'll decide later > whether to leave it or move the location of the lock at the end of the > series. If the patch is added, it'll either incur the double lookup (not > that expensive, might be optimised by the compiler) or come up with a > helper that takes the lock and returns the per-cpu structure. The double > lookup probably makes more sense initially because there are multiple > potential users of a helper that says "pin to CPU, lookup, lock and return > a per-cpu structure" for both IRQ-safe and IRQ-unsafe variants with the > associated expansion of the local_lock API. It might be better to introduce > such a helper with multiple users converted at the same time and there are > other local_lock users in preempt-rt that could do with upstreaming first. We had such helpers in RT a while ago but it turned into an helper explosion pretty fast. But that was one of the early versions of local locks which could not be embedded into a per CPU data structure due to raisins (my stupidity). But with the more thought out approach of today we can have (+/- the obligatory naming bikeshedding): --- a/include/linux/local_lock.h +++ b/include/linux/local_lock.h @@ -51,4 +51,35 @@ #define local_unlock_irqrestore(lock, flags) \ __local_unlock_irqrestore(lock, flags) +/** + * local_lock_get_cpu_ptr - Acquire a per CPU local lock and return + * a pointer to the per CPU data which + * contains the local lock. + * @pcp: Per CPU data structure + * @lock: The local lock member of @pcp + */ +#define local_lock_get_cpu_ptr(pcp, lock) \ + __local_lock_get_cpu_ptr(pcp, typeof(*(pcp)), lock) + +/** + * local_lock_irq_get_cpu_ptr - Acquire a per CPU local lock, disable + * interrupts and return a pointer to the + * per CPU data which contains the local lock. + * @pcp: Per CPU data structure + * @lock: The local lock member of @pcp + */ +#define local_lock_irq_get_cpu_ptr(pcp, lock) \ + __local_lock_irq_get_cpu_ptr(pcp, typeof(*(pcp)), lock) + +/** + * local_lock_irqsave_get_cpu_ptr - Acquire a per CPU local lock, save and + * disable interrupts and return a pointer to + * the CPU data which contains the local lock. + * @pcp: Per CPU data structure + * @lock: The local lock member of @pcp + * @flags: Storage for interrupt flags + */ +#define local_lock_irqsave_get_cpu_ptr(pcp, lock, flags) \ + __local_lock_irqsave_get_cpu_ptr(pcp, typeof(*(pcp)), lock, flags) + #endif --- a/include/linux/local_lock_internal.h +++ b/include/linux/local_lock_internal.h @@ -91,3 +91,33 @@ static inline void local_lock_release(lo local_lock_release(this_cpu_ptr(lock)); \ local_irq_restore(flags); \ } while (0) + +#define __local_lock_get_cpu_ptr(pcp, type, lock) \ + ({ \ + type *__pcp; \ + \ + preempt_disable(); \ + __pcp = this_cpu_ptr(pcp); \ + local_lock_acquire(&__pcp->lock); \ + __pcp; \ + }) + +#define __local_lock_irq_get_cpu_ptr(pcp, type, lock) \ + ({ \ + type *__pcp; \ + \ + local_irq_disable(); \ + __pcp = this_cpu_ptr(pcp); \ + local_lock_acquire(&__pcp->lock); \ + __pcp; \ + }) + +#define __local_lock_irqsave_get_cpu_ptr(pcp, type, lock, flags)\ + ({ \ + type *__pcp; \ + \ + local_irq_save(flags); \ + __pcp = this_cpu_ptr(pcp); \ + local_lock_acquire(&__pcp->lock); \ + __pcp; \ + }) and RT will then change that to: --- a/include/linux/local_lock_internal.h +++ b/include/linux/local_lock_internal.h @@ -96,7 +96,7 @@ static inline void local_lock_release(lo ({ \ type *__pcp; \ \ - preempt_disable(); \ + ll_preempt_disable(); \ __pcp = this_cpu_ptr(pcp); \ local_lock_acquire(&__pcp->lock); \ __pcp; \ @@ -106,7 +106,7 @@ static inline void local_lock_release(lo ({ \ type *__pcp; \ \ - local_irq_disable(); \ + ll_local_irq_disable(); \ __pcp = this_cpu_ptr(pcp); \ local_lock_acquire(&__pcp->lock); \ __pcp; \ @@ -116,7 +116,7 @@ static inline void local_lock_release(lo ({ \ type *__pcp; \ \ - local_irq_save(flags); \ + ll_local_irq_save(flags); \ __pcp = this_cpu_ptr(pcp); \ local_lock_acquire(&__pcp->lock); \ __pcp; \ where ll_xxx is defined as xxx for non-RT and on RT all of them get mapped to migrate_disable(). Thoughts? Thanks, tglx