Skip to content

Commit

Permalink
Remove memory-check feature (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorstmann authored Jan 24, 2022
1 parent e375bba commit 5e435e2
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 63 deletions.
13 changes: 0 additions & 13 deletions arrow/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ Rust [README.md](../README.md).
Please refer to [lib.rs](src/lib.rs) for an introduction to this
specific crate and its current functionality.

### How to check memory allocations

This crate heavily uses `unsafe` due to how memory is allocated in cache lines.
We have a small tool to verify that this crate does not leak memory (beyond what the compiler already does)

Run it with

```bash
cargo test --features memory-check --lib -- --test-threads 1
```

This runs all unit-tests on a single thread and counts all allocations and de-allocations.

## IPC

The expected flatc version is 1.12.0+, built from [flatbuffers](https://github.com/google/flatbuffers)
Expand Down
4 changes: 0 additions & 4 deletions arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ prettyprint = ["comfy-table"]
# an optional dependency for supporting compile to wasm32-unknown-unknown
# target without assuming an environment containing JavaScript.
test_utils = ["rand"]
# this is only intended to be used in single-threaded programs: it verifies that
# all allocated memory is being released (no memory leaks).
# See README for details
memory-check = []
pyarrow = ["pyo3"]

[dev-dependencies]
Expand Down
15 changes: 1 addition & 14 deletions arrow/src/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,16 @@
//! Defines memory-related functions, such as allocate/deallocate/reallocate memory
//! regions, cache and allocation alignments.
use std::alloc::{handle_alloc_error, Layout};
use std::mem::size_of;
use std::ptr::NonNull;
use std::{
alloc::{handle_alloc_error, Layout},
sync::atomic::AtomicIsize,
};

mod alignment;
mod types;

pub use alignment::ALIGNMENT;
pub use types::NativeType;

// If this number is not zero after all objects have been `drop`, there is a memory leak
pub static mut ALLOCATIONS: AtomicIsize = AtomicIsize::new(0);

#[inline]
unsafe fn null_pointer<T: NativeType>() -> NonNull<T> {
NonNull::new_unchecked(ALIGNMENT as *mut T)
Expand All @@ -48,7 +42,6 @@ pub fn allocate_aligned<T: NativeType>(size: usize) -> NonNull<T> {
null_pointer()
} else {
let size = size * size_of::<T>();
ALLOCATIONS.fetch_add(size as isize, std::sync::atomic::Ordering::SeqCst);

let layout = Layout::from_size_align_unchecked(size, ALIGNMENT);
let raw_ptr = std::alloc::alloc(layout) as *mut T;
Expand All @@ -66,7 +59,6 @@ pub fn allocate_aligned_zeroed<T: NativeType>(size: usize) -> NonNull<T> {
null_pointer()
} else {
let size = size * size_of::<T>();
ALLOCATIONS.fetch_add(size as isize, std::sync::atomic::Ordering::SeqCst);

let layout = Layout::from_size_align_unchecked(size, ALIGNMENT);
let raw_ptr = std::alloc::alloc_zeroed(layout) as *mut T;
Expand All @@ -86,7 +78,6 @@ pub fn allocate_aligned_zeroed<T: NativeType>(size: usize) -> NonNull<T> {
pub unsafe fn free_aligned<T: NativeType>(ptr: NonNull<T>, size: usize) {
if ptr != null_pointer() {
let size = size * size_of::<T>();
ALLOCATIONS.fetch_sub(size as isize, std::sync::atomic::Ordering::SeqCst);
std::alloc::dealloc(
ptr.as_ptr() as *mut u8,
Layout::from_size_align_unchecked(size, ALIGNMENT),
Expand Down Expand Up @@ -121,10 +112,6 @@ pub unsafe fn reallocate<T: NativeType>(
return null_pointer();
}

ALLOCATIONS.fetch_add(
new_size as isize - old_size as isize,
std::sync::atomic::Ordering::SeqCst,
);
let raw_ptr = std::alloc::realloc(
ptr.as_ptr() as *mut u8,
Layout::from_size_align_unchecked(old_size, ALIGNMENT),
Expand Down
1 change: 0 additions & 1 deletion arrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,3 @@ pub mod record_batch;
pub mod temporal_conversions;
pub mod tensor;
pub mod util;
mod zz_memory_check;
31 changes: 0 additions & 31 deletions arrow/src/zz_memory_check.rs

This file was deleted.

0 comments on commit 5e435e2

Please sign in to comment.