-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Make MemoryAllocator into a Customizable class #8980
Conversation
mrambacher
commented
Sep 30, 2021
- Make MemoryAllocator and its implementations into a Customizable class.
- Added a "DefaultMemoryAllocator" which uses new and delete
- Added a "CountedMemoryAllocator" that counts the number of allocs and free
- Updated the existing tests to use these new allocators
- Changed the memkind allocator test into a generic test that can test the various allocators.
- Added tests for creating all of the allocators
- Added tests to verify/create the JemallocNodumpAllocator using its options.
Some platforms (RedHat?) appear to have a slightly higher default...
include/rocksdb/memory_allocator.h
Outdated
std::string GetId() const override { return GenerateIndividualId(); } | ||
}; | ||
|
||
class MemoryAllocatorWrapper : public MemoryAllocator { |
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.
Can you explain a little why we need this "Wrapper" class?
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.
The CountedMemoryAllocator (a new class) extends this base one. If you rather it not, I can eliminate this class, but then the pattern does not follow almost every other Customizable class with Base and BaseWrapper
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.
If it is not necessary but just keep the pattern, we may not need it. We can add in the future if it is really useful.
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.
Tests under table_test use the CountedMemoryAllocator. Prior to this PR, the CountedMemoryAllocator was simply Default+count and not its own allocator. Are you suggesting I revert that? Is there a reason that we would not want to be able to potentially count allocations (for debug/stats purposes)?
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.
I prefer not to add the wrapper class to the public, it is kind of confusing. When we really need it, we can easily add in the future.
// Base class for a | ||
class BaseMemoryAllocator : public MemoryAllocator { | ||
public: | ||
void* Allocate(size_t /*size*/) override { |
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.
Can you explain why we need the "BaseMemoryAllocator". Looks like "JemallocNodumpAllocator", "MockMemoryAllocator", and "MemkindKmemAllocator" can directly inherited from "MemoryAllocator"
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.
The BaseMemoryAllocator implements the methods in a failure mode. By extending this class, Jemalloc et al can define the "real" methods only in the case where the functionality is compiled in. In other words, if compiled with Jemalloc disabled, the "Base" implementation is used. If compiled with Jemalloc enabled, the "real" implementation is used.
Otherwise, the code gets funky to allow the Jemalloc et al classes to exist but be empty for the implementations in which they are not enabled at compile time.
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.
You may add "The BaseMemoryAllocator implements the methods in a failure mode. By extending this class, Jemalloc et al can define the "real" methods only in the case where the functionality is compiled in. In other words, if compiled with Jemalloc disabled, the "Base" implementation is used. If compiled with Jemalloc enabled, the "real" implementation is used" as the comment for BaseMemoryAllocator
and indicate that all the allocator implementation should inherited from BaseMemoryAllocator
instead of MemoryAllocator
#include "rocksdb/memory_allocator.h" | ||
|
||
namespace ROCKSDB_NAMESPACE { | ||
// A memory allocator using new/delete |
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.
Need some comments to explain when should the user use this default memory allocator. Currently, it is mainly used in the test to replace the "CustomMemoryAllocator"
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.
There is no great advantage of using this class. We could set it as the default allocator and get rid of all of the code that checks if one exists and does new if it does not.
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.
I see. Just add some comments here to indicate the potential use cases.
@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
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.
LGTM
@mrambacher has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
@mrambacher has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
std::string msg; | ||
if (!JemallocNodumpAllocator::IsSupported(&msg)) { | ||
ASSERT_TRUE(s.IsNotSupported()); | ||
ROCKSDB_GTEST_SKIP("JEMALLOC not supported"); |
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.
Can we avoid using GTEST_SKIP
for now? Our internal infra reports this as warning which is a mixed signal.
@mrambacher
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.
@riversand963 I can change it to something else. Is the suggestion to use ROCKSDB_GTEST_BYPASS? Silently not running tests is a bad idea IMO.
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.
I haven't tried ROCKSDB_GTEST_BYPASS, but it's being used in external_sst_file_basic_test
, thus looks promising.
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.
@pdillinger @riversand963 I had it as SKIP as I thought that was appropriate but was then told to change it to BYPASS, which is what it is at now. This appears to fit exactly what SKIP says it is meant for (a feature not available in a compilation environment).
I think improving the comment with examples (e.g. if Snappy is not available, then use which one?) for when to use SKIP or BYPASS would be beneficial.
Status s = MemoryAllocator::CreateFromString(config_options_, id, &allocator); | ||
if (!JemallocNodumpAllocator::IsSupported()) { | ||
ASSERT_TRUE(s.IsNotSupported()); | ||
ROCKSDB_GTEST_SKIP("JEMALLOC not supported"); |
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.
Ditto