use spin lock in auto growth allocator#34910
use spin lock in auto growth allocator#34910wanghuancoder merged 6 commits intoPaddlePaddle:developfrom wanghuancoder:spinlocks_for_allocator
Conversation
|
Thanks for your contribution! |
|
Some comments are listed as follows. @zhiqiu @wanghuancoder
|
我是在为新版本执行器写GC时发现的该问题,我用文字描述一下我的测试: 如果换成1跟线程同时负责以上2跟线程的工作(即不发生锁碰撞),整个测试用时24秒,mutable_data用时2.212,reeAllocation用时1.557秒。 如果仍是2根线程,将Allocator的锁改成自旋锁,整个测试用时27秒,mutable_data用时3.83,reeAllocation用时6.72秒。 |
There was a problem hiding this comment.
LGTM for some suggestions.
- Please add some notes about where the codes of
spin_lock.his from. - Try to implement a BasicLockable class instead of using macro everywhere.
class SpinLock {
public:
void lock();
void unlock();
DISABLE_COPY_AND_ASSIGN(SpinLock);
};… spinlocks_for_allocator
This reverts commit 6bacfb0.
PR types
Others
PR changes
Others
Describe
测试发现,在多线程申请显存、释放显存过程中,会发生锁碰撞。此时,会有1个线程进入休眠状态。当该线程获得锁后,再从休眠状态唤醒。这个过程是非常耗时的。直接影响了执行器的调度性能。
为此,我们将std::mutex 换成 自旋锁,自旋锁在发现锁已经被lock时,本线程会自旋等待,不进入休眠状态,实测性能比std::mutex好很多。
本PR只修改了auto growth allocator,其它的allocator不清楚都是什么依赖关系,暂未修改。