Skip to content

Commit 1fbd5a5

Browse files
committed
fix bugs, modify printf for statistic information
1 parent 672ada5 commit 1fbd5a5

File tree

7 files changed

+65
-10
lines changed

7 files changed

+65
-10
lines changed

storage/innobase/buf/buf0flu.cc

+15-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Created 11/11/1995 Heikki Tuuri
6161
static const int buf_flush_page_cleaner_priority = -20;
6262
#endif /* UNIV_LINUX */
6363

64+
#if defined(UNIV_TRACE_FLUSH_TIME)
65+
extern ulint gb_flush_time;
66+
#endif
6467
#if defined(UNIV_PMEMOBJ_BUF)
6568
#include "my_pmemobj.h"
6669
#include <libpmemobj.h>
@@ -1187,6 +1190,12 @@ buf_flush_page(
11871190

11881191
bool is_uncompressed;
11891192

1193+
#if defined(UNIV_TRACE_FLUSH_TIME)
1194+
ulint start_time;
1195+
ulint end_time;
1196+
1197+
start_time = ut_time_ms();
1198+
#endif
11901199
is_uncompressed = (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
11911200
ut_ad(is_uncompressed == (block_mutex != &buf_pool->zip_mutex));
11921201

@@ -1278,6 +1287,11 @@ buf_flush_page(
12781287
//printf(" END buf_flush_write_block_low ] ");
12791288
}
12801289

1290+
#if defined(UNIV_TRACE_FLUSH_TIME)
1291+
end_time = ut_time_ms();
1292+
gb_flush_time += (end_time - start_time);
1293+
#endif
1294+
12811295
return(flush);
12821296
}
12831297

@@ -4109,7 +4123,7 @@ DECLARE_THREAD(pm_flusher_worker)(
41094123

41104124
mutex_enter(&flusher->mutex);
41114125
flusher->n_workers--;
4112-
printf("close a worker, current open workers %zu, n_requested/size = %zu/%zu/%zu is_running = %d\n", flusher->n_workers, flusher->n_requested, flusher->size, flusher->is_running);
4126+
//printf("close a worker, current open workers %zu, n_requested/size = %zu/%zu/%zu is_running = %d\n", flusher->n_workers, flusher->n_requested, flusher->size, flusher->is_running);
41134127
if (flusher->n_workers == 0) {
41144128
printf("The last worker is closing\n");
41154129
//os_event_set(flusher->is_all_closed);

storage/innobase/handler/ha_innodb.cc

+9
Original file line numberDiff line numberDiff line change
@@ -3732,6 +3732,9 @@ innobase_init(
37323732
if (!srv_pmem_n_flush_threads) {
37333733
srv_pmem_n_flush_threads = 8;
37343734
}
3735+
if (!srv_pmem_flush_threshold) {
3736+
srv_pmem_flush_threshold = srv_pmem_n_flush_threads - 2;
3737+
}
37353738
#endif
37363739
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
37373740
if (!srv_pmem_n_space_bits) {
@@ -19510,6 +19513,11 @@ static MYSQL_SYSVAR_ULONG(pmem_n_flush_threads, srv_pmem_n_flush_threads,
1951019513
"Number of threads in flusher, from 1 to 64, default is 8.",
1951119514
NULL, NULL, 8, 1, 64, 0);
1951219515

19516+
static MYSQL_SYSVAR_ULONG(pmem_flush_threshold, srv_pmem_flush_threshold,
19517+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
19518+
"If the pointer assign in thread flusher larger than this threshold. The batch flush is trigger, from 1 to 64, default is number of flusher threads - 2.",
19519+
NULL, NULL, 6, 1, 64, 0);
19520+
1951319521
#endif
1951419522

1951519523
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
@@ -20359,6 +20367,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
2035920367
#endif
2036020368
#if defined (UNIV_PMEMOBJ_BUF_FLUSHER)
2036120369
MYSQL_SYSVAR(pmem_n_flush_threads),
20370+
MYSQL_SYSVAR(pmem_flush_threshold),
2036220371
#endif
2036320372
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
2036420373
MYSQL_SYSVAR(pmem_n_space_bits),

storage/innobase/include/my_pmemobj.h

+3
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,15 @@ hash_f1(
643643
@S [in]: number of bits present space_no
644644
@P [in]: number of bits present max number of pages per space on a bucket, this value is log2(page_per_bucket)
645645
* */
646+
//Use this funciton for DEBUG only
646647
//#define PMEM_LESS_BUCKET_HASH_KEY(hashed, space, page)\
647648
// hash_f1(hashed, space, page,\
648649
// PMEM_N_BUCKETS,\
649650
// PMEM_N_BUCKET_BITS,\
650651
// PMEM_N_SPACE_BITS,\
651652
// PMEM_PAGE_PER_BUCKET_BITS)
653+
654+
//Use this macro for production build
652655
#define PMEM_LESS_BUCKET_HASH_KEY(hashed, space, page)\
653656
PARTITION_FUNC1(hashed, space, page,\
654657
PMEM_N_BUCKETS,\

storage/innobase/include/srv0srv.h

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ extern ulong srv_pmem_buf_bucket_size;
276276
#endif
277277
#if defined(UNIV_PMEMOBJ_BUF_FLUSHER)
278278
extern ulong srv_pmem_n_flush_threads;
279+
extern ulong srv_pmem_flush_threshold;
279280
#endif
280281
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
281282
extern ulong srv_pmem_n_space_bits;

storage/innobase/pmem/pmem0buf.cc

+22-7
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ static uint64_t PMEM_N_FLUSH_THREADS;
3232
//set this to large number to eliminate
3333
//static uint64_t PMEM_PAGE_PER_BUCKET_BITS=32;
3434

35+
// 1 < this_value < flusher->size (32)
36+
//static uint64_t PMEM_FLUSHER_WAKE_THRESHOLD=5;
37+
static uint64_t PMEM_FLUSHER_WAKE_THRESHOLD=30;
38+
39+
static FILE* debug_file = fopen("part_debug.txt","a");
40+
3541
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
3642
//256 buckets => 8 bits, max 32 spaces => 5 bits => need 3 = 8 - 5 bits
3743
static uint64_t PMEM_N_BUCKET_BITS = 8;
3844
static uint64_t PMEM_N_SPACE_BITS = 5;
3945
static uint64_t PMEM_PAGE_PER_BUCKET_BITS=10;
40-
// 1 < this_value < flusher->size
41-
//static uint64_t PMEM_FLUSHER_WAKE_THRESHOLD=5;
42-
static uint64_t PMEM_FLUSHER_WAKE_THRESHOLD=2;
4346

44-
static FILE* debug_file = fopen("part_debug.txt","w");
4547

4648
/*
4749
* This is the "clear" version of hash function, use it for debugging
@@ -111,6 +113,7 @@ pm_wrapper_buf_alloc_or_open(
111113
PMEM_BUF_FLUSH_PCT = srv_pmem_buf_flush_pct;
112114
#if defined (UNIV_PMEMOBJ_BUF_FLUSHER)
113115
PMEM_N_FLUSH_THREADS= srv_pmem_n_flush_threads;
116+
PMEM_FLUSHER_WAKE_THRESHOLD = srv_pmem_flush_threshold;
114117
#endif
115118

116119
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
@@ -200,7 +203,7 @@ pm_wrapper_buf_alloc_or_open(
200203
pmw->pbuf->cur_free_param = 0; //start with the 0
201204

202205
//Open file
203-
pmw->pbuf->deb_file = fopen("pmem_debug.txt","w");
206+
pmw->pbuf->deb_file = fopen("pmem_debug.txt","a");
204207

205208
// ////test for recovery
206209
// printf("========== > Test for recovery\n");
@@ -2310,7 +2313,7 @@ pm_buf_resume_flushing(
23102313

23112314
for (i = 0; i < PMEM_N_BUCKETS; i++) {
23122315
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
2313-
printf ("\n====>resuming flush hash %zu\n", i);
2316+
//printf ("\n====>resuming flush hash %zu\n", i);
23142317
#endif
23152318
TOID_ASSIGN(cur_list, (D_RW(buf->buckets)[i]).oid);
23162319
phashlist = D_RW(cur_list);
@@ -2471,7 +2474,12 @@ pm_buf_assign_flusher(
24712474
//delay calling flush up to a threshold
24722475
//printf("trigger worker...\n");
24732476
//if (flusher->n_requested == flusher->size - 2) {
2474-
if (flusher->n_requested == PMEM_FLUSHER_WAKE_THRESHOLD) {
2477+
//if (flusher->n_requested == PMEM_FLUSHER_WAKE_THRESHOLD) {
2478+
if (flusher->n_requested >= PMEM_FLUSHER_WAKE_THRESHOLD) {
2479+
#if defined (UNIV_PMEMOBJ_BUF_RECOVERY_DEBUG)
2480+
printf("\n in [1.1] try to trigger flusher list_id = %zu\n", phashlist->list_id);
2481+
#endif
2482+
24752483
os_event_set(flusher->is_req_not_empty);
24762484
}
24772485

@@ -2560,6 +2568,9 @@ void pm_buf_bucket_stat_init(PMEM_BUF* pbuf) {
25602568
pbuf->bucket_stats = arr;
25612569
}
25622570

2571+
/*
2572+
*Print statistic infomation for all hashed lists
2573+
* */
25632574
void pm_buf_stat_print_all(PMEM_BUF* pbuf) {
25642575
ulint i;
25652576
PMEM_BUCKET_STAT* arr = pbuf->bucket_stats;
@@ -2592,6 +2603,10 @@ void pm_buf_stat_print_all(PMEM_BUF* pbuf) {
25922603
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);
25932604
fprintf(pbuf->deb_file, "\n==========\n");
25942605

2606+
fprintf(debug_file, "\n==========\n Statistic info:\n n_writes n_overwrites n_reads n_reads_hit n_reads_flushing max_linked_lists n_flushed_lists \n %zu %zu %zu %zu %zu %zu %zu \n",
2607+
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);
2608+
fprintf(pbuf->deb_file, "\n==========\n");
2609+
25952610
}
25962611

25972612
#endif //UNIV_PMEMOBJ_STAT

storage/innobase/srv/srv0srv.cc

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ ulong srv_pmem_buf_bucket_size = 256;
209209
#endif
210210
#if defined(UNIV_PMEMOBJ_BUF_FLUSHER)
211211
ulong srv_pmem_n_flush_threads = 8;
212+
ulong srv_pmem_flush_threshold = 6;
212213
#endif
213214
#if defined (UNIV_PMEMOBJ_BUF_PARTITION)
214215
ulong srv_pmem_n_space_bits = 5;

storage/innobase/srv/srv0start.cc

+14-2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ enum srv_shutdown_t srv_shutdown_state = SRV_SHUTDOWN_NONE;
172172

173173
/** Files comprising the system tablespace */
174174
static pfs_os_file_t files[1000];
175+
176+
#if defined (UNIV_TRACE_FLUSH_TIME)
177+
ulint gb_flush_time = 0;
178+
FILE* gb_trace_file = fopen("trace_flush.txt","a");
179+
#endif
175180
#ifdef UNIV_NVM_LOG
176181
//tdnguyen
177182
/** global PMEM_FILE_COLL object*/
@@ -1775,6 +1780,7 @@ innobase_start_or_create_for_mysql(void)
17751780
"; n_buckets=" << srv_pmem_buf_n_buckets <<
17761781
#ifdef UNIV_PMEMOBJ_BUF_FLUSHER
17771782
"; n_flush_threads=" << srv_pmem_n_flush_threads <<
1783+
"; flush_threshold=" << srv_pmem_flush_threshold <<
17781784
#endif
17791785
"; n_slots_per_seg=" << srv_aio_n_slots_per_seg <<
17801786
"; flush_pct=" << srv_pmem_buf_flush_pct <<
@@ -1972,8 +1978,9 @@ innobase_start_or_create_for_mysql(void)
19721978
os_thread_create(pm_buf_flush_list_cleaner_coordinator, NULL, NULL);
19731979
#if defined (UNIV_PMEMOBJ_BUF_FLUSHER)
19741980
//os_thread_create(pm_flusher_coordinator, NULL, NULL);
1975-
//printf("PMEM_INFO: ========> create %d worker threads for pm\n", PMEM_N_BUCKETS);
1976-
for (i = 1; i < srv_n_page_cleaners; ++i) {
1981+
printf("PMEM_INFO: ========> create %d worker threads for pm\n", srv_pmem_n_flush_threads);
1982+
//for (i = 1; i < srv_n_page_cleaners; ++i) {
1983+
for (i = 0; i < srv_pmem_n_flush_threads; ++i) {
19771984
os_thread_create(pm_flusher_worker, NULL, NULL);
19781985
}
19791986
#endif
@@ -2861,6 +2868,11 @@ innobase_shutdown_for_mysql(void)
28612868
#endif
28622869
pm_wrapper_free(gb_pmw);
28632870
#endif
2871+
#if defined (UNIV_TRACE_FLUSH_TIME)
2872+
printf("=== > TRACE FLUSH TIME: total flush time (ms) = %zu\n ", gb_flush_time);
2873+
fprintf(gb_trace_file, "\n===>TRACE_FLUSH_TIME: total flush time (ms) = %zu", gb_flush_time);
2874+
fclose(gb_trace_file);
2875+
#endif
28642876

28652877
/* 2. Make all threads created by InnoDB to exit */
28662878
srv_shutdown_all_bg_threads();

0 commit comments

Comments
 (0)