hugepage-rs 0.1.0

wrapped allocator for linux hugepage
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented1 out of 2 items with examples
  • Size
  • Source code size: 10.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.27 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • cppcoffee/hugepage-rs
    12 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cppcoffee

hugepage-rs

hugepage-rs wrapped allocator for linux hugepage.

Usage

HugePage Allocator

Hugepage allocator provides two interfaces for operation, hugepage_rs::alloc and hugepage_rs::dealloc, allocate and free hugepage memory.

The hugepage_rs::alloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. returns std::ptr::null_mut() if allocation fails, otherwise returns a pointer.

use hugepage_rs;

use std::alloc::Layout;
use std::{mem, ptr};

fn main() {
    let layout = Layout::array::<char>(2048).unwrap();
    let dst = hugepage_rs::alloc(layout);

    let src = String::from("hello");
    let len = src.len();
    unsafe {
        ptr::copy_nonoverlapping(src.as_ptr(), dst, len);
        let s = String::from_raw_parts(dst, len, len);
        assert_eq!(s, src);
        mem::forget(s);
    }

    hugepage_rs::dealloc(dst, layout);
}

HugePage Boxed

Simple Box implementation with ownership, data on hugepage allocated memory, released directly after going out of scope, memory allocator using hugepage allocator.

use hugepage_rs;

fn main() {
    let mut v = hugepage_rs::Box::new(5);
    *v += 42;
    assert_eq!(*v, 47);
}

Notes

  • System need to enable hugepage.

Reference

Huge pages part 1 (Introduction)

Huge pages part 2: Interfaces

Huge pages part 3: Administration

Huge pages part 4: benchmarking with huge pages

Huge pages part 5: A deeper look at TLBs and costs

https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt

https://man7.org/linux/man-pages/man2/mmap.2.html