From: Thomas Gleixner <tglx@linutronix.de>
To: Mel Gorman <mgorman@techsingularity.net>,
Peter Zijlstra <peterz@infradead.org>
Cc: Linux-MM <linux-mm@kvack.org>,
Linux-RT-Users <linux-rt-users@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Chuck Lever <chuck.lever@oracle.com>,
Jesper Dangaard Brouer <brouer@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Ingo Molnar <mingo@kernel.org>, Michal Hocko <mhocko@kernel.org>,
Oscar Salvador <osalvador@suse.de>
Subject: Re: [PATCH 02/11] mm/page_alloc: Convert per-cpu list protection to local_lock
Date: Mon, 12 Apr 2021 23:47:00 +0200 [thread overview]
Message-ID: <87lf9nyy3v.ffs@nanos.tec.linutronix.de> (raw)
In-Reply-To: <20210412115612.GX3697@techsingularity.net>
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
next prev parent reply other threads:[~2021-04-12 21:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-07 20:24 [PATCH 0/11 v2] Use local_lock for pcp protection and reduce stat overhead Mel Gorman
2021-04-07 20:24 ` [PATCH 01/11] mm/page_alloc: Split per cpu page lists and zone stats Mel Gorman
2021-04-12 17:43 ` Vlastimil Babka
2021-04-13 13:27 ` Mel Gorman
2021-04-07 20:24 ` [PATCH 02/11] mm/page_alloc: Convert per-cpu list protection to local_lock Mel Gorman
2021-04-08 10:52 ` Peter Zijlstra
2021-04-08 17:42 ` Mel Gorman
2021-04-09 6:39 ` Peter Zijlstra
2021-04-09 7:59 ` Mel Gorman
2021-04-09 8:24 ` Peter Zijlstra
2021-04-09 13:32 ` Mel Gorman
2021-04-09 18:55 ` Peter Zijlstra
2021-04-12 11:56 ` Mel Gorman
2021-04-12 21:47 ` Thomas Gleixner [this message]
2021-04-13 16:52 ` Mel Gorman
2021-04-07 20:24 ` [PATCH 03/11] mm/memory_hotplug: Make unpopulated zones PCP structures unreachable during hot remove Mel Gorman
2021-04-07 20:24 ` [PATCH 04/11] mm/vmstat: Convert NUMA statistics to basic NUMA counters Mel Gorman
2021-04-14 12:56 ` Vlastimil Babka
2021-04-14 15:18 ` Mel Gorman
2021-04-14 15:56 ` Vlastimil Babka
2021-04-15 10:06 ` Mel Gorman
2021-04-07 20:24 ` [PATCH 05/11] mm/vmstat: Inline NUMA event counter updates Mel Gorman
2021-04-07 20:24 ` [PATCH 06/11] mm/page_alloc: Batch the accounting updates in the bulk allocator Mel Gorman
2021-04-07 20:24 ` [PATCH 07/11] mm/page_alloc: Reduce duration that IRQs are disabled for VM counters Mel Gorman
2021-04-07 20:24 ` [PATCH 08/11] mm/page_alloc: Remove duplicate checks if migratetype should be isolated Mel Gorman
2021-04-07 20:24 ` [PATCH 09/11] mm/page_alloc: Explicitly acquire the zone lock in __free_pages_ok Mel Gorman
2021-04-07 20:24 ` [PATCH 10/11] mm/page_alloc: Avoid conflating IRQs disabled with zone->lock Mel Gorman
2021-04-07 20:24 ` [PATCH 11/11] mm/page_alloc: Update PGFREE outside the zone lock in __free_pages_ok Mel Gorman
2021-04-08 10:56 ` [PATCH 0/11 v2] Use local_lock for pcp protection and reduce stat overhead Peter Zijlstra
2021-04-08 17:48 ` Mel Gorman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lf9nyy3v.ffs@nanos.tec.linutronix.de \
--to=tglx@linutronix.de \
--cc=brouer@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=mingo@kernel.org \
--cc=osalvador@suse.de \
--cc=peterz@infradead.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox