Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
How to set a free strategy?

I've encountered high memory usage (looks like a memory leak) in production environment (container in k8s), and want to check if it's because of the "MADV_FREE" behaviour.

Is there a way to change to use MADV_DONTNEED instead of MADV_FREE in rust?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Rust allows overriding the default allocator with the #[global_allocator] attribute

struct MyAllocator;

unsafe impl GlobalAlloc for MyAllocator {
    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
        System.alloc(layout)
    }

    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
        System.dealloc(ptr, layout)
    }
}

#[global_allocator]
static GLOBAL: MyAllocator = MyAllocator;

You could use this to change the behavior of the deallocation to your needs.

Or possably use an existing crate that impliment allocators tha logs the allocations/deallocations such as tracing-allocator or logging-allocator.

#[global_allocator]
static GLOBAL: tracing_allocator::Allocator = tracing_allocator::Allocator{};

fn main() {
  let f = File::create("trace.txt").unwrap();
  tracing_allocator::Allocator::initialize(&f);
  tracing_allocator::Allocator::activate();
}

(I have no experience with these crates so I have no idea what they uses for allocations)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!