@@ -72,13 +72,16 @@ namespace {
7272struct CachedBlock {
7373 static constexpr u16 CacheIndexMax = UINT16_MAX;
7474 static constexpr u16 InvalidEntry = CacheIndexMax;
75- // * MaxReleasedCachePages default is currently 4
76- // - We arrived at this value after noticing that mapping
77- // in larger memory regions performs better than releasing
78- // memory and forcing a cache hit. According to the data,
79- // it suggests that beyond 4 pages, the release execution time is
80- // longer than the map execution time. In this way, the default
81- // is dependent on the platform.
75+ // We allow a certain amount of fragmentation and part of the fragmented bytes
76+ // will be released by `releaseAndZeroPagesToOS()`. This increases the chance
77+ // of cache hit rate and reduces the overhead to the RSS at the same time. See
78+ // more details in the `MapAllocatorCache::retrieve()` section.
79+ //
80+ // We arrived at this default value after noticing that mapping in larger
81+ // memory regions performs better than releasing memory and forcing a cache
82+ // hit. According to the data, it suggests that beyond 4 pages, the release
83+ // execution time is longer than the map execution time. In this way,
84+ // the default is dependent on the platform.
8285 static constexpr uptr MaxReleasedCachePages = 4U ;
8386
8487 uptr CommitBase = 0 ;
@@ -725,8 +728,14 @@ MapAllocator<Config>::tryAllocateFromCache(const Options &Options, uptr Size,
725728 uptr EntryHeaderPos;
726729 uptr MaxAllowedFragmentedPages = MaxUnreleasedCachePages;
727730
728- if (UNLIKELY ( useMemoryTagging<Config>(Options)))
731+ if (LIKELY (! useMemoryTagging<Config>(Options))) {
729732 MaxAllowedFragmentedPages += CachedBlock::MaxReleasedCachePages;
733+ } else {
734+ // TODO: Enable MaxReleasedCachePages may result in pages for an entry being
735+ // partially released and it erases the tag of those pages as well. To
736+ // support this feature for MTE, we need to tag those pages again.
737+ DCHECK_EQ (MaxAllowedFragmentedPages, MaxUnreleasedCachePages);
738+ }
730739
731740 Entry = Cache.retrieve (MaxAllowedFragmentedPages, Size, Alignment,
732741 getHeadersSize (), EntryHeaderPos);
0 commit comments