Skip to content

Allow user-data for chunks. #203

Closed
Closed

Description

@ldalessa

We use the custom chunk allocators to manage network-registered memory. A network-registration event returns a "key" that must be used with future network DMA operations. Right now, we store these keys out-of-place and look them up as necessary.

It would be really convenient for us if we could store the key (16 bytes at the moment) as part of the jemalloc chunk metadata at the base of each chunk or out-of-place for large allocations, and retrieve it using jemalloc's fast internal address masking or lookup.

An interface like id = JE_CURRENT_CHUNK(), je_chunk_set_user_data(chunk_id id, void *data, size_t size), and void *je_chunk_get_user_data(chunk_id id) would save us a lot of work for tracking this information.

A bounded size for user data would be fine.

This is simply a feature request to go along with the custom chunk allocation infrastructure.

Activity

  1. jasone commented on Mar 6, 2015

    @jasone
    Member

    I have some similar hypothetical use cases involving garbage collector metadata. One challenge for the application is that huge allocations still have to be handled similarly to your current approach.

    As for implementation challenges, the messiest one I'm aware of is that we either have to know how large the application metadata will be during allocator bootstrapping, or we have to track how much metadata actually got allocated on a per chunk basis (assuming that some chunks may have been created prior to application metadata being configured).

    One other consideration is whether to put application metadata in the chunk header, or to instead create a separate chunk footer. I slightly favor the chunk footer at the moment, because it enables simpler math for locating the metadata, which might be critical to performance in e.g. a GC write barrier.

  2. jasone commented on Mar 6, 2015

    @jasone
    Member

    The GC use case allows the application metadata to be proportional to the allocation size. So, a page of 16-byte regions would have the same amount of metadata storage as a page of 32-byte regions. Does that fit with your use case?

  3. ldalessa commented on Mar 6, 2015

    @ldalessa
    Author

    We really only need one fixed-width value per chunk. I can't, at the moment, think of a reason that we'd need anything dependent on the actual data. I just need to supply it to the network driver whenever anyone tries to perform DMA from or to the chunk.

    I have no preference w.r.t. header or footer that I can think of.

  4. ldalessa commented on Mar 6, 2015

    @ldalessa
    Author

    Oops, wrong button, sorry.

  5. jasone commented on Mar 6, 2015

    @jasone
    Member

    Embedding this in the header is probably better for small metadata uses like yours because it doesn't automatically require a full page to satisfy.

  6. ldalessa commented on Mar 7, 2015

    @ldalessa
    Author

    Yeah, as long as I can uniformly find it that's okay. I don't precisely know how jemalloc finds the larger allocations—there's clearly not a header being used there since we're getting the 0-bit offset back for them (which is good because we often need that alignment).

  7. DmitryKiselev commented on Mar 25, 2015

    @DmitryKiselev

    Hi there,
    We are also working with network registered memory and custom chunk allocators.

    Although, with RDMA sometimes you just want to expose a whole memory region for direct remote access (e.g. remote reads). (Memcached double read technique does just that).

    Hence, I would propose not to reserve that extra header or footer in a memory chunk by default. In other words if je_chunk_set_user_data() is not called, the whole chunk should be available to a user.

  8. ldalessa commented on Mar 25, 2015

    @ldalessa
    Author

    Hi Dmitry. My understanding is that, for normal chunks, jemalloc always uses a header for its own purpose, so the entire chunk would never be available. For "large" allocations I think jemalloc uses out-of-place metadata (or chunk footers?) to store its information. I'm sure Jason can elaborate.

  9. thestinger commented on Mar 25, 2015

    @thestinger
    Contributor

    Chunks (4M before, 256k recently in master) are naturally aligned and it finds the header where metadata is stored from the alignment offset. Anything at least as large as the chunk size (jemalloc calls these "huge") uses a global data structure for the metadata.

  10. ldalessa commented on Mar 25, 2015

    @ldalessa
    Author

    Oh, that's the first time I heard about the 256k change. 256k is a terrible chunk size for applications that are using common hugetlb sizes. I know chunk size can be set in MALLOC_CONF and via explicit char * string symbols, but that's sort of brittle.

    I'll have to add a request for jemalloc to use the hugetlbfs default page size for default chunk size if it exists and isn't overriden by MALLOC_CONF.

  11. thestinger commented on Mar 25, 2015

    @thestinger
    Contributor

    I like the idea of 2M as the default chunk size because it makes chunk/huge allocation play very well with transparent huge pages. I think there are good reasons for jemalloc switching to 256k though. The page fault heuristic for transparent huge pages also plays very poorly with jemalloc and tcmalloc right now but I don't really expect chunks smaller than 2M to result in less huge pages in the long term. It would need to be measured.

  12. thestinger commented on Mar 25, 2015

    @thestinger
    Contributor

    I think it switched to 256k because it reduces metadata overhead caused by sparsely filled chunks left after many deallocations but that are not completely emptied.

  13. ldalessa commented on Mar 25, 2015

    @ldalessa
    Author

    We deal with explicit huge pages all the time on older Cray systems in order to register enough memory for RDMA. When the default chunk size is lower than the default huge page size we end having to waste huge amounts of memory.

    I guess that we can just generate an error that MALLOC_CONF is set to a bad chunk size...

  14. DmitryKiselev commented on Mar 25, 2015

    @DmitryKiselev

    Hi Idalessa,
    good point! I forgot to mention that in our case, and hopefully in other cases too, it is only relevant to expose large memory regions across the fabric (Starting from 10 or 100 MB, for instance).

    We also use huge pages. I wonder if there is better way than erroring based on the MALLOC_CONF number, like to override that setting during the runtime, for instance.

  15. ldalessa commented on Mar 25, 2015

    @ldalessa
    Author

    Well, you can try and explicitly embed a chunk size if by including jemalloc.h and using the const char *malloc_conf symbol. We do this now to prevent madvise(), so it's trivial to set a default page size.

    Unfortunately, people use different default hugetlbfs sizes at runtime, which basically requires that they set their own MALLOC_CONF. I believe this should override the string symbol, but I haven't verified that.

  16. ldalessa commented on Mar 25, 2015

    @ldalessa
    Author

    In reality, if 256k is a better size for application behavior, then I can implement a super-chunk layer that allocates jemalloc chunks from huge tlb pages. I have a custom chunk allocator to get these pages anyway. The metadata layer between jemalloc and mmap() will slow down chunk allocation (particularly if I write it :-), but as long as that's not a critical path thing then it's not a big deal. I'll have to do this management out-of-place since jemalloc will want aligned chunks, which is unfortunate.

    The user data interface would still be useful, I'd just have to replicate RDMA keys; not a big deal at all.

  17. shamisp commented on Oct 15, 2015

    @shamisp

    Side comment: 16 bytes might not be enough for multi-rail RDMA scenarios. You may end up registering the memory with multiple devices,

  18. ldalessa commented on Oct 15, 2015

    @ldalessa
    Author

    Yeah, that's a good point. I feel like we might have a numa-thing going at that point where we only want to use a particular NIC for a particular chunk, but that's way out there in terms of what I'm worried about now. With 16 bytes I could do a counted pointer to a malloced record or something too, though getting more space inline wouldn't ever hurt.

  19. shamisp commented on Oct 15, 2015

    @shamisp

    Agreed, 16bytes is enough to store an entry to some external table or something.

  20. added this to the 5.0.0 milestone on Mar 15, 2016
  21. removed this from the 5.0.0 milestone on May 4, 2016
  22. jasone commented on May 4, 2016

    @jasone
    Member

    #360 may change jemalloc internals such that this feature doesn't fit well anymore. Also, during my (ongoing) work on that issue, I increasingly question the value of placing such metadata inside jemalloc data structures, since it would be possible to use a separate radix tree with very similar performance characteristics to the one used internally by jemalloc.

  23. ldalessa commented on May 4, 2016

    @ldalessa
    Author

    Sure, if you're moving away from in-place metadata this is less useful. As an aside, if your concurrent datastructures were distributed separately, or built with external linkage and exposed through an installed header, that would be a great contribution to users.

  24. jasone commented on Jan 11, 2017

    @jasone
    Member

    Chunks look like they're gone for good in the dev branch, and per extent user data would be of marginal utility. I'm going to close this issue, since it probably isn't going to fit well with jemalloc's design for the foreseeable future.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions