@@ -37,6 +37,8 @@ static uint64_t PMEM_N_FLUSH_THREADS;
37
37
static uint64_t PMEM_N_BUCKET_BITS = 8 ;
38
38
static uint64_t PMEM_N_SPACE_BITS = 5 ;
39
39
static uint64_t PMEM_PAGE_PER_BUCKET_BITS=10 ;
40
+ // 1 < this_value < flusher->size
41
+ static uint64_t PMEM_FLUSHER_WAKE_THRESHOLD=5 ;
40
42
41
43
static FILE* debug_file = fopen(" part_debug.txt" ," w" );
42
44
@@ -190,35 +192,35 @@ pm_wrapper_buf_alloc_or_open(
190
192
pmw->pbuf ->cur_free_param = 0 ; // start with the 0
191
193
192
194
// Open file
193
- pmw->pbuf ->deb_file = fopen (" part_debug .txt" ," w" );
195
+ pmw->pbuf ->deb_file = fopen (" pmem_debug .txt" ," w" );
194
196
195
- // //test for recovery
196
- printf (" ========== > Test for recovery\n " );
197
- TOID (PMEM_BUF_BLOCK_LIST) cur_list;
198
- PMEM_BUF_BLOCK_LIST* pcurlist;
199
-
200
- printf (" The bucket ====\n " );
201
- for (i = 0 ; i < PMEM_N_BUCKETS; i++) {
202
- TOID_ASSIGN (cur_list, (D_RW (pmw->pbuf ->buckets )[i]).oid );
203
- plist = D_RW (cur_list);
204
- printf (" list %zu is_flush %d cur_pages %zu max_pages %zu\n " ,plist->list_id , plist->is_flush , plist->cur_pages , plist->max_pages );
205
-
206
- TOID_ASSIGN (cur_list, (D_RW (cur_list)->next_list ).oid );
207
- printf (" \t [next list \n " );
208
- while ( !TOID_IS_NULL (cur_list)) {
209
- plist = D_RW (cur_list);
210
- printf (" \t\t next list %zu is_flush %d cur_pages %zu max_pages %zu\n " ,plist->list_id , plist->is_flush , plist->cur_pages , plist->max_pages );
211
- TOID_ASSIGN (cur_list, (D_RW (cur_list)->next_list ).oid );
212
- }
213
- printf (" \t end next list] \n " );
214
-
215
- // print the linked-list
216
-
217
- }
218
- printf (" The free pool ====\n " );
219
- PMEM_BUF_FREE_POOL* pfree_pool = D_RW (pmw->pbuf ->free_pool );
220
- printf (" cur_lists = %zu max_lists=%zu\n " ,
221
- pfree_pool->cur_lists , pfree_pool->max_lists );
197
+ // ////test for recovery
198
+ // printf("========== > Test for recovery\n");
199
+ // TOID(PMEM_BUF_BLOCK_LIST) cur_list;
200
+ // PMEM_BUF_BLOCK_LIST* pcurlist;
201
+ //
202
+ // printf("The bucket ====\n");
203
+ // for (i = 0; i < PMEM_N_BUCKETS; i++) {
204
+ // TOID_ASSIGN(cur_list, (D_RW(pmw->pbuf->buckets)[i]).oid);
205
+ // plist = D_RW(cur_list);
206
+ // printf("list %zu is_flush %d cur_pages %zu max_pages %zu\n",plist->list_id, plist->is_flush, plist->cur_pages, plist->max_pages );
207
+ //
208
+ // TOID_ASSIGN(cur_list, (D_RW(cur_list)->next_list).oid);
209
+ // printf("\t[next list \n");
210
+ // while( !TOID_IS_NULL(cur_list)) {
211
+ // plist = D_RW(cur_list);
212
+ // printf("\t\t next list %zu is_flush %d cur_pages %zu max_pages %zu\n",plist->list_id, plist->is_flush, plist->cur_pages, plist->max_pages );
213
+ // TOID_ASSIGN(cur_list, (D_RW(cur_list)->next_list).oid);
214
+ // }
215
+ // printf("\t end next list] \n");
216
+ //
217
+ // //print the linked-list
218
+ //
219
+ // }
220
+ // printf("The free pool ====\n");
221
+ // PMEM_BUF_FREE_POOL* pfree_pool = D_RW(pmw->pbuf->free_pool);
222
+ // printf("cur_lists = %zu max_lists=%zu\n",
223
+ // pfree_pool->cur_lists, pfree_pool->max_lists);
222
224
223
225
}
224
226
@@ -1238,9 +1240,10 @@ pm_buf_write_with_flusher(
1238
1240
pm_buf_handle_full_hashed_list (pop, buf, hashed);
1239
1241
goto retry;
1240
1242
}
1241
-
1242
- // printf("\n wait for list %zu cur_pages = %zu max_pages= %zu flushing....",
1243
- // phashlist->list_id, phashlist->cur_pages, phashlist->max_pages);
1243
+ #if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
1244
+ printf (" \n wait for list %zu cur_pages = %zu max_pages= %zu flushing...." ,
1245
+ phashlist->list_id , phashlist->cur_pages , phashlist->max_pages );
1246
+ #endif
1244
1247
1245
1248
pmemobj_rwlock_unlock (pop, &phashlist->lock );
1246
1249
os_event_wait (buf->flush_events [hashed]);
@@ -1360,6 +1363,10 @@ pm_buf_write_with_flusher(
1360
1363
// block upcomming writes into this bucket
1361
1364
os_event_reset (buf->flush_events [hashed]);
1362
1365
1366
+ #if defined (UNIV_PMEMOBJ_BUF_STAT)
1367
+ ++buf->bucket_stats [hashed].n_flushed_lists ;
1368
+ #endif
1369
+
1363
1370
pmemobj_rwlock_unlock (pop, &phashlist->lock );
1364
1371
pm_buf_handle_full_hashed_list (pop, buf, hashed);
1365
1372
@@ -2034,6 +2041,11 @@ pm_buf_read(
2034
2041
#endif
2035
2042
2036
2043
TOID_ASSIGN (cur_list, (D_RO (buf->buckets )[hashed]).oid );
2044
+
2045
+ #if defined(UNIV_PMEMOBJ_BUF_STAT)
2046
+ ++buf->bucket_stats [hashed].n_reads ;
2047
+ #endif
2048
+
2037
2049
if ( TOID_IS_NULL (cur_list)) {
2038
2050
// assert(!TOID_IS_NULL(cur_list));
2039
2051
printf (" PMEM_ERROR error in get hashded list, but return NULL, check again! \n " );
@@ -2045,11 +2057,15 @@ pm_buf_read(
2045
2057
// pblock = NULL;
2046
2058
// found = -1;
2047
2059
2048
- while ( !TOID_IS_NULL (cur_list) ) {
2060
+ while ( !TOID_IS_NULL (cur_list) && ( D_RO (cur_list) != NULL ) ) {
2049
2061
// plist = D_RW(cur_list);
2050
2062
// pmemobj_rwlock_rdlock(pop, &plist->lock);
2051
2063
// Scan in this list
2052
2064
// for (i = 0; i < D_RO(cur_list)->max_pages; i++) {
2065
+ if (D_RO (cur_list) == NULL ) {
2066
+ printf (" ===> ERROR read NULL list \n " );
2067
+ assert (0 );
2068
+ }
2053
2069
for (i = 0 ; i < D_RO (cur_list)->cur_pages ; i++) {
2054
2070
// accepted states: PMEM_IN_USED_BLOCK, PMEM_IN_FLUSH_BLOCK
2055
2071
// if ( D_RO(D_RO(plist->arr)[i])->state != PMEM_FREE_BLOCK &&
@@ -2060,30 +2076,21 @@ pm_buf_read(
2060
2076
// if(is_lock_on_read)
2061
2077
pmemobj_rwlock_rdlock (pop, &pblock->lock );
2062
2078
2063
- // if (!pblock->size.equals_to(size)) {
2064
- // printf("PMEM_ERROR size not equal!!!\n");
2065
- // assert(0);
2066
- // }
2067
- // found = i;
2068
2079
pdata = buf->p_align ;
2069
2080
2070
- // UNIV_MEM_ASSERT_RW(data, pblock->size.physical());
2071
- // pmemobj_memcpy_persist(pop, data, pdata + pblock->pmemaddr, pblock->size.physical());
2072
- // memcpy(data, pdata + D_RO(D_RO(D_RO(cur_list)->arr)[i])->pmemaddr, D_RO(D_RO(D_RO(cur_list)->arr)[i])->size.physical());
2073
2081
memcpy (data, pdata + pblock->pmemaddr , pblock->size .physical ());
2074
2082
// bytes_read = pblock->size.physical();
2075
2083
#if defined (UNIV_PMEMOBJ_DEBUG)
2076
2084
assert ( pm_check_io (pdata + pblock->pmemaddr , pblock->id ) ) ;
2077
2085
#endif
2078
2086
#if defined(UNIV_PMEMOBJ_BUF_STAT)
2079
- ++buf->bucket_stats [hashed].n_reads ;
2087
+ ++buf->bucket_stats [hashed].n_reads_hit ;
2080
2088
if (D_RO (cur_list)->is_flush )
2081
2089
++buf->bucket_stats [hashed].n_reads_flushing ;
2082
2090
#endif
2083
2091
// if(is_lock_on_read)
2084
2092
pmemobj_rwlock_unlock (pop, &pblock->lock );
2085
2093
2086
- // return bytes_read;
2087
2094
// return pblock;
2088
2095
return D_RO (D_RO (D_RO (cur_list)->arr )[i]);
2089
2096
}
@@ -2093,6 +2100,9 @@ pm_buf_read(
2093
2100
if ( TOID_IS_NULL (D_RO (cur_list)->next_list ))
2094
2101
break ;
2095
2102
TOID_ASSIGN (cur_list, (D_RO (cur_list)->next_list ).oid );
2103
+ if (TOID_IS_NULL (cur_list) || D_RO (cur_list) == NULL )
2104
+ break ;
2105
+
2096
2106
#if defined(UNIV_PMEMOBJ_BUF_STAT)
2097
2107
cur_level++;
2098
2108
if (buf->bucket_stats [hashed].max_linked_lists < cur_level)
@@ -2341,11 +2351,11 @@ pm_buf_handle_full_hashed_list(
2341
2351
2342
2352
/* (1) Handle flusher */
2343
2353
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
2344
- printf (" \n [ begin handle assign flusher list %zu hashed %zu ===> " , phashlist->list_id , hashed);
2354
+ printf (" \n [(1) begin handle assign flusher list %zu hashed %zu ===> " , phashlist->list_id , hashed);
2345
2355
#endif
2346
2356
pm_buf_assign_flusher (buf, phashlist);
2347
2357
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
2348
- printf (" end handle assign flusher list %zu]\n " , phashlist->list_id );
2358
+ printf (" (1) end handle assign flusher list %zu]\n " , phashlist->list_id );
2349
2359
#endif
2350
2360
2351
2361
@@ -2359,6 +2369,9 @@ pm_buf_handle_full_hashed_list(
2359
2369
2360
2370
/* (2) Handle free list*/
2361
2371
get_free_list:
2372
+ #if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
2373
+ printf (" \n (2) begin get_free_list to replace full list %zu ==>" , phashlist->list_id );
2374
+ #endif
2362
2375
// Get a free list from the free pool
2363
2376
pmemobj_rwlock_wrlock (pop, &(D_RW (buf->free_pool )->lock ));
2364
2377
@@ -2393,6 +2406,9 @@ pm_buf_handle_full_hashed_list(
2393
2406
TOID_ASSIGN ( D_RW (first_list)->next_list , hash_list.oid );
2394
2407
TOID_ASSIGN ( D_RW (hash_list)->prev_list , first_list.oid );
2395
2408
2409
+ #if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
2410
+ printf (" \n (2) end get_free_list %zu to replace full list %zu ==>" , D_RW (first_list)->list_id , phashlist->list_id );
2411
+ #endif
2396
2412
2397
2413
#if defined (UNIV_PMEMOBJ_BUF_STAT)
2398
2414
if ( !TOID_IS_NULL ( D_RW (hash_list)->next_list ))
@@ -2437,7 +2453,8 @@ pm_buf_assign_flusher(
2437
2453
++flusher->n_requested ;
2438
2454
// delay calling flush up to a threshold
2439
2455
// printf("trigger worker...\n");
2440
- if (flusher->n_requested == flusher->size - 2 ) {
2456
+ // if (flusher->n_requested == flusher->size - 2) {
2457
+ if (flusher->n_requested == PMEM_FLUSHER_WAKE_THRESHOLD) {
2441
2458
os_event_set (flusher->is_req_not_empty );
2442
2459
}
2443
2460
@@ -2508,7 +2525,7 @@ pm_filemap_init(
2508
2525
#define PMEM_BUF_BUCKET_STAT_PRINT (pb, index ) do {\
2509
2526
assert (0 <= index && index <= PMEM_N_BUCKETS);\
2510
2527
PMEM_BUCKET_STAT* p = &pb->bucket_stats [index];\
2511
- printf (" bucket %d [n_writes %zu,\t n_overwrites %zu,\t n_reads %zu, n_reads_flushing %zu \t max_linked_lists %zu, \t n_flushed_lists %zu] \n " ,index, p->n_writes , p->n_overwrites , p->n_reads , p->n_reads_flushing , p->max_linked_lists , p->n_flushed_lists ); \
2528
+ printf (" bucket %zu [n_writes %zu,\t n_overwrites %zu,\t n_reads %zu, n_reads_hit %zu, n_reads_flushing %zu \t max_linked_lists %zu, \t n_flushed_lists %zu] \n " ,index, p->n_writes , p->n_overwrites , p->n_reads , p-> n_reads_hit , p->n_reads_flushing , p->max_linked_lists , p->n_flushed_lists ); \
2512
2529
}while (0 )
2513
2530
2514
2531
@@ -2520,7 +2537,7 @@ void pm_buf_bucket_stat_init(PMEM_BUF* pbuf) {
2520
2537
2521
2538
for (i = 0 ; i < PMEM_N_BUCKETS; i++) {
2522
2539
arr[i].n_writes = arr[i].n_overwrites =
2523
- arr[i].n_reads = arr[i].n_reads_flushing = arr[i].max_linked_lists =
2540
+ arr[i].n_reads = arr[i].n_reads_hit = arr[i]. n_reads_flushing = arr[i].max_linked_lists =
2524
2541
arr[i].n_flushed_lists = 0 ;
2525
2542
}
2526
2543
pbuf->bucket_stats = arr;
@@ -2529,10 +2546,35 @@ void pm_buf_bucket_stat_init(PMEM_BUF* pbuf) {
2529
2546
void pm_buf_stat_print_all (PMEM_BUF* pbuf) {
2530
2547
ulint i;
2531
2548
PMEM_BUCKET_STAT* arr = pbuf->bucket_stats ;
2549
+ PMEM_BUCKET_STAT sumstat;
2550
+
2551
+ sumstat.n_writes = sumstat.n_overwrites =
2552
+ sumstat.n_reads = sumstat.n_reads_hit = sumstat.n_reads_flushing = sumstat.max_linked_lists = sumstat.n_flushed_lists = 0 ;
2553
+
2532
2554
2533
2555
for (i = 0 ; i < PMEM_N_BUCKETS; i++) {
2556
+ sumstat.n_writes += arr[i].n_writes ;
2557
+ sumstat.n_overwrites += arr[i].n_overwrites ;
2558
+ sumstat.n_reads += arr[i].n_reads ;
2559
+ sumstat.n_reads_hit += arr[i].n_reads_hit ;
2560
+ sumstat.n_reads_flushing += arr[i].n_reads_flushing ;
2561
+ sumstat.n_flushed_lists += arr[i].n_flushed_lists ;
2562
+
2563
+ if (sumstat.max_linked_lists < arr[i].max_linked_lists ) {
2564
+ sumstat.max_linked_lists = arr[i].max_linked_lists ;
2565
+ }
2566
+
2534
2567
PMEM_BUF_BUCKET_STAT_PRINT (pbuf, i);
2535
2568
}
2569
+
2570
+ printf (" \n ==========\n Statistic info:\n n_writes\t n_overwrites \t n_reads \t n_reads_hit \t n_reads_flushing \t max_linked_lists \t n_flushed_lists \n %zu \t %zu \t %zu \t %zu \t %zu \t %zu \t %zu \n " ,
2571
+ sumstat.n_writes , sumstat.n_overwrites , sumstat.n_reads , sumstat.n_reads_hit , sumstat.n_reads_flushing , sumstat.max_linked_lists , sumstat.n_flushed_lists );
2572
+ printf (" \n ==========\n " );
2573
+
2574
+ fprintf (pbuf->deb_file , " \n ==========\n Statistic info:\n n_writes\t n_overwrites \t n_reads \t n_reads_hit \t n_reads_flushing \t max_linked_lists \t n_flushed_lists \n %zu \t %zu \t %zu \t %zu \t %zu \t %zu \t %zu \n " ,
2575
+ sumstat.n_writes , sumstat.n_overwrites , sumstat.n_reads , sumstat.n_reads_hit , sumstat.n_reads_flushing , sumstat.max_linked_lists , sumstat.n_flushed_lists );
2576
+ fprintf (pbuf->deb_file , " \n ==========\n " );
2577
+
2536
2578
}
2537
2579
2538
2580
#endif // UNIV_PMEMOBJ_STAT
0 commit comments