prefetch some objs associated with req->obj_id by searching prefetch_hashtable and ptable_array and evict when space is full. @param cache the cache struct @param req the request containing the request @return */
| 328 | @return |
| 329 | */ |
| 330 | void Mithril_prefetch(cache_t *cache, const request_t *req) { |
| 331 | Mithril_params_t *Mithril_params = |
| 332 | (Mithril_params_t *)(cache->prefetcher->params); |
| 333 | |
| 334 | gint prefetch_table_index = GPOINTER_TO_INT(g_hash_table_lookup( |
| 335 | Mithril_params->prefetch_hashtable, GINT_TO_POINTER(req->obj_id))); |
| 336 | |
| 337 | gint dim1 = |
| 338 | (gint)floor(prefetch_table_index / (double)PREFETCH_TABLE_SHARD_SIZE); |
| 339 | gint dim2 = prefetch_table_index % PREFETCH_TABLE_SHARD_SIZE * |
| 340 | (Mithril_params->pf_list_size + 1); |
| 341 | |
| 342 | request_t *new_req = my_malloc(request_t); |
| 343 | copy_request(new_req, req); |
| 344 | |
| 345 | if (prefetch_table_index) { |
| 346 | int i; |
| 347 | for (i = 1; i < Mithril_params->pf_list_size + 1; i++) { |
| 348 | // begin from 1 because index 0 is the obj_id of originated request |
| 349 | if (Mithril_params->ptable_array[dim1][dim2 + i] == 0) { |
| 350 | break; |
| 351 | } |
| 352 | new_req->obj_id = Mithril_params->ptable_array[dim1][dim2 + i]; |
| 353 | new_req->obj_size = GPOINTER_TO_INT(g_hash_table_lookup( |
| 354 | Mithril_params->cache_size_map, GINT_TO_POINTER(new_req->obj_id))); |
| 355 | |
| 356 | if (Mithril_params->output_statistics) { |
| 357 | Mithril_params->num_of_check += 1; |
| 358 | } |
| 359 | |
| 360 | if (cache->find(cache, new_req, false)) { |
| 361 | continue; |
| 362 | } |
| 363 | |
| 364 | while ((long)cache->get_occupied_byte(cache) + new_req->obj_size + |
| 365 | cache->obj_md_size > |
| 366 | (long)cache->cache_size) { |
| 367 | cache->evict(cache, new_req); |
| 368 | } |
| 369 | cache->insert(cache, new_req); |
| 370 | |
| 371 | if (Mithril_params->output_statistics) { |
| 372 | Mithril_params->num_of_prefetch_Mithril += 1; |
| 373 | |
| 374 | g_hash_table_insert(Mithril_params->prefetched_hashtable_Mithril, |
| 375 | GINT_TO_POINTER(new_req->obj_id), |
| 376 | GINT_TO_POINTER(1)); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // prefetch sequential |
| 382 | // just use in block or cache line level where obj_size is same |
| 383 | if (Mithril_params->sequential_type == 1 && |
| 384 | _Mithril_check_sequential(cache, req)) { |
| 385 | new_req->obj_id = req->obj_id + 1; |
| 386 | new_req->obj_size = req->obj_size; // same size |
| 387 |
nothing calls this directly
no test coverage detected