Skip to content

Commit

Permalink
Fix recommitted pages not being zeroed when madvise is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
klzgrad committed Sep 17, 2023
1 parent 978ff90 commit 0fc7bef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ jobs:
- arch: aarch64_cortex-a53-static
openwrt: 'target=sunxi subtarget=cortexa53'
target_cpu: arm64
extra: 'arm_cpu="cortex-a53" build_static=true'
extra: 'arm_cpu="cortex-a53" build_static=true no_madvise_syscall=true'
- arch: aarch64_cortex-a72
openwrt: 'target=mvebu subtarget=cortexa72'
target_cpu: arm64
Expand Down Expand Up @@ -443,7 +443,7 @@ jobs:
- arch: arm_cortex-a7_neon-vfpv4-static
openwrt: 'target=sunxi subtarget=cortexa7'
target_cpu: arm
extra: 'arm_version=0 arm_cpu="cortex-a7" arm_fpu="neon-vfpv4" arm_float_abi="hard" arm_use_neon=true build_static=true'
extra: 'arm_version=0 arm_cpu="cortex-a7" arm_fpu="neon-vfpv4" arm_float_abi="hard" arm_use_neon=true build_static=true no_madvise_syscall=true'
- arch: arm_cortex-a8_vfpv3
openwrt: 'target=sunxi subtarget=cortexa8'
target_cpu: arm
Expand All @@ -455,7 +455,7 @@ jobs:
- arch: arm_cortex-a9-static
openwrt: 'target=bcm53xx subtarget=generic'
target_cpu: arm
extra: 'arm_version=0 arm_cpu="cortex-a9" arm_float_abi="soft" arm_use_neon=false build_static=true'
extra: 'arm_version=0 arm_cpu="cortex-a9" arm_float_abi="soft" arm_use_neon=false build_static=true no_madvise_syscall=true'
- arch: arm_cortex-a9_neon
openwrt: 'target=zynq subtarget=generic'
target_cpu: arm
Expand All @@ -479,7 +479,7 @@ jobs:
- arch: mipsel_24kc-static
openwrt: 'target=ramips subtarget=rt305x'
target_cpu: mipsel
extra: 'mips_arch_variant="r2" mips_float_abi="soft" build_static=true'
extra: 'mips_arch_variant="r2" mips_float_abi="soft" build_static=true no_madvise_syscall=true'
- arch: mipsel_mips32
openwrt: 'target=bcm47xx subtarget=generic'
target_cpu: mipsel
Expand Down
2 changes: 2 additions & 0 deletions src/base/allocator/partition_allocator/page_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ constexpr PA_COMPONENT_EXPORT(
PARTITION_ALLOC) bool DecommittedMemoryIsAlwaysZeroed() {
#if BUILDFLAG(IS_APPLE)
return false;
#elif defined(NO_MADVISE_SYSCALL)
return false;
#else
return true;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,17 @@ void DiscardSystemPagesInternal(uintptr_t address, size_t length) {
ret = madvise(ptr, length, MADV_DONTNEED);
}
PA_PCHECK(ret == 0);
#elif defined(NO_MADVISE_SYSCALL)
static_cast<void>(ptr);
static_cast<void>(length);
#else // BUILDFLAG(IS_APPLE)
// We have experimented with other flags, but with suboptimal results.
//
// MADV_FREE (Linux): Makes our memory measurements less predictable;
// performance benefits unclear.
//
// Therefore, we just do the simple thing: MADV_DONTNEED.
int ret = madvise(ptr, length, MADV_DONTNEED);
if (ret && errno == ENOSYS) {
// Ignores when the kernel is built without CONFIG_ADVISE_SYSCALLS
return;
}
PA_PCHECK(ret == 0);
PA_PCHECK(0 == madvise(ptr, length, MADV_DONTNEED));
#endif // BUILDFLAG(IS_APPLE)
}

Expand Down
6 changes: 6 additions & 0 deletions src/build/config/openwrt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ assert(current_os == "openwrt")

declare_args() {
build_static = false

no_madvise_syscall = false
}

# This is included by reference in the //build/config/compiler config that
Expand All @@ -39,6 +41,10 @@ config("compiler") {
ldflags += [ "-Wl,--dynamic-linker=/lib/ld-musl-mipsel-sf.so.1" ]
}

if (no_madvise_syscall) {
defines += [ "NO_MADVISE_SYSCALL" ]
}

abi = "musl"
if (current_cpu == "arm") {
abi = "muslgnueabi"
Expand Down

0 comments on commit 0fc7bef

Please sign in to comment.