You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All of the locks used in JCoz are home-grown spinlocks + memory fences. The original intention here was to get the profiler out of the way of the program as quickly as possible, and spinlocks avoid the overhead of making syscalls or being descheduled by the kernel. Realistically, this was wrong for several reasons:
Some of the logic we do in the code is non-trivial. For example, we take the frame_lock when populating the vector of frames that were collected by user threads. This could result in dynamic memory allocations. This should just be a mutex.
libc mutexes are pretty heavily optimized at this point. They often do atomics and some minimal spinning to check if a lock is free or will be free soon, and then otherwise use a futex to sleep. This is much more efficient for the overall runtime of the system.
Linus Torvalds recently wrote about how using spin locks in userspace is not a good idea, which I agree with: https://www.realworldtech.com/forum/?threadid=189711&curpostid=189723. Even if we knew that some critical section was tiny, the kernel scheduler could just come in and deschedule us anyways.
Let's just use normal locking primitives.
The text was updated successfully, but these errors were encountered:
All of the locks used in
JCoz
are home-grown spinlocks + memory fences. The original intention here was to get the profiler out of the way of the program as quickly as possible, and spinlocks avoid the overhead of making syscalls or being descheduled by the kernel. Realistically, this was wrong for several reasons:frame_lock
when populating the vector of frames that were collected by user threads. This could result in dynamic memory allocations. This should just be a mutex.Let's just use normal locking primitives.
The text was updated successfully, but these errors were encountered: