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
{{ message }}
Repository navigation
Implement opt-in per arena background asynchronous worker threads. #149
Several housekeeping operations in jemalloc are currently piggybacked on normal allocation/deallocation requests, because there is no way to asynchronously perform work. Although jemalloc must continue to support this mode of operation by default (it's unacceptable to create threads behind the application's back), large long-lived server applications could greatly benefit from jemalloc managing per arena background asynchronous worker threads. Main application threads could hand off various work, including:
Purge unused dirty pages.
Batch-deallocate regions flushed from tcaches or acaches.
An alternative to letting jemalloc manage its own threads would be to let the application provide a callback through which jemalloc can schedule work on some application-specific thread pool.
For periodic garbage collecting work, jemalloc could also expose an API function that the application can call during otherwise "idle" periods (e.g. from an event or scheduler loop).
Stephan's second suggestion is something that we could use relatively easily as well. We could leverage a "progress" call to let us do some allocator work while we're waiting on network operations or whatnot.
I've started work on decay-based unused dirty page purging (#325), and during design it has become apparent that we can get away without asynchronous threads for that feature as long as we aren't using per CPU arenas (#14). With per CPU arenas, two important things will change:
Quiescent arenas will be a more likely possibility for typical applications, because kernel scheduling of threads determines arena use rather than thread-->arena binding.
CPU-->arena binding will make per NUMA node asynchronous threads especially important, because a single asynchronous thread would damage NUMA-attached memory locality.
Therefore I'm going to put this feature off until we have a better sense of how well per CPU arenas might work.
In that case I'll try to prioritize the per cpu arenas work.
Regarding the quiescent arena with per cpu arenas, do you mean that no
other thread will be accessing the arena when the async thread is
scheduled? The benefit would be simpler and faster synchronization?
Thanks,
Qi
On Feb 5, 2016 10:09 AM, "Jason Evans" [email protected] wrote:
I've started work on decay-based unused dirty page purging (#325 #325), and during design it
has become apparent that we can get away without asynchronous threads for
that feature as long as we aren't using per CPU arenas (#14 #14). With per CPU arenas,
two important things will change:
Quiescent arenas will be a more likely possibility for typical
applications, because kernel scheduling of threads determines arena use
rather than thread-->arena binding.
CPU-->arena binding will make per NUMA node asynchronous threads
especially important, because a single asynchronous thread would damage
NUMA-attached memory locality.
Therefore I'm going to put this feature off until we have a better sense
of how well per CPU arenas might work.
—
Reply to this email directly or view it on GitHub #149 (comment).
Re: quiescent arenas, my concern is that even if an application has a set of constantly active threads in the steady state, it is possible for an arena to remain quiescent for extended periods of time simply due to the whims of the kernel's thread scheduling. For example, say thread T runs on CPU 0 most of the time, but the kernel schedules it on CPU 7 for a few seconds at some point due to a load spike, the arena associated with CPU 7 may never get used again. As a result, we can't depend as much on applications to consistently access particular sets of arenas, so if we try to drive unused dirty page purging based only on hooks that fire when an arena is accessed, we may arbitrarily fail to adequately purge.
I made the above comment mainly to document that asynchronous threads are actually important in the context of per CPU arenas, rather than in the context of unused dirty page purging, so the drive for this feature is different than I'd imagined. So, that doesn't put any special pressure on the timeline for per CPU arena support, but we do need to consider asynchronous threads an important aspect of that work.
I'm voting for the API "perform_maintenance_work" because we're spin-waiting on idle threads for requests to arrive (to avoid thread switch latency) and it makes perfect sense to do maintenance work here.
Also, for this API to be really useful, it should be fairly granular (and/or with customizable granularity), so we don't end up thread unexpectedly doing something long.
Activity
stephan-tolksdorf commentedon Oct 14, 2014
An alternative to letting jemalloc manage its own threads would be to let the application provide a callback through which jemalloc can schedule work on some application-specific thread pool.
For periodic garbage collecting work, jemalloc could also expose an API function that the application can call during otherwise "idle" periods (e.g. from an event or scheduler loop).
ldalessa commentedon May 8, 2015
Stephan's second suggestion is something that we could use relatively easily as well. We could leverage a "progress" call to let us do some allocator work while we're waiting on network operations or whatnot.
jasone commentedon Feb 5, 2016
I've started work on decay-based unused dirty page purging (#325), and during design it has become apparent that we can get away without asynchronous threads for that feature as long as we aren't using per CPU arenas (#14). With per CPU arenas, two important things will change:
Therefore I'm going to put this feature off until we have a better sense of how well per CPU arenas might work.
interwq commentedon Feb 5, 2016
Hi Jason,
In that case I'll try to prioritize the per cpu arenas work.
Regarding the quiescent arena with per cpu arenas, do you mean that no
other thread will be accessing the arena when the async thread is
scheduled? The benefit would be simpler and faster synchronization?
Thanks,
Qi
On Feb 5, 2016 10:09 AM, "Jason Evans" [email protected] wrote:
jasone commentedon Feb 5, 2016
Re: quiescent arenas, my concern is that even if an application has a set of constantly active threads in the steady state, it is possible for an arena to remain quiescent for extended periods of time simply due to the whims of the kernel's thread scheduling. For example, say thread T runs on CPU 0 most of the time, but the kernel schedules it on CPU 7 for a few seconds at some point due to a load spike, the arena associated with CPU 7 may never get used again. As a result, we can't depend as much on applications to consistently access particular sets of arenas, so if we try to drive unused dirty page purging based only on hooks that fire when an arena is accessed, we may arbitrarily fail to adequately purge.
I made the above comment mainly to document that asynchronous threads are actually important in the context of per CPU arenas, rather than in the context of unused dirty page purging, so the drive for this feature is different than I'd imagined. So, that doesn't put any special pressure on the timeline for per CPU arena support, but we do need to consider asynchronous threads an important aspect of that work.
wizzard0 commentedon Jul 21, 2016
I'm voting for the API "perform_maintenance_work" because we're spin-waiting on idle threads for requests to arrive (to avoid thread switch latency) and it makes perfect sense to do maintenance work here.
Also, for this API to be really useful, it should be fairly granular (and/or with customizable granularity), so we don't end up thread unexpectedly doing something long.