Skip to content

Implement opt-in per arena background asynchronous worker threads. #149

Closed

Description

@jasone

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.
  • Pre-fill acaches.

Activity

  1. self-assigned this
    on Oct 14, 2014
  2. added this to the 4.0.0 milestone on Oct 14, 2014
  3. stephan-tolksdorf commented on Oct 14, 2014

    @stephan-tolksdorf

    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).

  4. modified the milestones: 4.1.0, 4.0.0 on Apr 30, 2015
  5. ldalessa commented on May 8, 2015

    @ldalessa

    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.

  6. jasone commented on Feb 5, 2016

    @jasone
    MemberAuthor

    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:

    1. Quiescent arenas will be a more likely possibility for typical applications, because kernel scheduling of threads determines arena use rather than thread-->arena binding.
    2. 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.

  7. interwq commented on Feb 5, 2016

    @interwq
    Contributor

    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:

    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:

    1. Quiescent arenas will be a more likely possibility for typical
      applications, because kernel scheduling of threads determines arena use
      rather than thread-->arena binding.
    2. 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).

  8. jasone commented on Feb 5, 2016

    @jasone
    MemberAuthor

    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.

  9. modified the milestones: 4.2.0, 4.1.0 on Feb 21, 2016
  10. modified the milestones: 5.0.0, 4.2.0 on May 4, 2016
  11. removed their assignment
    on Jun 8, 2016
  12. wizzard0 commented on Jul 21, 2016

    @wizzard0

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions