folly/folly/memory/JemallocNodumpAllocator.cpp

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed 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 <folly/memory/JemallocNodumpAllocator.h>

#include <folly/Conv.h>
#include <folly/String.h>
#include <folly/memory/Malloc.h>

#include <glog/logging.h>

namespace folly {

JemallocNodumpAllocator::JemallocNodumpAllocator(State state) {}

bool JemallocNodumpAllocator::extend_and_setup_arena() {}

void* JemallocNodumpAllocator::allocate(size_t size) {}

void* JemallocNodumpAllocator::reallocate(void* p, size_t size) {}

#ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED

#ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_CHUNK
chunk_alloc_t* JemallocNodumpAllocator::original_alloc_ = nullptr;
void* JemallocNodumpAllocator::alloc(
    void* chunk,
#else
extent_hooks_t JemallocNodumpAllocator::extent_hooks_;
extent_alloc_t* JemallocNodumpAllocator::original_alloc_ = nullptr;
void* JemallocNodumpAllocator::alloc(
    extent_hooks_t* extent,
    void* new_addr,
#endif
    size_t size,
    size_t alignment,
    bool* zero,
    bool* commit,
    unsigned arena_ind) {
  void* result = original_alloc_(
      JEMALLOC_CHUNK_OR_EXTENT,
#ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_EXTENT
      new_addr,
#endif
      size,
      alignment,
      zero,
      commit,
      arena_ind);
  if (result != nullptr) {
    if (auto ret = madvise(result, size, MADV_DONTDUMP)) {
      VLOG(1) << "Unable to madvise(MADV_DONTDUMP): " << errnoStr(ret);
    }
  }

  return result;
}

#endif // FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED

void JemallocNodumpAllocator::deallocate(void* p, size_t) {}

void JemallocNodumpAllocator::deallocate(void* p, void* userData) {}

JemallocNodumpAllocator& globalJemallocNodumpAllocator() {}

} // namespace folly