Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

mrambacher
Copy link
Contributor

  • 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.

std::string GetId() const override { return GenerateIndividualId(); }
};

class MemoryAllocatorWrapper : public MemoryAllocator {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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)?

Copy link
Contributor

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 {
Copy link
Contributor

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"

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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"

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@zhichao-cao zhichao-cao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@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");
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

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

Successfully merging this pull request may close these issues.

4 participants