forked from OSchip/llvm-project
[scudo] Separate Fuchsia & Default SizeClassMap
The Fuchsia allocator config was using the default size class map. This CL gives Fuchsia its own size class map and changes a couple of things in the default one: - make `SizeDelta` configurable in `Config` for a fixed size class map as it currently is for a table size class map; - switch `SizeDelta` to 0 for the default config, it allows for size classes that allow for power of 2s, and overall better wrt pages filling; - increase the max number of caches pointers to 14 in the default, this makes the transfer batch 64/128 bytes on 32/64-bit platforms, which is cache-line friendly (previous size was 48/96 bytes). The Fuchsia size class map remains untouched for now, this doesn't impact Android which uses the table size class map. Differential Revision: https://reviews.llvm.org/D102783
This commit is contained in:
parent
e42636d3c1
commit
20c1f94220
|
@ -140,7 +140,7 @@ struct AndroidSvelteConfig {
|
|||
|
||||
#if SCUDO_CAN_USE_PRIMARY64
|
||||
struct FuchsiaConfig {
|
||||
using SizeClassMap = DefaultSizeClassMap;
|
||||
using SizeClassMap = FuchsiaSizeClassMap;
|
||||
static const bool MaySupportMemoryTagging = false;
|
||||
|
||||
typedef SizeClassAllocator64<FuchsiaConfig> Primary;
|
||||
|
|
|
@ -64,12 +64,10 @@ class FixedSizeClassMap : public SizeClassMapBase<Config> {
|
|||
static const u8 S = Config::NumBits - 1;
|
||||
static const uptr M = (1UL << S) - 1;
|
||||
|
||||
static const uptr SizeDelta = Chunk::getHeaderSize();
|
||||
|
||||
public:
|
||||
static const u32 MaxNumCachedHint = Config::MaxNumCachedHint;
|
||||
|
||||
static const uptr MaxSize = (1UL << Config::MaxSizeLog) + SizeDelta;
|
||||
static const uptr MaxSize = (1UL << Config::MaxSizeLog) + Config::SizeDelta;
|
||||
static const uptr NumClasses =
|
||||
MidClass + ((Config::MaxSizeLog - Config::MidSizeLog) << S) + 1;
|
||||
static_assert(NumClasses <= 256, "");
|
||||
|
@ -79,24 +77,22 @@ public:
|
|||
static uptr getSizeByClassId(uptr ClassId) {
|
||||
DCHECK_NE(ClassId, BatchClassId);
|
||||
if (ClassId <= MidClass)
|
||||
return (ClassId << Config::MinSizeLog) + SizeDelta;
|
||||
return (ClassId << Config::MinSizeLog) + Config::SizeDelta;
|
||||
ClassId -= MidClass;
|
||||
const uptr T = MidSize << (ClassId >> S);
|
||||
return T + (T >> S) * (ClassId & M) + SizeDelta;
|
||||
return T + (T >> S) * (ClassId & M) + Config::SizeDelta;
|
||||
}
|
||||
|
||||
static u8 getSizeLSBByClassId(uptr ClassId) {
|
||||
return u8(getLeastSignificantSetBitIndex(getSizeByClassId(ClassId)));
|
||||
}
|
||||
|
||||
static constexpr bool usesCompressedLSBFormat() {
|
||||
return false;
|
||||
}
|
||||
static constexpr bool usesCompressedLSBFormat() { return false; }
|
||||
|
||||
static uptr getClassIdBySize(uptr Size) {
|
||||
if (Size <= SizeDelta + (1 << Config::MinSizeLog))
|
||||
if (Size <= Config::SizeDelta + (1 << Config::MinSizeLog))
|
||||
return 1;
|
||||
Size -= SizeDelta;
|
||||
Size -= Config::SizeDelta;
|
||||
DCHECK_LE(Size, MaxSize);
|
||||
if (Size <= MidSize)
|
||||
return (Size + MinSize - 1) >> Config::MinSizeLog;
|
||||
|
@ -227,12 +223,25 @@ struct DefaultSizeClassConfig {
|
|||
static const uptr MinSizeLog = 5;
|
||||
static const uptr MidSizeLog = 8;
|
||||
static const uptr MaxSizeLog = 17;
|
||||
static const u32 MaxNumCachedHint = 10;
|
||||
static const u32 MaxNumCachedHint = 14;
|
||||
static const uptr MaxBytesCachedLog = 10;
|
||||
static const uptr SizeDelta = 0;
|
||||
};
|
||||
|
||||
typedef FixedSizeClassMap<DefaultSizeClassConfig> DefaultSizeClassMap;
|
||||
|
||||
struct FuchsiaSizeClassConfig {
|
||||
static const uptr NumBits = 3;
|
||||
static const uptr MinSizeLog = 5;
|
||||
static const uptr MidSizeLog = 8;
|
||||
static const uptr MaxSizeLog = 17;
|
||||
static const u32 MaxNumCachedHint = 10;
|
||||
static const uptr MaxBytesCachedLog = 10;
|
||||
static const uptr SizeDelta = Chunk::getHeaderSize();
|
||||
};
|
||||
|
||||
typedef FixedSizeClassMap<FuchsiaSizeClassConfig> FuchsiaSizeClassMap;
|
||||
|
||||
struct AndroidSizeClassConfig {
|
||||
#if SCUDO_WORDSIZE == 64U
|
||||
static const uptr NumBits = 7;
|
||||
|
@ -285,6 +294,7 @@ struct SvelteSizeClassConfig {
|
|||
static const uptr MaxSizeLog = 14;
|
||||
static const u32 MaxNumCachedHint = 13;
|
||||
static const uptr MaxBytesCachedLog = 10;
|
||||
static const uptr SizeDelta = Chunk::getHeaderSize();
|
||||
#else
|
||||
static const uptr NumBits = 4;
|
||||
static const uptr MinSizeLog = 3;
|
||||
|
@ -292,6 +302,7 @@ struct SvelteSizeClassConfig {
|
|||
static const uptr MaxSizeLog = 14;
|
||||
static const u32 MaxNumCachedHint = 14;
|
||||
static const uptr MaxBytesCachedLog = 10;
|
||||
static const uptr SizeDelta = Chunk::getHeaderSize();
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -509,6 +509,7 @@ struct DeathSizeClassConfig {
|
|||
static const scudo::uptr MaxSizeLog = 13;
|
||||
static const scudo::u32 MaxNumCachedHint = 4;
|
||||
static const scudo::uptr MaxBytesCachedLog = 12;
|
||||
static const scudo::uptr SizeDelta = 0;
|
||||
};
|
||||
|
||||
static const scudo::uptr DeathRegionSizeLog = 20U;
|
||||
|
|
|
@ -35,6 +35,7 @@ struct OneClassSizeClassConfig {
|
|||
static const scudo::uptr MaxSizeLog = 5;
|
||||
static const scudo::u32 MaxNumCachedHint = 0;
|
||||
static const scudo::uptr MaxBytesCachedLog = 0;
|
||||
static const scudo::uptr SizeDelta = 0;
|
||||
};
|
||||
|
||||
TEST(ScudoSizeClassMapTest, OneClassSizeClassMap) {
|
||||
|
@ -49,6 +50,7 @@ struct LargeMaxSizeClassConfig {
|
|||
static const scudo::uptr MaxSizeLog = 63;
|
||||
static const scudo::u32 MaxNumCachedHint = 128;
|
||||
static const scudo::uptr MaxBytesCachedLog = 16;
|
||||
static const scudo::uptr SizeDelta = 0;
|
||||
};
|
||||
|
||||
TEST(ScudoSizeClassMapTest, LargeMaxSizeClassMap) {
|
||||
|
|
Loading…
Reference in New Issue