Re: [PATCH RESEND v3 03/10] mm/vma: rename is_vma_write_only(), separate out shared refcount put

Vlastimil Babka
2026-01-23T08:24:56Z

On 1/22/26 20:31, Suren Baghdasaryan wrote:
>> > + int oldcnt;
>> > + bool detached;
>> > +
>> > + detached = __refcount_dec_and_test(&vma->vm_refcnt, &oldcnt);
>> > + if (refcnt)
>> > + *refcnt = oldcnt - 1;
>> > + return detached;
>
> IIUC there is always a connection between detached and *refcnt
> resulting value. If detached==true then the resulting *refcnt has to
> be 0. If so, __vma_refcount_put() can simply return (oldcnt - 1) as
> new count:
>
> static inline int __vma_refcount_put(struct vm_area_struct *vma)
> {
> int oldcnt;
>
> __refcount_dec_and_test(&vma->vm_refcnt, &oldcnt);
> return oldcnt - 1;
> }
>
> And later:
>
> newcnt = __vma_refcount_put(&vma->vm_refcnt);
> detached = newcnt == 0;

If we go that way (both ways are fine with me) I'd suggest we rename the
function to __vma_refcount_put_return to make this more obvious. (c.f.
atomic_dec_return, lockref_put_return).