diff --git a/src/server/pdc_server_region/pdc_server_region_cache.c b/src/server/pdc_server_region/pdc_server_region_cache.c index 92c408fa6..d2f2abe56 100644 --- a/src/server/pdc_server_region/pdc_server_region_cache.c +++ b/src/server/pdc_server_region/pdc_server_region_cache.c @@ -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) { @@ -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(); } @@ -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 @@ -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); }