Skip to content

Commit

Permalink
[PA] Add GetSubsequentPageMetadata()
Browse files Browse the repository at this point in the history
Several call sites in `partition_page.h` use a naked "+ 1" to denote
hopping from one `PartitionPage` to the next. This CL adds a helper
to centralize that logic in a helper function of two variants (const
and non-const args + returns).

Change-Id: I01768c2c4fae13273ce13d1fc06b368776258f8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3829203
Commit-Queue: Kalvin Lee <kdlee@chromium.org>
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1035017}
  • Loading branch information
Kalvin Lee authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent f36813b commit 032ef13
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions base/allocator/partition_allocator/partition_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ PA_ALWAYS_INLINE PartitionPage<thread_safe>* PartitionSuperPageToMetadataArea(
SystemPageSize());
}

template <bool thread_safe>
PA_ALWAYS_INLINE const PartitionPage<thread_safe>* GetSubsequentPageMetadata(
const PartitionPage<thread_safe>* page) {
return page + 1;
}

template <bool thread_safe>
PA_ALWAYS_INLINE PartitionPage<thread_safe>* GetSubsequentPageMetadata(
PartitionPage<thread_safe>* page) {
return page + 1;
}

template <bool thread_safe>
PA_ALWAYS_INLINE PartitionSuperPageExtentEntry<thread_safe>*
PartitionSuperPageToExtent(uintptr_t super_page) {
Expand Down Expand Up @@ -678,23 +690,25 @@ template <bool thread_safe>
PA_ALWAYS_INLINE void SlotSpanMetadata<thread_safe>::SetRawSize(
size_t raw_size) {
PA_DCHECK(CanStoreRawSize());
auto* the_next_page = reinterpret_cast<PartitionPage<thread_safe>*>(this) + 1;
auto* the_next_page = GetSubsequentPageMetadata(
reinterpret_cast<PartitionPage<thread_safe>*>(this));
the_next_page->subsequent_page_metadata.raw_size = raw_size;
}

template <bool thread_safe>
PA_ALWAYS_INLINE size_t SlotSpanMetadata<thread_safe>::GetRawSize() const {
PA_DCHECK(CanStoreRawSize());
auto* the_next_page =
reinterpret_cast<const PartitionPage<thread_safe>*>(this) + 1;
auto* the_next_page = GetSubsequentPageMetadata(
reinterpret_cast<const PartitionPage<thread_safe>*>(this));
return the_next_page->subsequent_page_metadata.raw_size;
}

template <bool thread_safe>
PA_ALWAYS_INLINE PartitionTag*
SlotSpanMetadata<thread_safe>::DirectMapMTETag() {
PA_DCHECK(bucket->is_direct_mapped());
auto* the_next_page = reinterpret_cast<PartitionPage<thread_safe>*>(this) + 1;
auto* the_next_page = GetSubsequentPageMetadata(
reinterpret_cast<PartitionPage<thread_safe>*>(this));
return &the_next_page->subsequent_page_metadata.direct_map_tag;
}

Expand Down

0 comments on commit 032ef13

Please sign in to comment.