linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: bpf <bpf@vger.kernel.org>, Andrii Nakryiko <andrii@kernel.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Steven Rostedt <rostedt@goodmis.org>,
	Hou Tao <houtao1@huawei.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Michal Hocko <mhocko@suse.com>,
	Matthew Wilcox <willy@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jann Horn <jannh@google.com>, Tejun Heo <tj@kernel.org>,
	linux-mm <linux-mm@kvack.org>, Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v6 3/6] locking/local_lock: Introduce local_trylock_t and local_trylock_irqsave()
Date: Wed, 29 Jan 2025 09:17:26 +0100	[thread overview]
Message-ID: <20250129081726.vGHs_2kD@linutronix.de> (raw)
In-Reply-To: <CAADnVQ+6YD=jzx08ynUDo=ptFbD62o17ozymFfycF5WbPb9GbA@mail.gmail.com>

PeterZ, may I summon you.

On 2025-01-28 10:50:33 [-0800], Alexei Starovoitov wrote:
> On Tue, Jan 28, 2025 at 9:21 AM Sebastian Andrzej Siewior
> <bigeasy@linutronix.de> wrote:
> >
> > On 2025-01-23 19:56:52 [-0800], Alexei Starovoitov wrote:
> > > Usage:
> > >
> > > local_lock_t lock;                     // sizeof(lock) == 0 in !RT
> > > local_lock_irqsave(&lock, ...);        // irqsave as before
> > > if (local_trylock_irqsave(&lock, ...)) // compilation error
> > >
> > > local_trylock_t lock;                  // sizeof(lock) == 4 in !RT
> > > local_lock_irqsave(&lock, ...);        // irqsave and active = 1
> > > if (local_trylock_irqsave(&lock, ...)) // if (!active) irqsave
> >
> > so I've been looking at this for a while and I don't like the part where
> > the type is hidden away. It is then casted back. So I tried something
> > with _Generics but then the existing guard implementation complained.
> > Then I asked myself why do we want to hide much of the implementation
> > and not make it obvious.
> 
> Well, the idea of hiding extra field with _Generic is to avoid
> the churn:
> 
> git grep -E 'local_.*lock_irq'|wc -l
> 42

This could be also hidden with a macro defining the general body and
having a place holder for "lock primitive".

> I think the api is clean enough and _Generic part is not exposed
> to users.
> Misuse or accidental usage is not possible either.
> See the point:
> if (local_trylock_irqsave(&lock, ...)) // compilation error
> 
> So imo it's a better tradeoff.
> 
> > is this anywhere near possible to accept?
> 
> Other than churn it's fine.
> I can go with it if you insist,
> but casting and _Generic() I think is cleaner.
> Certainly a bit unusual pattern.
> Could you sleep on it?

The cast there is somehow… We could have BUILD_BUG_ON() to ensure a
stable the layout of the structs… However all this is not my call.

PeterZ, do you have any preferences or an outline what you would like to
see here?

> I can do s/local_trylock_t/localtry_lock_t/.
> That part is trivial.

Sebastian


  reply	other threads:[~2025-01-29  8:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-24  3:56 [PATCH bpf-next v6 0/6] bpf, mm: Introduce try_alloc_pages() Alexei Starovoitov
2025-01-24  3:56 ` [PATCH bpf-next v6 1/6] mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation Alexei Starovoitov
2025-01-28 18:09   ` Shakeel Butt
2025-01-24  3:56 ` [PATCH bpf-next v6 2/6] mm, bpf: Introduce free_pages_nolock() Alexei Starovoitov
2025-01-28 18:18   ` Shakeel Butt
2025-01-24  3:56 ` [PATCH bpf-next v6 3/6] locking/local_lock: Introduce local_trylock_t and local_trylock_irqsave() Alexei Starovoitov
2025-01-28 17:21   ` Sebastian Andrzej Siewior
2025-01-28 18:50     ` Alexei Starovoitov
2025-01-29  8:17       ` Sebastian Andrzej Siewior [this message]
2025-01-30 20:51         ` Alexei Starovoitov
2025-02-06 11:13         ` Sebastian Andrzej Siewior
2025-01-24  3:56 ` [PATCH bpf-next v6 4/6] memcg: Use trylock to access memcg stock_lock Alexei Starovoitov
2025-01-24  3:56 ` [PATCH bpf-next v6 5/6] mm, bpf: Use memcg in try_alloc_pages() Alexei Starovoitov
2025-01-24  3:56 ` [PATCH bpf-next v6 6/6] bpf: Use try_alloc_pages() to allocate pages for bpf needs Alexei Starovoitov
2025-01-24 14:16 ` [PATCH bpf-next v6 0/6] bpf, mm: Introduce try_alloc_pages() Matthew Wilcox
2025-01-24 14:19   ` Vlastimil Babka
2025-01-24 16:19     ` Alexei Starovoitov
2025-01-24 16:28       ` Vlastimil Babka
2025-01-24 16:46         ` Alexei Starovoitov
2025-01-24 16:28       ` Matthew Wilcox

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=20250129081726.vGHs_2kD@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=houtao1@huawei.com \
    --cc=jannh@google.com \
    --cc=kernel-team@fb.com \
    --cc=linux-mm@kvack.org \
    --cc=memxor@gmail.com \
    --cc=mhocko@suse.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=shakeel.butt@linux.dev \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=vbabka@suse.cz \
    --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