Skip to content

Revert "[scudo] Fix the logic of MaxAllowedFragmentedPages" #108130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

ChiaHungDuan
Copy link
Contributor

@ChiaHungDuan ChiaHungDuan commented Sep 11, 2024

Reverts #107927

We are supposed to check the MaxAllowedFragmentedPages instead.

@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (ChiaHungDuan)

Changes

Reverts llvm/llvm-project#107927


Full diff: https://github.com/llvm/llvm-project/pull/108130.diff

1 Files Affected:

  • (modified) compiler-rt/lib/scudo/standalone/secondary.h (+8-17)
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index c79ec1360b00a7..1a232b9b9fb2d7 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -72,16 +72,13 @@ namespace {
 struct CachedBlock {
   static constexpr u16 CacheIndexMax = UINT16_MAX;
   static constexpr u16 InvalidEntry = CacheIndexMax;
-  // We allow a certain amount of fragmentation and part of the fragmented bytes
-  // will be released by `releaseAndZeroPagesToOS()`. This increases the chance
-  // of cache hit rate and reduces the overhead to the RSS at the same time. See
-  // more details in the `MapAllocatorCache::retrieve()` section.
-  //
-  // We arrived at this default value after noticing that mapping in larger
-  // memory regions performs better than releasing memory and forcing a cache
-  // hit. According to the data, it suggests that beyond 4 pages, the release
-  // execution time is longer than the map execution time. In this way,
-  // the default is dependent on the platform.
+  //   * MaxReleasedCachePages default is currently 4
+  //        - We arrived at this value after noticing that mapping
+  //        in larger memory regions performs better than releasing
+  //        memory and forcing a cache hit. According to the data,
+  //        it suggests that beyond 4 pages, the release execution time is
+  //        longer than the map execution time. In this way, the default
+  //        is dependent on the platform.
   static constexpr uptr MaxReleasedCachePages = 4U;
 
   uptr CommitBase = 0;
@@ -728,14 +725,8 @@ MapAllocator<Config>::tryAllocateFromCache(const Options &Options, uptr Size,
   uptr EntryHeaderPos;
   uptr MaxAllowedFragmentedPages = MaxUnreleasedCachePages;
 
-  if (LIKELY(!useMemoryTagging<Config>(Options))) {
+  if (UNLIKELY(useMemoryTagging<Config>(Options)))
     MaxAllowedFragmentedPages += CachedBlock::MaxReleasedCachePages;
-  } else {
-    // TODO: Enable MaxReleasedCachePages may result in pages for an entry being
-    // partially released and it erases the tag of those pages as well. To
-    // support this feature for MTE, we need to tag those pages again.
-    DCHECK_EQ(CachedBlock::MaxReleasedCachePages, 0U);
-  }
 
   Entry = Cache.retrieve(MaxAllowedFragmentedPages, Size, Alignment,
                          getHeadersSize(), EntryHeaderPos);

@ChiaHungDuan ChiaHungDuan merged commit 76151c4 into main Sep 11, 2024
9 of 10 checks passed
@ChiaHungDuan ChiaHungDuan deleted the revert-107927-quick-fix branch September 11, 2024 01:56
ChiaHungDuan added a commit to ChiaHungDuan/Scudo-Workspace that referenced this pull request Sep 11, 2024
ChiaHungDuan added a commit that referenced this pull request Sep 11, 2024
#108134)

This reverts commit 76151c4.

Also changed to check MaxAllowedFragmentedPages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants