Skip to content

Commit

Permalink
Improved Slab module to use less memory and be more lighweight
Browse files Browse the repository at this point in the history
  • Loading branch information
smarco committed Apr 4, 2022
1 parent f37fb5d commit 418777c
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 105 deletions.
27 changes: 19 additions & 8 deletions system/mm_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,25 +454,30 @@ void mm_allocator_get_occupation(
for (segment_idx=0;segment_idx<num_segments;++segment_idx) {
mm_allocator_segment_t* const segment = mm_allocator_get_segment(mm_allocator,segment_idx);
const uint64_t num_requests = mm_allocator_segment_get_num_requests(segment);
bool free_memory = true;
bool memory_freed = true;
for (request_idx=num_requests-1;request_idx>=0;--request_idx) {
mm_allocator_request_t* const request = mm_allocator_segment_get_request(segment,request_idx);
const uint64_t size = MM_ALLOCATOR_REQUEST_SIZE(request);
if (MM_ALLOCATOR_REQUEST_IS_FREE(request)) {
if (free_memory) {
if (memory_freed) {
*bytes_free_available += size;
} else {
*bytes_free_fragmented += size;
}
} else {
free_memory = false;
memory_freed = false;
*bytes_used_allocator += size;
}
}
// Account for free space at the end of the segment
if (num_requests > 0) {
mm_allocator_request_t* const request = mm_allocator_segment_get_request(segment,num_requests-1);
*bytes_free_available += segment->used - (request->offset+request->size);
const uint64_t bytes_free_at_end = segment->size - (request->offset+request->size);
if (segment_idx == mm_allocator->current_segment_idx) {
*bytes_free_available += bytes_free_at_end;
} else {
*bytes_free_fragmented += bytes_free_at_end;
}
}
}
// Check malloc memory
Expand Down Expand Up @@ -590,10 +595,16 @@ void mm_allocator_print(
uint64_t bytes_used_malloc, bytes_used_allocator;
uint64_t bytes_free_available, bytes_free_fragmented;
mm_allocator_get_occupation(mm_allocator,&bytes_used_malloc,&bytes_used_allocator,&bytes_free_available,&bytes_free_fragmented);
fprintf(stream," => Memory.used %" PRIu64 "\n",bytes_used_allocator);
fprintf(stream," => Memory.free %" PRIu64 "\n",bytes_free_available+bytes_free_fragmented);
fprintf(stream," => Memory.free.available %" PRIu64 "\n",bytes_free_available);
fprintf(stream," => Memory.free.fragmented %" PRIu64 "\n",bytes_free_fragmented);
const float bytes_total = num_segments * segment_size;
const uint64_t bytes_free = bytes_free_available + bytes_free_fragmented;
fprintf(stream," => Memory.used %" PRIu64 " (%2.1f %%)\n",
bytes_used_allocator,100.0f*(float)bytes_used_allocator/bytes_total);
fprintf(stream," => Memory.free %" PRIu64 " (%2.1f %%)\n",
bytes_free,100.0f*(float)bytes_free/bytes_total);
fprintf(stream," => Memory.free.available %" PRIu64 " (%2.1f %%)\n",
bytes_free_available,100.0f*(float)bytes_free_available/bytes_total);
fprintf(stream," => Memory.free.fragmented %" PRIu64 " (%2.1f %%)\n",
bytes_free_fragmented,100.0f*(float)bytes_free_fragmented/bytes_total);
fprintf(stream," => Memory.malloc %" PRIu64 "\n",bytes_used_malloc);
// Print memory requests
if (display_requests) {
Expand Down
14 changes: 6 additions & 8 deletions tools/align_benchmark/align_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ benchmark_args parameters = {
// System
.num_threads = 1,
.batch_size = 10000,
.progress = 10000,
.progress = 100000,
.verbose = 0,
};

Expand Down Expand Up @@ -293,12 +293,10 @@ int match_function(int v,int h,void* arguments) {
* Configuration
*/
wavefront_aligner_t* align_input_configure_wavefront(
align_input_t* const align_input,
mm_allocator_t* const mm_allocator) {
align_input_t* const align_input) {
// Set attributes
wavefront_aligner_attr_t attributes = wavefront_aligner_attr_default;
attributes.memory_mode = parameters.wfa_memory_mode;
attributes.mm_allocator = mm_allocator;
if (parameters.wfa_score_only) {
attributes.alignment_scope = compute_score;
}
Expand Down Expand Up @@ -390,10 +388,10 @@ void align_input_configure_global(
align_input->output_file = parameters.output_file;
align_input->output_full = parameters.output_full;
// MM
align_input->mm_allocator = mm_allocator_new(BUFFER_SIZE_8M);
align_input->mm_allocator = mm_allocator_new(BUFFER_SIZE_1M);
// WFA
if (align_benchmark_is_wavefront(parameters.algorithm)) {
align_input->wf_aligner = align_input_configure_wavefront(align_input,align_input->mm_allocator);
align_input->wf_aligner = align_input_configure_wavefront(align_input);
} else {
align_input->wf_aligner = NULL;
}
Expand Down Expand Up @@ -615,7 +613,7 @@ void align_benchmark_sequential() {
align_benchmark_print_progress(seqs_processed);
}
// DEBUG
// mm_allocator_print(stderr,align_input.mm_allocator,true);
// mm_allocator_print(stderr,align_input.wf_aligner->mm_allocator,true);
// Plot
if (parameters.plot > 0) align_benchmark_plot_wf(&align_input,seqs_processed);
}
Expand Down Expand Up @@ -690,7 +688,7 @@ void align_benchmark_parallel() {
align_benchmark_print_progress(seqs_processed);
}
// DEBUG
// mm_allocator_print(stderr,align_input.mm_allocator,true);
// mm_allocator_print(stderr,align_input.wf_aligner->mm_allocator,true);
}
// Print benchmark results
timer_stop(&parameters.timer_global);
Expand Down
4 changes: 3 additions & 1 deletion wavefront/wavefront_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ void wavefront_align_begin(
wavefront_debug_prologue(wf_aligner,pattern,pattern_length,text,text_length);
// Resize wavefront aligner
wavefront_aligner_resize(wf_aligner,pattern,pattern_length,text,text_length);
// DEBUG
// mm_allocator_print(stderr,wf_aligner->mm_allocator,false);
// Configure WF-compute function
switch (wf_aligner->penalties.distance_metric) {
case indel:
Expand Down Expand Up @@ -339,7 +341,7 @@ void wavefront_align_end(
wf_memory_used = wavefront_aligner_get_size(wf_aligner);
// Slab
if (wf_memory_used > wf_aligner->system.max_memory_resident) {
wavefront_slab_reap(wf_aligner->wavefront_slab,wf_slab_reap_all);
wavefront_slab_reap(wf_aligner->wavefront_slab);
}
}
// DEBUG
Expand Down
5 changes: 3 additions & 2 deletions wavefront/wavefront_aligner.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ wavefront_aligner_t* wavefront_aligner_new(
wavefront_aligner_t* const wf_aligner = mm_allocator_alloc(mm_allocator,wavefront_aligner_t);
wf_aligner->mm_allocator = mm_allocator;
wf_aligner->mm_allocator_own = mm_allocator_own;
wf_aligner->wavefront_slab = wavefront_slab_new(1000,bt_piggyback,mm_allocator);
const wf_slab_mode_t slab_mode = (memory_modular) ? wf_slab_reuse : wf_slab_tight;
wf_aligner->wavefront_slab = wavefront_slab_new(1000,bt_piggyback,slab_mode,mm_allocator);
// Configuration
wf_aligner->pattern_length = pattern_length;
wf_aligner->text_length = text_length;
Expand Down Expand Up @@ -254,7 +255,7 @@ void wavefront_aligner_reap(
// Wavefront components
wavefront_components_reap(&wf_aligner->wf_components);
// Slab
wavefront_slab_reap(wf_aligner->wavefront_slab,wf_slab_reap_all);
wavefront_slab_reap(wf_aligner->wavefront_slab);
}
void wavefront_aligner_delete(
wavefront_aligner_t* const wf_aligner) {
Expand Down
2 changes: 1 addition & 1 deletion wavefront/wavefront_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ wavefront_aligner_attr_t wavefront_aligner_attr_default = {
// System
.system = {
.max_alignment_score = INT_MAX, // Unlimited
.probe_interval_global = 2000,
.probe_interval_global = 3000,
.probe_interval_compact = 6000,
.max_memory_compact = -1, // Automatically set based on memory-mode
.max_memory_resident = -1, // Automatically set based on memory-mode
Expand Down
1 change: 1 addition & 0 deletions wavefront/wavefront_compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ int wavefront_compute_num_threads(
const int hi) {
// Parameters
const int max_num_threads = wf_aligner->system.max_num_threads;
if (max_num_threads == 1) return 1;
const int min_offsets_per_thread = wf_aligner->system.min_offsets_per_thread;
// Compute minimum work-chunks worth spawning threads
const int num_chunks = WAVEFRONT_LENGTH(lo,hi)/min_offsets_per_thread;
Expand Down
Loading

0 comments on commit 418777c

Please sign in to comment.