Skip to content

Revert "[libc] Use best-fit binary trie to make malloc logarithmic" #117065

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

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions libc/fuzzing/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,3 @@ add_libc_fuzzer(
COMPILE_OPTIONS
-D__LIBC_EXPLICIT_SIMD_OPT
)

add_libc_fuzzer(
freelist_heap_fuzz
SRCS
freelist_heap_fuzz.cpp
DEPENDS
libc.src.__support.freelist_heap
)
227 changes: 0 additions & 227 deletions libc/fuzzing/__support/freelist_heap_fuzz.cpp

This file was deleted.

26 changes: 2 additions & 24 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,25 @@ add_header_library(
libc.src.__support.CPP.type_traits
)

add_object_library(
add_header_library(
freelist
HDRS
freelist.h
SRCS
freelist.cpp
DEPENDS
.block
libc.src.__support.fixedvector
libc.src.__support.CPP.array
libc.src.__support.CPP.cstddef
libc.src.__support.CPP.new
libc.src.__support.CPP.span
)

add_object_library(
freetrie
HDRS
freetrie.h
SRCS
freetrie.cpp
DEPENDS
.block
.freelist
)

add_header_library(
freestore
HDRS
freestore.h
DEPENDS
.freetrie
)

add_header_library(
freelist_heap
HDRS
freelist_heap.h
DEPENDS
.block
.freestore
.freelist
libc.src.__support.CPP.cstddef
libc.src.__support.CPP.array
libc.src.__support.CPP.optional
Expand Down
35 changes: 11 additions & 24 deletions libc/src/__support/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,32 +174,16 @@ class Block {
return inner_size - sizeof(prev_) + BLOCK_OVERHEAD;
}

/// @returns The number of usable bytes inside the block were it to be
/// allocated.
/// @returns The number of usable bytes inside the block.
size_t inner_size() const {
if (!next())
return 0;
return inner_size(outer_size());
}

/// @returns The number of usable bytes inside a block with the given outer
/// size were it to be allocated.
static size_t inner_size(size_t outer_size) {
// The usable region includes the prev_ field of the next block.
return inner_size_free(outer_size) + sizeof(prev_);
}

/// @returns The number of usable bytes inside the block if it remains free.
size_t inner_size_free() const {
if (!next())
return 0;
return inner_size_free(outer_size());
}

/// @returns The number of usable bytes inside a block with the given outer
/// size if it remains free.
static size_t inner_size_free(size_t outer_size) {
return outer_size - BLOCK_OVERHEAD;
return outer_size - BLOCK_OVERHEAD + sizeof(prev_);
}

/// @returns A pointer to the usable space inside this block.
Expand All @@ -217,11 +201,14 @@ class Block {

/// Attempts to split this block.
///
/// If successful, the block will have an inner size of at least
/// `new_inner_size`, rounded to ensure that the split point is on an
/// ALIGNMENT boundary. The remaining space will be returned as a new block.
/// Note that the prev_ field of the next block counts as part of the inner
/// size of the returnd block.
/// If successful, the block will have an inner size of `new_inner_size`,
/// rounded to ensure that the split point is on an ALIGNMENT boundary. The
/// remaining space will be returned as a new block. Note that the prev_ field
/// of the next block counts as part of the inner size of the returnd block.
///
/// This method may fail if the remaining space is too small to hold a new
/// block. If this method fails for any reason, the original block is
/// unmodified.
optional<Block *> split(size_t new_inner_size);

/// Merges this block with the one that comes after it.
Expand Down Expand Up @@ -455,7 +442,7 @@ Block<OffsetType, kAlign>::split(size_t new_inner_size) {
// The prev_ field of the next block is always available, so there is a
// minimum size to a block created through splitting.
if (new_inner_size < sizeof(prev_))
new_inner_size = sizeof(prev_);
return {};

size_t old_inner_size = inner_size();
new_inner_size =
Expand Down
42 changes: 0 additions & 42 deletions libc/src/__support/freelist.cpp

This file was deleted.

Loading
Loading