| 1 | #include "fio.h" |
| 2 | |
| 3 | int init_dedupe_working_set_seeds(struct thread_data *td) |
| 4 | { |
| 5 | unsigned long long i, j, num_seed_advancements; |
| 6 | struct frand_state dedupe_working_set_state = {0}; |
| 7 | |
| 8 | if (!td->o.dedupe_percentage || !(td->o.dedupe_mode == DEDUPE_MODE_WORKING_SET)) |
| 9 | return 0; |
| 10 | |
| 11 | num_seed_advancements = td->o.min_bs[DDIR_WRITE] / |
| 12 | min_not_zero(td->o.min_bs[DDIR_WRITE], (unsigned long long) td->o.compress_chunk); |
| 13 | /* |
| 14 | * The dedupe working set keeps seeds of unique data (generated by buf_state). |
| 15 | * Dedupe-ed pages will be generated using those seeds. |
| 16 | */ |
| 17 | td->num_unique_pages = (td->o.size * (unsigned long long)td->o.dedupe_working_set_percentage / 100) / td->o.min_bs[DDIR_WRITE]; |
| 18 | td->dedupe_working_set_states = malloc(sizeof(struct frand_state) * td->num_unique_pages); |
| 19 | if (!td->dedupe_working_set_states) { |
| 20 | log_err("fio: could not allocate dedupe working set\n"); |
| 21 | return 1; |
| 22 | } |
| 23 | frand_copy(&dedupe_working_set_state, &td->buf_state); |
| 24 | for (i = 0; i < td->num_unique_pages; i++) { |
| 25 | frand_copy(&td->dedupe_working_set_states[i], &dedupe_working_set_state); |
| 26 | /* |
| 27 | * When compression is used the seed is advanced multiple times to |
| 28 | * generate the buffer. We want to regenerate the same buffer when |
| 29 | * deduping against this page |
| 30 | */ |
| 31 | for (j = 0; j < num_seed_advancements; j++) |
| 32 | __get_next_seed(&dedupe_working_set_state); |
| 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |