Skip to content

Commit

Permalink
pw_allocator: Refactor first fit allocators
Browse files Browse the repository at this point in the history
This CL merges the FirstFitBlockAllocator, LastFitBlockAllocator, and
DualFirstFitBlockAllocator into a single class, which makes use of
the updated Bucket types. It provides legacy aliases for existing
consumers.

Change-Id: I01c363236f3871b548617a5e134c19f80bf623fe
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/234816
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Taylor Cramer <cramertj@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Commit-Queue: Aaron Green <aarongreen@google.com>
  • Loading branch information
nopsledder authored and CQ Bot Account committed Nov 18, 2024
1 parent 3bfdac7 commit 0766dba
Show file tree
Hide file tree
Showing 54 changed files with 696 additions and 1,157 deletions.
4 changes: 1 addition & 3 deletions docs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,10 @@ _doxygen_input_files = [ # keep-sorted: start
"$dir_pw_allocator/public/pw_allocator/chunk_pool.h",
"$dir_pw_allocator/public/pw_allocator/config.h",
"$dir_pw_allocator/public/pw_allocator/deallocator.h",
"$dir_pw_allocator/public/pw_allocator/dual_first_fit_block_allocator.h",
"$dir_pw_allocator/public/pw_allocator/fallback_allocator.h",
"$dir_pw_allocator/public/pw_allocator/first_fit_block_allocator.h",
"$dir_pw_allocator/public/pw_allocator/first_fit.h",
"$dir_pw_allocator/public/pw_allocator/fragmentation.h",
"$dir_pw_allocator/public/pw_allocator/fuzzing.h",
"$dir_pw_allocator/public/pw_allocator/last_fit_block_allocator.h",
"$dir_pw_allocator/public/pw_allocator/layout.h",
"$dir_pw_allocator/public/pw_allocator/libc_allocator.h",
"$dir_pw_allocator/public/pw_allocator/metrics.h",
Expand Down
57 changes: 21 additions & 36 deletions pw_allocator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,12 @@ cc_library(
],
)

# TODO(b/376730645): Remove deprecated interfaces.
cc_library(
name = "dual_first_fit_block_allocator",
hdrs = ["public/pw_allocator/dual_first_fit_block_allocator.h"],
strip_include_prefix = "public",
deps = [
":block_allocator",
":config",
"//pw_allocator/block:detailed_block",
],
deps = [":first_fit"],
)

cc_library(
Expand All @@ -256,16 +253,25 @@ cc_library(
)

cc_library(
name = "first_fit_block_allocator",
hdrs = ["public/pw_allocator/first_fit_block_allocator.h"],
name = "first_fit",
hdrs = ["public/pw_allocator/first_fit.h"],
strip_include_prefix = "public",
deps = [
":block_allocator",
":config",
"//pw_allocator/block:detailed_block",
"//pw_allocator/bucket:sequenced",
],
)

# TODO(b/376730645): Remove deprecated interfaces.
cc_library(
name = "first_fit_block_allocator",
hdrs = ["public/pw_allocator/first_fit_block_allocator.h"],
includes = ["public"],
deps = [":first_fit"],
)

cc_library(
name = "fragmentation",
srcs = ["fragmentation.cc"],
Expand All @@ -287,15 +293,12 @@ cc_library(
],
)

# TODO(b/376730645): Remove deprecated interfaces.
cc_library(
name = "last_fit_block_allocator",
hdrs = ["public/pw_allocator/last_fit_block_allocator.h"],
strip_include_prefix = "public",
deps = [
":block_allocator",
":config",
"//pw_allocator/block:detailed_block",
],
deps = [":first_fit"],
)

cc_library(
Expand Down Expand Up @@ -412,10 +415,9 @@ cc_library(
deps = [
":allocator",
":buffer",
":first_fit_block_allocator",
":first_fit",
":test_config",
":tracking_allocator",
"//pw_allocator/block:detailed_block",
"//pw_assert",
"//pw_bytes",
"//pw_result",
Expand Down Expand Up @@ -580,16 +582,6 @@ pw_cc_test(
],
)

pw_cc_test(
name = "dual_first_fit_block_allocator_test",
srcs = ["dual_first_fit_block_allocator_test.cc"],
deps = [
":block_allocator_testing",
":dual_first_fit_block_allocator",
"//pw_unit_test",
],
)

pw_cc_test(
name = "fallback_allocator_test",
srcs = [
Expand All @@ -604,12 +596,15 @@ pw_cc_test(
)

pw_cc_test(
name = "first_fit_block_allocator_test",
srcs = ["first_fit_block_allocator_test.cc"],
name = "first_fit_test",
srcs = ["first_fit_test.cc"],
deps = [
":block_allocator_testing",
":buffer",
":dual_first_fit_block_allocator",
":first_fit",
":first_fit_block_allocator",
":last_fit_block_allocator",
"//pw_unit_test",
"//third_party/fuchsia:stdcompat",
],
Expand Down Expand Up @@ -639,16 +634,6 @@ pw_cc_test(
],
)

pw_cc_test(
name = "last_fit_block_allocator_test",
srcs = ["last_fit_block_allocator_test.cc"],
deps = [
":block_allocator_testing",
":last_fit_block_allocator",
"//pw_unit_test",
],
)

pw_cc_test(
name = "layout_test",
srcs = ["layout_test.cc"],
Expand Down
78 changes: 27 additions & 51 deletions pw_allocator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,11 @@ pw_source_set("deallocator") {
]
}

# TODO(b/376730645): Remove deprecated interfaces.
pw_source_set("dual_first_fit_block_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/dual_first_fit_block_allocator.h" ]
public_deps = [
":block_allocator",
":config",
"block:detailed_block",
]
public_deps = [ ":first_fit" ]
}

pw_source_set("fallback_allocator") {
Expand All @@ -227,16 +224,24 @@ pw_source_set("fallback_allocator") {
deps = [ "$dir_pw_assert:check" ]
}

pw_source_set("first_fit_block_allocator") {
pw_source_set("first_fit") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/first_fit_block_allocator.h" ]
public = [ "public/pw_allocator/first_fit.h" ]
public_deps = [
":block_allocator",
":config",
"block:detailed_block",
"bucket:sequenced",
]
}

# TODO(b/376730645): Remove deprecated interfaces.
pw_source_set("first_fit_block_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/first_fit_block_allocator.h" ]
public_deps = [ ":first_fit" ]
}

pw_source_set("fragmentation") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/fragmentation.h" ]
Expand All @@ -254,14 +259,11 @@ pw_source_set("freelist_heap") {
]
}

# TODO(b/376730645): Remove deprecated interfaces.
pw_source_set("last_fit_block_allocator") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_allocator/last_fit_block_allocator.h" ]
public_deps = [
":block_allocator",
":config",
"block:detailed_block",
]
public_deps = [ ":first_fit" ]
}

pw_source_set("libc_allocator") {
Expand Down Expand Up @@ -350,10 +352,9 @@ pw_source_set("testing") {
public_deps = [
":allocator",
":buffer",
":first_fit_block_allocator",
":first_fit",
":tracking_allocator",
"$dir_pw_sync:interrupt_spin_lock",
"block:detailed_block",
dir_pw_bytes,
dir_pw_result,
dir_pw_status,
Expand Down Expand Up @@ -473,14 +474,6 @@ pw_test("chunk_pool_test") {
sources = [ "chunk_pool_test.cc" ]
}

pw_test("dual_first_fit_block_allocator_test") {
deps = [
":block_allocator_testing",
":dual_first_fit_block_allocator",
]
sources = [ "dual_first_fit_block_allocator_test.cc" ]
}

pw_test("fallback_allocator_test") {
deps = [
":fallback_allocator",
Expand All @@ -490,14 +483,17 @@ pw_test("fallback_allocator_test") {
sources = [ "fallback_allocator_test.cc" ]
}

pw_test("first_fit_block_allocator_test") {
pw_test("first_fit_test") {
deps = [
":block_allocator_testing",
":buffer",
":dual_first_fit_block_allocator",
":first_fit",
":first_fit_block_allocator",
":last_fit_block_allocator",
"$dir_pw_third_party/fuchsia:stdcompat",
]
sources = [ "first_fit_block_allocator_test.cc" ]
sources = [ "first_fit_test.cc" ]
}

pw_test("fragmentation_test") {
Expand All @@ -518,14 +514,6 @@ pw_test("freelist_heap_test") {
sources = [ "freelist_heap_test.cc" ]
}

pw_test("last_fit_block_allocator_test") {
deps = [
":block_allocator_testing",
":last_fit_block_allocator",
]
sources = [ "last_fit_block_allocator_test.cc" ]
}

pw_test("layout_test") {
deps = [
":deallocator",
Expand Down Expand Up @@ -623,12 +611,10 @@ pw_test_group("tests") {
":buffer_test",
":bump_allocator_test",
":chunk_pool_test",
":dual_first_fit_block_allocator_test",
":fallback_allocator_test",
":first_fit_block_allocator_test",
":first_fit_test",
":fragmentation_test",
":freelist_heap_test",
":last_fit_block_allocator_test",
":layout_test",
":libc_allocator_test",
":null_allocator_test",
Expand Down Expand Up @@ -689,20 +675,10 @@ pw_size_diff("concrete_allocators_size_report") {
label = "BumpAllocator"
},
{
target = "size_report:dual_first_fit_block_allocator"
base = "size_report:null_allocator"
label = "DualFirstFitBlockAllocator"
},
{
target = "size_report:first_fit_block_allocator"
target = "size_report:first_fit"
base = "size_report:null_allocator"
label = "FirstFitBlockAllocator"
},
{
target = "size_report:last_fit_block_allocator"
base = "size_report:null_allocator"
label = "LastFitBlockAllocator"
},
{
target = "size_report:libc_allocator"
base = "size_report:null_allocator"
Expand Down Expand Up @@ -731,22 +707,22 @@ pw_size_diff("forwarding_allocators_size_report") {
},
{
target = "size_report:synchronized_allocator_isl"
base = "size_report:first_fit_block_allocator"
base = "size_report:first_fit"
label = "SynchronizedAllocator<sync::InterruptSpinLock>"
},
{
target = "size_report:synchronized_allocator_mutex"
base = "size_report:first_fit_block_allocator"
base = "size_report:first_fit"
label = "SynchronizedAllocator<sync::Mutex>"
},
{
target = "size_report:tracking_allocator_all_metrics"
base = "size_report:first_fit_block_allocator"
base = "size_report:first_fit"
label = "TrackingAllocator<AllMetrics>"
},
{
target = "size_report:tracking_allocator_no_metrics"
base = "size_report:first_fit_block_allocator"
base = "size_report:first_fit"
label = "TrackingAllocator<NoMetrics>"
},
]
Expand All @@ -757,7 +733,7 @@ pw_size_diff("allocator_utilities_size_report") {
binaries = [
{
target = "size_report:unique_ptr"
base = "size_report:first_fit_block_allocator"
base = "size_report:first_fit"
label = "UniquePtr"
},
]
Expand Down
Loading

0 comments on commit 0766dba

Please sign in to comment.