[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJuCfpH_4EF6+-cUF9uNrfX7wONWHR8f13EQHN4AeVkALMBWfQ@mail.gmail.com>
Date: Mon, 13 Jan 2025 13:18:48 -0800
From: Suren Baghdasaryan <surenb@...gle.com>
To: Wei Yang <richard.weiyang@...il.com>
Cc: akpm@...ux-foundation.org, peterz@...radead.org, willy@...radead.org,
liam.howlett@...cle.com, lorenzo.stoakes@...cle.com,
david.laight.linux@...il.com, mhocko@...e.com, vbabka@...e.cz,
hannes@...xchg.org, mjguzik@...il.com, oliver.sang@...el.com,
mgorman@...hsingularity.net, david@...hat.com, peterx@...hat.com,
oleg@...hat.com, dave@...olabs.net, paulmck@...nel.org, brauner@...nel.org,
dhowells@...hat.com, hdanton@...a.com, hughd@...gle.com,
lokeshgidra@...gle.com, minchan@...gle.com, jannh@...gle.com,
shakeel.butt@...ux.dev, souravpanda@...gle.com, pasha.tatashin@...een.com,
klarasmodin@...il.com, corbet@....net, linux-doc@...r.kernel.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org, kernel-team@...roid.com
Subject: Re: [PATCH v9 11/17] mm: replace vm_lock and detached flag with a
reference count
On Mon, Jan 13, 2025 at 1:36 AM Wei Yang <richard.weiyang@...il.com> wrote:
>
> On Fri, Jan 10, 2025 at 08:25:58PM -0800, Suren Baghdasaryan wrote:
> [...]
> >
> >+static inline bool is_vma_writer_only(int refcnt)
> >+{
> >+ /*
> >+ * With a writer and no readers, refcnt is VMA_LOCK_OFFSET if the vma
> >+ * is detached and (VMA_LOCK_OFFSET + 1) if it is attached. Waiting on
> >+ * a detached vma happens only in vma_mark_detached() and is a rare
> >+ * case, therefore most of the time there will be no unnecessary wakeup.
> >+ */
> >+ return refcnt & VMA_LOCK_OFFSET && refcnt <= VMA_LOCK_OFFSET + 1;
>
> It looks equivalent to
>
> return (refcnt == VMA_LOCK_OFFSET) || (refcnt == VMA_LOCK_OFFSET + 1);
>
> And its generated code looks a little simpler.
Yeah, but I think the original version is a bit more descriptive,
checking that (1) there is a writer and (2) there are no readers.
>
> >+}
> >+
> >+static inline void vma_refcount_put(struct vm_area_struct *vma)
> >+{
> >+ /* Use a copy of vm_mm in case vma is freed after we drop vm_refcnt */
> >+ struct mm_struct *mm = vma->vm_mm;
> >+ int oldcnt;
> >+
> >+ rwsem_release(&vma->vmlock_dep_map, _RET_IP_);
> >+ if (!__refcount_dec_and_test(&vma->vm_refcnt, &oldcnt)) {
> >+
> >+ if (is_vma_writer_only(oldcnt - 1))
> >+ rcuwait_wake_up(&mm->vma_writer_wait);
> >+ }
> >+}
> >+
>
> --
> Wei Yang
> Help you, Help me
Powered by blists - more mailing lists