Repository navigation
Skip redundant memset for large calloc allocations backed by OS-zeroed pages. - #1915
Draft
copybara-service[bot] wants to merge 1 commit into
Draft
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
…d pages. Large `calloc` allocations (such as Android bitmaps exceeding `kMaxSize`) that are satisfied from freshly mapped or `MADV_DONTNEED`-released memory are already guaranteed by the kernel to read as zero. Running `memset` across the entire allocation eagerly faults in every physical page, increasing memory footprint and allocation latency even for pages the caller never touches. Propagate a `zeroed` status in `PageAllocatorInterface::AllocationState` (packed into existing struct padding with zero size increase) from `HugePageAwareAllocator` using existing unbacked-page metadata: - `HugeCache` allocations report `zeroed = from_released` when satisfied from `HugeAllocator` or released cache entries. - `HugeRegion::Inc` reports `zeroed = true` when every hugepage spanned by the allocation was previously unbacked in `backed_`. - `HugePageFiller::TryGet` reports `zeroed = true` when `previously_unbacked == n` (all pages were subreleased), and `RefillFiller` reports `zeroed = from_released` for the initial allocation on a newly refilled `PageTracker`. - `HugePageAwareAllocator::Finalize` clears `zeroed` if the `SystemAllocator` has ever released pages via `MADV_FREE` (`has_released_with_madv_free()`), or if a custom `AddressRegionFactory` is installed. In `do_calloc`, large allocations (`!is_small`) now call `slow_calloc_large`, which skips `memset` when `do_malloc_pages` reports `zeroed = true` and no `MallocHook::InvokeNewHook` was invoked. PiperOrigin-RevId: 1019402138
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Skip redundant memset for large calloc allocations backed by OS-zeroed pages.
Large
callocallocations (such as Android bitmaps exceedingkMaxSize) that are satisfied from freshly mapped orMADV_DONTNEED-released memory are already guaranteed by the kernel to read as zero. Runningmemsetacross the entire allocation eagerly faults in every physical page, increasing memory footprint and allocation latency even for pages the caller never touches.Propagate a
zeroedstatus inPageAllocatorInterface::AllocationState(packed into existing struct padding with zero size increase) fromHugePageAwareAllocatorusing existing unbacked-page metadata:HugeCacheallocations reportzeroed = from_releasedwhen satisfied fromHugeAllocatoror released cache entries.HugeRegion::Increportszeroed = truewhen every hugepage spanned by the allocation was previously unbacked inbacked_.HugePageFiller::TryGetreportszeroed = truewhenpreviously_unbacked == n(all pages were subreleased), andRefillFillerreportszeroed = from_releasedfor the initial allocation on a newly refilledPageTracker.HugePageAwareAllocator::Finalizeclearszeroedif theSystemAllocatorhas ever released pages viaMADV_FREE(has_released_with_madv_free()), or if a customAddressRegionFactoryis installed.In
do_calloc, large allocations (!is_small) now callslow_calloc_large, which skipsmemsetwhendo_malloc_pagesreportszeroed = trueand noMallocHook::InvokeNewHookwas invoked.