[PA] kOffsetTagNotInDirectMap->kOffsetTagNormalBuckets
Change-Id: Ie2697abd4a3e690bd35b9ce77b291b9fbe2b0d30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2943381 Commit-Queue: Bartek Nowierski <bartekn@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Takashi Sakamoto <tasak@google.com> Cr-Commit-Position: refs/heads/master@{#890865}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
cd07856e42
commit
2d20a0a71e
base/allocator/partition_allocator
@ -3037,12 +3037,11 @@ TEST_F(PartitionAllocTest, RefCountRealloc) {
|
|||||||
#endif // BUILDFLAG(USE_BACKUP_REF_PTR)
|
#endif // BUILDFLAG(USE_BACKUP_REF_PTR)
|
||||||
|
|
||||||
TEST_F(PartitionAllocTest, ReservationOffset) {
|
TEST_F(PartitionAllocTest, ReservationOffset) {
|
||||||
// For normal buckets, offset should be kOffsetTagNotInDirectMap.
|
// For normal buckets, offset should be kOffsetTagNormalBuckets.
|
||||||
void* ptr = allocator.root()->Alloc(kTestAllocSize, type_name);
|
void* ptr = allocator.root()->Alloc(kTestAllocSize, type_name);
|
||||||
EXPECT_TRUE(ptr);
|
EXPECT_TRUE(ptr);
|
||||||
uintptr_t ptr_as_uintptr = reinterpret_cast<uintptr_t>(ptr);
|
uintptr_t ptr_as_uintptr = reinterpret_cast<uintptr_t>(ptr);
|
||||||
EXPECT_EQ(kOffsetTagNotInDirectMap,
|
EXPECT_EQ(kOffsetTagNormalBuckets, *ReservationOffsetPointer(ptr_as_uintptr));
|
||||||
*ReservationOffsetPointer(ptr_as_uintptr));
|
|
||||||
allocator.root()->Free(ptr);
|
allocator.root()->Free(ptr);
|
||||||
|
|
||||||
// For not yet allocated memory, offset should be kOffsetTagNotAllocated.
|
// For not yet allocated memory, offset should be kOffsetTagNotAllocated.
|
||||||
|
@ -290,7 +290,7 @@ SlotSpanMetadata<thread_safe>* PartitionDirectMap(
|
|||||||
int offset = 0;
|
int offset = 0;
|
||||||
while (ptr_start < ptr_end) {
|
while (ptr_start < ptr_end) {
|
||||||
PA_DCHECK(offset_ptr < GetReservationOffsetTableEnd());
|
PA_DCHECK(offset_ptr < GetReservationOffsetTableEnd());
|
||||||
PA_DCHECK(offset < kOffsetTagNotInDirectMap);
|
PA_DCHECK(offset < kOffsetTagNormalBuckets);
|
||||||
*offset_ptr++ = offset++;
|
*offset_ptr++ = offset++;
|
||||||
ptr_start += kSuperPageSize;
|
ptr_start += kSuperPageSize;
|
||||||
}
|
}
|
||||||
@ -536,10 +536,8 @@ ALWAYS_INLINE void* PartitionBucket<thread_safe>::AllocNewSuperPage(
|
|||||||
if (UNLIKELY(!super_page))
|
if (UNLIKELY(!super_page))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// Set the reservation offset table entry to NotInDirectMapOffsetTag, to
|
|
||||||
// indicate that it isn't direct-map allocated.
|
|
||||||
*ReservationOffsetPointer(reinterpret_cast<uintptr_t>(super_page)) =
|
*ReservationOffsetPointer(reinterpret_cast<uintptr_t>(super_page)) =
|
||||||
kOffsetTagNotInDirectMap;
|
kOffsetTagNormalBuckets;
|
||||||
|
|
||||||
root->total_size_of_super_pages.fetch_add(kSuperPageSize,
|
root->total_size_of_super_pages.fetch_add(kSuperPageSize,
|
||||||
std::memory_order_relaxed);
|
std::memory_order_relaxed);
|
||||||
|
@ -21,7 +21,7 @@ namespace internal {
|
|||||||
|
|
||||||
static constexpr uint16_t kOffsetTagNotAllocated =
|
static constexpr uint16_t kOffsetTagNotAllocated =
|
||||||
std::numeric_limits<uint16_t>::max();
|
std::numeric_limits<uint16_t>::max();
|
||||||
static constexpr uint16_t kOffsetTagNotInDirectMap =
|
static constexpr uint16_t kOffsetTagNormalBuckets =
|
||||||
std::numeric_limits<uint16_t>::max() - 1;
|
std::numeric_limits<uint16_t>::max() - 1;
|
||||||
|
|
||||||
// The main purpose of the reservation offset table is to easily locate the
|
// The main purpose of the reservation offset table is to easily locate the
|
||||||
@ -50,7 +50,7 @@ static constexpr uint16_t kOffsetTagNotInDirectMap =
|
|||||||
// ((Z >> kSuperPageShift) - (the entry for Z)) << kSuperPageShift
|
// ((Z >> kSuperPageShift) - (the entry for Z)) << kSuperPageShift
|
||||||
//
|
//
|
||||||
// kOffsetTagNotAllocated is a special tag denoting that the super page isn't
|
// kOffsetTagNotAllocated is a special tag denoting that the super page isn't
|
||||||
// allocated by PartitionAlloc and kOffsetTagNotInDirectMap denotes that it is
|
// allocated by PartitionAlloc and kOffsetTagNormalBuckets denotes that it is
|
||||||
// used for a normal-bucket allocation, not for a direct-map allocation.
|
// used for a normal-bucket allocation, not for a direct-map allocation.
|
||||||
//
|
//
|
||||||
// *) In 32-bit mode, Y is not used by PartitionAlloc, and cannot be used
|
// *) In 32-bit mode, Y is not used by PartitionAlloc, and cannot be used
|
||||||
@ -75,8 +75,8 @@ class BASE_EXPORT ReservationOffsetTable {
|
|||||||
static constexpr size_t kReservationOffsetTableLength =
|
static constexpr size_t kReservationOffsetTableLength =
|
||||||
4 * kGiB / kSuperPageSize;
|
4 * kGiB / kSuperPageSize;
|
||||||
#endif
|
#endif
|
||||||
static_assert(kReservationOffsetTableLength < kOffsetTagNotInDirectMap,
|
static_assert(kReservationOffsetTableLength < kOffsetTagNormalBuckets,
|
||||||
"Offsets should be smaller than kOffsetTagNotInDirectMap.");
|
"Offsets should be smaller than kOffsetTagNormalBuckets.");
|
||||||
|
|
||||||
static struct _ReservationOffsetTable {
|
static struct _ReservationOffsetTable {
|
||||||
// Thenumber of table elements is less than MAX_UINT16, so the element type
|
// Thenumber of table elements is less than MAX_UINT16, so the element type
|
||||||
@ -123,7 +123,7 @@ ALWAYS_INLINE uintptr_t GetDirectMapReservationStart(void* address) {
|
|||||||
uintptr_t ptr_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
uintptr_t ptr_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
||||||
uint16_t* offset_ptr = ReservationOffsetPointer(ptr_as_uintptr);
|
uint16_t* offset_ptr = ReservationOffsetPointer(ptr_as_uintptr);
|
||||||
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
||||||
if (*offset_ptr == kOffsetTagNotInDirectMap)
|
if (*offset_ptr == kOffsetTagNormalBuckets)
|
||||||
return 0;
|
return 0;
|
||||||
uintptr_t reservation_start =
|
uintptr_t reservation_start =
|
||||||
(ptr_as_uintptr & kSuperPageBaseMask) -
|
(ptr_as_uintptr & kSuperPageBaseMask) -
|
||||||
@ -157,7 +157,7 @@ ALWAYS_INLINE bool IsReservationStart(const void* address) {
|
|||||||
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
||||||
uint16_t* offset_ptr = ReservationOffsetPointer(address_as_uintptr);
|
uint16_t* offset_ptr = ReservationOffsetPointer(address_as_uintptr);
|
||||||
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
||||||
return ((*offset_ptr == kOffsetTagNotInDirectMap) || (*offset_ptr == 0)) &&
|
return ((*offset_ptr == kOffsetTagNormalBuckets) || (*offset_ptr == 0)) &&
|
||||||
(address_as_uintptr % kSuperPageSize == 0);
|
(address_as_uintptr % kSuperPageSize == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ ALWAYS_INLINE bool IsManagedByNormalBuckets(const void* address) {
|
|||||||
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
||||||
uint16_t* offset_ptr = ReservationOffsetPointer(address_as_uintptr);
|
uint16_t* offset_ptr = ReservationOffsetPointer(address_as_uintptr);
|
||||||
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
||||||
return *offset_ptr == kOffsetTagNotInDirectMap;
|
return *offset_ptr == kOffsetTagNormalBuckets;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if |address| belongs to a direct map region.
|
// Returns true if |address| belongs to a direct map region.
|
||||||
@ -176,7 +176,7 @@ ALWAYS_INLINE bool IsManagedByDirectMap(const void* address) {
|
|||||||
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
uintptr_t address_as_uintptr = reinterpret_cast<uintptr_t>(address);
|
||||||
uint16_t* offset_ptr = ReservationOffsetPointer(address_as_uintptr);
|
uint16_t* offset_ptr = ReservationOffsetPointer(address_as_uintptr);
|
||||||
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
PA_DCHECK(*offset_ptr != kOffsetTagNotAllocated);
|
||||||
return *offset_ptr != kOffsetTagNotInDirectMap;
|
return *offset_ptr != kOffsetTagNormalBuckets;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
Reference in New Issue
Block a user