Re: [PATCH v2 2/2] locking/rwsem: Optimize down_read_trylock()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Waiman Long <longman@xxxxxxxxxx>
- Subject: Re: [PATCH v2 2/2] locking/rwsem: Optimize down_read_trylock()
- From: Ingo Molnar <mingo@xxxxxxxxxx>
- Date: Wed, 13 Feb 2019 08:45:44 +0100
- Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Will Deacon <will.deacon@xxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Linux List Kernel Mailing <linux-kernel@xxxxxxxxxxxxxxx>, linux-alpha@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-hexagon@xxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, Linux-sh list <linux-sh@xxxxxxxxxxxxxxx>, sparclinux@xxxxxxxxxxxxxxx, linux-xtensa@xxxxxxxxxxxxxxxx, linux-arch <linux-arch@xxxxxxxxxxxxxxx>, the arch/x86 maintainers <x86@xxxxxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, Davidlohr Bueso <dave@xxxxxxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
- In-reply-to: <ef66f262-d68e-58ea-34f6-15b88803cf71@redhat.com>
- References: <1549913486-16799-1-git-send-email-longman@redhat.com> <1549913486-16799-3-git-send-email-longman@redhat.com> <CAHk-=wjTmSg6zX=xKFSPZor7FWi3s4D0dy-hz_M=yeF_6478QA@mail.gmail.com> <ef66f262-d68e-58ea-34f6-15b88803cf71@redhat.com>
- User-agent: Mutt/1.9.4 (2018-02-28)
* Waiman Long <longman@xxxxxxxxxx> wrote:
> I looked at the assembly code in arch/x86/include/asm/rwsem.h. For both
> trylocks (read & write), the count is read first before attempting to
> lock it. We did the same for all trylock functions in other locks.
> Depending on how the trylock is used and how contended the lock is, it
> may help or hurt performance. Changing down_read_trylock to do an
> unconditional cmpxchg will change the performance profile of existing
> code. So I would prefer keeping the current code.
>
> I do notice now that the generic down_write_trylock() code is doing an
> unconditional compxchg. So I wonder if we should change it to read the
> lock first like other trylocks or just leave it as it is.
No, I think we should instead move the other trylocks to the
try-for-ownership model as well, like Linus suggested.
That's the general assumption we make in locking primitives, that we
optimize for the common, expected case - which would be that the trylock
succeeds, and I don't see why trylock primitives should be different.
In fact I can see more ways for read-for-sharing to perform suboptimally
on larger systems.
Thanks,
Ingo
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]