[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250113093611.hmjmizvt73mrq2y2@master>
Date: Mon, 13 Jan 2025 09:36:11 +0000
From: Wei Yang <richard.weiyang@...il.com>
To: Suren Baghdasaryan <surenb@...gle.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,
richard.weiyang@...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 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.
>+}
>+
>+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