blob_contents.cc 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #include "db/blob/blob_contents.h"
  6. #include <cassert>
  7. #include "cache/cache_entry_roles.h"
  8. #include "cache/cache_helpers.h"
  9. #include "port/malloc.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. size_t BlobContents::ApproximateMemoryUsage() const {
  12. size_t usage = 0;
  13. if (allocation_) {
  14. MemoryAllocator* const allocator = allocation_.get_deleter().allocator;
  15. if (allocator) {
  16. usage += allocator->UsableSize(allocation_.get(), data_.size());
  17. } else {
  18. #ifdef ROCKSDB_MALLOC_USABLE_SIZE
  19. usage += malloc_usable_size(allocation_.get());
  20. #else
  21. usage += data_.size();
  22. #endif
  23. }
  24. }
  25. #ifdef ROCKSDB_MALLOC_USABLE_SIZE
  26. usage += malloc_usable_size(const_cast<BlobContents*>(this));
  27. #else
  28. usage += sizeof(*this);
  29. #endif
  30. return usage;
  31. }
  32. } // namespace ROCKSDB_NAMESPACE