-
Notifications
You must be signed in to change notification settings - Fork 844
full use of jemalloc with NUMA support and rework of thread spawning #2314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,10 +23,11 @@ | |
|
|
||
| #ifndef __ARENA_H__ | ||
| #define __ARENA_H__ | ||
| #include "ts/ink_assert.h" | ||
| #include "ts/ink_memory.h" | ||
|
|
||
| #include <sys/types.h> | ||
| #include <memory.h> | ||
| #include "ts/ink_assert.h" | ||
|
|
||
| struct ArenaBlock { | ||
| ArenaBlock *next; | ||
|
|
@@ -166,4 +167,23 @@ Arena::str_store(const char *str, size_t len) | |
| return mem; | ||
| } | ||
|
|
||
| struct Arena_NoCache : public Arena { | ||
| std::allocator<uint64_t> m_alloc; | ||
|
|
||
| inkcoreapi void * | ||
| alloc(size_t size, size_t alignment = sizeof(double)) | ||
| { | ||
| return m_alloc.allocate((size + 1) / sizeof(uint64_t)); | ||
| } | ||
| void | ||
| free(void *mem, size_t size) | ||
| { | ||
| m_alloc.deallocate(static_cast<uint64_t *>(mem), size); | ||
| } | ||
| }; | ||
|
|
||
| #if HAVE_LIBJEMALLOC | ||
| #define Arena Arena_NoCache | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels odd. You're over-riding the alloc/free functions in a non-virtual class by way of the preprocessor. A person reading the code is unlikely to properly guess which function is actually going to be called. I'd move the As it is, if someone changes the signature of the first
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .. nope. C++ blocks all signature overloads from a base class that have the same function name. Lots and lots and lots of different techniques of specialized memory-hoarding doesn't speed things up, but often makes them vulnerable to unchecked and invisible bad-pointer usage. There's also no way to profile deletions or allocations ... when they're hidden deep inside a memory-hoarder. The thread-cache in Jemalloc is far more efficient.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, fair enough. It's still odd. I'm not seeing how the claim about memory-hoarding is relevant to this observation thought? I'm claiming that a reader is unlikely to determine correctly which code is actually going to execute by reading the function.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently I'm trying to make a non-mainline Jemalloc install (which is the point of the commit) work such that we can estimate it's performance. As it is ... the burden of #ifdef is worse than the burden of two overridden calls. |
||
| #endif | ||
|
|
||
| #endif /* __ARENA_H__ */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /** @file | ||
|
|
||
| A brief file description | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #include "StdAllocWrapper.h" | ||
| #include "ts/jemallctl.h" | ||
|
|
||
| #include "ts/ink_queue.h" | ||
| #include "ts/ink_defs.h" | ||
| #include "ts/ink_resource.h" | ||
| #include "ts/ink_align.h" | ||
| #include "ts/ink_memory.h" | ||
|
|
||
| void | ||
| AlignedAllocator::re_init(const char *name, unsigned int element_size, unsigned int chunk_size, unsigned int alignment, int advice) | ||
| { | ||
| _name = name; | ||
| _sz = aligned_spacing(element_size, std::max(sizeof(uint64_t), alignment + 0UL)); // increase to aligned size | ||
|
|
||
| if (advice == MADV_DONTDUMP) { | ||
| _arena = jemallctl::proc_arena_nodump; | ||
| } else if (advice == MADV_NORMAL) { | ||
| _arena = jemallctl::proc_arena; | ||
| } else { | ||
| ink_abort("allocator re_init: unknown madvise() flags: %x", advice); | ||
| } | ||
|
|
||
| void *preCached[chunk_size]; | ||
|
|
||
| for (int n = chunk_size; n--;) { | ||
| preCached[n] = mallocx(_sz, (MALLOCX_ALIGN(_sz) | MALLOCX_ARENA(_arena))); | ||
| } | ||
| for (int n = chunk_size; n--;) { | ||
| deallocate(preCached[n]); | ||
| } | ||
| } | ||
|
|
||
| AlignedAllocator::AlignedAllocator(const char *name, unsigned int element_size) | ||
| : _name(name), _sz(aligned_spacing(element_size, sizeof(uint64_t))) | ||
| { | ||
| // don't pre-allocate before main() is called | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to reorder these for a particular reason?