From e649e2b59522f6a0ca6f96968d429fa79a1a30da Mon Sep 17 00:00:00 2001 From: Aaron Kaiser Date: Mon, 22 Apr 2024 15:02:11 +0200 Subject: [PATCH] fix: reduce size of memory map --- src/bump_allocator.rs | 8 ++++---- src/sharedptr.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bump_allocator.rs b/src/bump_allocator.rs index ef56ade..6d99375 100644 --- a/src/bump_allocator.rs +++ b/src/bump_allocator.rs @@ -3,10 +3,10 @@ use std::{ usize, }; -use libc::{c_char, c_void, ftruncate, memfd_create, mmap, MAP_SHARED, PROT_READ, PROT_WRITE}; +use libc::{c_char, c_void, ftruncate, memfd_create, mmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE}; -pub(crate) const MEMFD_INITIAL_SIZE: usize = 1024 * 1024 * 4; -const MMAP_SIZE: usize = 1024 * 1024 * 1024; +pub(crate) const MEMFD_INITIAL_SIZE: usize = 1024 * 1024; +const MMAP_SIZE: usize = 1024 * 1024; pub(crate) static BUMP_ALLOCATOR: LazyLock> = LazyLock::new(|| unsafe { Mutex::new(BumpAllocator::new()) }); @@ -41,7 +41,7 @@ impl BumpAllocator { 0, ) as *mut u8; - assert_ne!(start_of_mem, 0 as *mut u8); + assert_ne!(start_of_mem, MAP_FAILED as *mut u8); let end_of_mem = start_of_mem.byte_add(MEMFD_INITIAL_SIZE); diff --git a/src/sharedptr.rs b/src/sharedptr.rs index 34652a8..a069714 100644 --- a/src/sharedptr.rs +++ b/src/sharedptr.rs @@ -6,6 +6,7 @@ use std::{ use crate::allocator::ALLOCATOR; +#[derive(Debug)] pub struct SharedPtr<'a>(&'a mut [u8]); impl SharedPtr<'_> {