Skip to content

Commit

Permalink
Fix the server cache issue when cache becomes full and needs flush (#113
Browse files Browse the repository at this point in the history
)

* Fix the server cache issue when cache becomes full and need flush

* Committing clang-format changes

---------

Co-authored-by: github-actions <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
houjun and github-actions[bot] authored Jul 27, 2023
1 parent d1bdc16 commit 55a5628
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/server/pdc_server_region/pdc_server_region_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,11 @@ PDC_region_cache_register(uint64_t obj_id, int obj_ndim, const uint64_t *obj_dim
struct pdc_region_info *region_cache_info;
if (obj_ndim != ndim && obj_ndim > 0) {
printf("PDC_region_cache_register reports obj_ndim != ndim, %d != %d\n", obj_ndim, ndim);
return FAIL;
}

pthread_mutex_lock(&pdc_obj_cache_list_mutex);

obj_cache_iter = obj_cache_list;
while (obj_cache_iter != NULL) {
if (obj_cache_iter->obj_id == obj_id) {
Expand Down Expand Up @@ -460,7 +463,15 @@ PDC_region_cache_register(uint64_t obj_id, int obj_ndim, const uint64_t *obj_dim
memcpy(region_cache_info->buf, buf, sizeof(char) * buf_size);
total_cache_size += buf_size;

pthread_mutex_unlock(&pdc_obj_cache_list_mutex);

if (total_cache_size > maximum_cache_size) {
int server_rank = 0;
#ifdef ENABLE_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &server_rank);
#endif
printf("==PDC_SERVER[%d]: server cache full %.1f / %.1f MB, will flush to storage\n", server_rank,
total_cache_size / 1048576.0, maximum_cache_size / 1048576.0);
PDC_region_cache_flush_all();
}

Expand Down Expand Up @@ -571,11 +582,11 @@ PDC_transfer_request_data_write_out(uint64_t obj_id, int obj_ndim, const uint64_
region_cache_iter = region_cache_iter->next;
}
}
pthread_mutex_unlock(&pdc_obj_cache_list_mutex);
if (!flag) {
PDC_region_cache_register(obj_id, obj_ndim, obj_dims, buf, write_size, region_info->offset,
region_info->size, region_info->ndim, unit);
}
pthread_mutex_unlock(&pdc_obj_cache_list_mutex);

// PDC_Server_data_write_out2(obj_id, region_info, buf, unit);
#ifdef PDC_TIMING
Expand Down Expand Up @@ -862,10 +873,9 @@ PDC_region_cache_clock_cycle(void *ptr)
gettimeofday(&finish_time, NULL);
elapsed_time = finish_time.tv_sec - current_time.tv_sec +
(finish_time.tv_usec - current_time.tv_usec) / 1000000.0;
fprintf(
stderr,
"==PDC_SERVER[%d]: flushed %d regions from cache to storage (every %.1fs), took %.4fs\n",
server_rank, nflush, flush_frequency_s, elapsed_time);
fprintf(stderr,
"==PDC_SERVER[%d]: flushed %d regions to storage (full/every %.0fs), took %.4fs\n",
server_rank, nflush, flush_frequency_s, elapsed_time);
}
pthread_mutex_unlock(&pdc_obj_cache_list_mutex);
}
Expand Down

0 comments on commit 55a5628

Please sign in to comment.