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
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.
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.
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?
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.
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).
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.
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.
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.
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.
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.
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.
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...
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.
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.
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.
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.
#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.
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.
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.
Activity
jasone commentedon Mar 6, 2015
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.
jasone commentedon Mar 6, 2015
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?
ldalessa commentedon Mar 6, 2015
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.
ldalessa commentedon Mar 6, 2015
Oops, wrong button, sorry.
jasone commentedon Mar 6, 2015
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.
ldalessa commentedon Mar 7, 2015
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).
DmitryKiselev commentedon Mar 25, 2015
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.
ldalessa commentedon Mar 25, 2015
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.
thestinger commentedon Mar 25, 2015
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.
ldalessa commentedon Mar 25, 2015
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.
thestinger commentedon Mar 25, 2015
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.
thestinger commentedon Mar 25, 2015
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.
ldalessa commentedon Mar 25, 2015
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...
DmitryKiselev commentedon Mar 25, 2015
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.
ldalessa commentedon Mar 25, 2015
Well, you can try and explicitly embed a chunk size if by including jemalloc.h and using the
const char *malloc_confsymbol. We do this now to preventmadvise(), 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.
ldalessa commentedon Mar 25, 2015
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.
shamisp commentedon Oct 15, 2015
Side comment: 16 bytes might not be enough for multi-rail RDMA scenarios. You may end up registering the memory with multiple devices,
ldalessa commentedon Oct 15, 2015
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.
shamisp commentedon Oct 15, 2015
Agreed, 16bytes is enough to store an entry to some external table or something.
jasone commentedon May 4, 2016
#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.
ldalessa commentedon May 4, 2016
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.
jasone commentedon Jan 11, 2017
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.