Skip to content

Extent hook wishlist #1009

Open
Open

Description

@davidtgoldblatt

Tracking issue for some extent hook things we've come across

  • Think about how to work with overallocating hooks #952 (let hooks overallocate if they want)
  • An indication of whether or not an allocation is for metadata or not (example application: allocation within memory sharing mappings with hardware. Metadata can be CPU-only, but allocations need to be within the memory shared with the hardware).

Activity

  1. interwq commented on Nov 3, 2017

    @interwq
    Contributor

    An additional use case came up with 1G huge page:

    • grow retained has an increasingly larger sequence for expanding VM
    • the sequence has no limit by default; however with 1G huge pages, physical memory is reserved already. grow_retained will obtain real committed physical memory
    • in addition, when the grow sequence becomes high, it could cause bad fragmentation, e.g. asking for 800MB when grow_retained, while we have 0.5G available from a huge page.

    #1064 is a workaround the issue with the current API. To solve this properly, we would want the API to incorporate more info, e.g. size_required and size_desired so that the extent hooks can determine how much memory to return.

  2. davidtgoldblatt commented on Dec 18, 2017

    @davidtgoldblatt
    ContributorAuthor

    A way to segregate thread-caches for different sets of extent hooks. (e.g. we really don't want no-dump memory leaking into non-nodump allocations).

  3. davidtgoldblatt commented on Dec 18, 2017

    @davidtgoldblatt
    ContributorAuthor

    Let users specify up-front whether or not their set of hooks should be considered to allow overcommit.

  4. davidtgoldblatt commented on Aug 6, 2018

    @davidtgoldblatt
    ContributorAuthor

    A "zero" option. Right now, we may call pages_purge_forced in the middle of a custom extent, which is more or less never desired.

  5. interwq commented on Jul 23, 2019

    @interwq
    Contributor

    Support for extent head / interior state, or to indicate a mergeable / splittable state -- as mentioned in #1545, on Windows we need to track if an extent is the head of a VirtualAlloc region (to avoid cross-region merge). Currently this information is tracked internally with a is_head bit, and we check the state before calling user hooks (instead of forcing the user to track this information).

  6. davidtgoldblatt commented on Dec 3, 2019

    @davidtgoldblatt
    ContributorAuthor

    Two:

    • The ability to mark a specific extent as "eager", in that it gets decayed / dalloc'd as soon as possible. This would let extent hooks from different arenas coordinate behind the scenes to share address space (say, that lives in a huge page somewhere).
    • The ability to set retain settings on a per-arena basis (different extent hooks may have different opinions there).
  7. davidtgoldblatt commented on Dec 3, 2019

    @davidtgoldblatt
    ContributorAuthor

    Information about whether or not an allocation is metadata can be useful on dealloc, too.

  8. davidtgoldblatt commented on Dec 3, 2019

    @davidtgoldblatt
    ContributorAuthor

    Letting the user squirrel away a pointer inside an extent (and get it back during extent operations) could be handy.

  9. davidtgoldblatt commented on Dec 4, 2019

    @davidtgoldblatt
    ContributorAuthor

    Letting the user squirrel away a pointer inside an extent (and get it back during extent operations) could be handy.

    To clarify: letting the user store a pointer-sized thing inside of the extent_t, which is passed back to the extent hooks during operations on the corresponding extents.

    Two ways to squeeze more space out of the extent_t:

    • Merge the ph node and the ql node (only one is active at a time).
    • Split up the representations for active and inactive extent_t (i.e. extent_t becomes a union across all possible extent types, each of which has its own representation).
  10. added this to the 6.0 milestone on Dec 4, 2019
  11. damageboy commented on Oct 6, 2020

    @damageboy

    Letting the user squirrel away a pointer inside an extent (and get it back during extent operations) could be handy.

    This would be great. AFAIK this is impossible today as jemalloc creates hooks on the fly during arena creation, like here, right? (On the last line):

    jemalloc/src/base.c

    Lines 344 to 355 in 092fcac

    base_t *
    base_new(tsdn_t *tsdn, unsigned ind, const extent_hooks_t *extent_hooks) {
    pszind_t pind_last = 0;
    size_t extent_sn_next = 0;
    /*
    * The base will contain the ehooks eventually, but it itself is
    * allocated using them. So we use some stack ehooks to bootstrap its
    * memory, and then initialize the ehooks within the base_t.
    */
    ehooks_t fake_ehooks;
    ehooks_init(&fake_ehooks, (extent_hooks_t *)extent_hooks, ind);

    As far as I can tell, this makes it impossible/useless to allocate the user supplied extents into a larger struct that carries more context with each extent, right?

    /cc: @davidtgoldblatt

  12. damageboy commented on Oct 6, 2020

    @damageboy

    Information about whether or not an allocation is metadata can be useful on dealloc, too.

    This would also be very useful for scenarios where I would like to control allocation inside a shared memory map, shared with a different process, for example, where all allocation is performed on one process but the resulting malloc'd pointers are to be used on both processes mapping the shared memory.

    This would allow hiding the metadata from the process NOT doing the allocation, so I think this could also be useful for the allocation of extents as well when supplying an extent_hooks_t

  13. davidtgoldblatt commented on Oct 9, 2020

    @davidtgoldblatt
    ContributorAuthor

    As far as I can tell, this makes it impossible/useless to allocate the user supplied extents into a larger struct that carries more context with each extent, right?

    Right; we don't do anything of the sort right now (and don't really provide a way to). I think asking the user to allocate the extents for us might be too much configurability, but I think we might be OK with a middle ground, of letting the user request some amount of per-extent space. We've also sort of run up against edata_t size limits in slab size configurations; we could make the edata_t size flexible and solve both issues at once.

    This would allow hiding the metadata from the process NOT doing the allocation, so I think this could also be useful for the allocation of extents as well when supplying an extent_hooks_t

    Yeah, this is the case we have in mind; right now we can ask for memory, but how that memory will be used may mean it should leave in different areas.

    BTW, if you can talk about it, we'd love to hear more about your use case -- we're actively thinking about how the next iteration of the extent hooks should look, so unusual use cases are of particular value right now.

  14. damageboy commented on Nov 3, 2020

    @damageboy

    @davidtgoldblatt understood.

    I think that providing a user-supplied size is a very reasonable way forward.
    I'll see if/when I can make the time for this.
    Thanks!

  15. Lapenkov commented on Sep 14, 2021

    @Lapenkov
    Contributor

    Store individual extern hook pointers per arena instead of storing a single pointer to user-provided extern_hooks_t. This way, we lose the ability to atomically set all hooks at once, but free the users of the burden of maintaining the lifetime of extern_hooks_t.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions