Skip to content

Commit 716e1a5

Browse files
committed
implement __trim_save_address() function
1 parent b65867d commit 716e1a5

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

src/third_party/wiredtiger/src/reconcile/rec_write.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88

99
#include "wt_internal.h"
1010

11+
#if defined(TDN_TRIM4) || defined(TDN_TRIM5)
12+
13+
#include "mytrim.h"
14+
#include <sys/ioctl.h> //for ioctl call
15+
#include <linux/fs.h> //for fstrim_range
16+
#include <string.h>
17+
#include <errno.h>
18+
19+
extern TRIM_MAP* trimmap;
20+
extern FILE* my_fp4;
21+
extern int32_t my_off_size; //size
22+
extern size_t my_trim_freq_config; //how often trim will call
23+
24+
extern pthread_t trim_tid;
25+
extern pthread_mutex_t trim_mutex;
26+
extern pthread_cond_t trim_cond;
27+
#endif //TDN_TRIM4
28+
1129
struct __rec_boundary; typedef struct __rec_boundary WT_BOUNDARY;
1230
struct __rec_dictionary; typedef struct __rec_dictionary WT_DICTIONARY;
1331
struct __rec_kv; typedef struct __rec_kv WT_KV;
@@ -288,6 +306,10 @@ typedef struct {
288306
uint32_t tested_ref_state; /* Debugging information */
289307
} WT_RECONCILE;
290308

309+
#if defined(TDN_TRIM5)
310+
static void __trim_save_address(WT_BM* , uint8_t* );
311+
#endif
312+
291313
static void __rec_bnd_cleanup(WT_SESSION_IMPL *, WT_RECONCILE *, bool);
292314
static void __rec_cell_build_addr(WT_SESSION_IMPL *,
293315
WT_RECONCILE *, const void *, size_t, u_int, uint64_t);
@@ -5270,6 +5292,14 @@ __rec_split_discard(WT_SESSION_IMPL *session, WT_PAGE *page)
52705292
WT_PAGE_MODIFY *mod;
52715293
WT_MULTI *multi;
52725294
uint32_t i;
5295+
#if defined(TDN_TRIM5)
5296+
5297+
WT_BM *bm;
5298+
WT_BTREE *btree;
5299+
5300+
btree = S2BT(session);
5301+
bm = btree->bm;
5302+
#endif
52735303

52745304
mod = page->modify;
52755305

@@ -5290,6 +5320,10 @@ __rec_split_discard(WT_SESSION_IMPL *session, WT_PAGE *page)
52905320
if (multi->addr.reuse)
52915321
multi->addr.addr = NULL;
52925322
else {
5323+
#if defined(TDN_TRIM5)
5324+
//save old address and trigger TRIM thread
5325+
__trim_save_address(bm, multi->addr.addr);
5326+
#endif
52935327
WT_RET(__wt_btree_block_free(session,
52945328
multi->addr.addr, multi->addr.size));
52955329
__wt_free(session, multi->addr.addr);
@@ -5360,6 +5394,58 @@ __rec_split_dump_keys(WT_SESSION_IMPL *session, WT_PAGE *page, WT_RECONCILE *r)
53605394
err: __wt_scr_free(session, &tkey);
53615395
return (ret);
53625396
}
5397+
#if defined(TDN_TRIM5)
5398+
/*
5399+
*tdnguyen
5400+
Save old address (begin offset, end offset) in trimmap struct
5401+
Trigger TRIM commnad if the number of saved address of one file > a threashold
5402+
* */
5403+
static void __trim_save_address(WT_BM* bm, uint8_t* addr){
5404+
5405+
TRIM_OBJ* obj;
5406+
wt_off_t tem_offset1;
5407+
uint32_t tem_size1, tem_cksum1;
5408+
5409+
uint32_t retsize;
5410+
int tem_ret;
5411+
int index, fdtem;
5412+
5413+
//if the nunber of saved offset still less than a threadhold
5414+
if(trimmap->oid == TRIM_INDEX_NOT_SET){
5415+
//convert from addr to (offset, size) pair
5416+
__wt_block_buffer_to_addr(bm->block, addr,
5417+
&tem_offset1, &tem_size1, &tem_cksum1);
5418+
//save the range
5419+
fdtem = bm->block->fh->fd;
5420+
index = trimmap_find(trimmap, fdtem);
5421+
if (index >= 0){
5422+
obj = trimmap->data[index];
5423+
retsize = trimobj_add_range(obj, tem_offset1, tem_offset1 + tem_size1);
5424+
//check for oversize
5425+
if (retsize >= (obj->max_size - 10)){
5426+
// triger trim thread
5427+
printf("===>begin trigger TRIM command thread, retsize=%d, index=%d, max_size=%d, count=%d\n",
5428+
retsize, index, obj->max_size, obj->count);
5429+
fprintf(my_fp4, "===>begin trigger TRIM command thread, retsize=%d, index=%d, max_size=%d, count=%d\n",
5430+
retsize, index, obj->max_size, obj->count);
5431+
trimmap->oid = index;
5432+
tem_ret = pthread_mutex_trylock(&trim_mutex);
5433+
if(tem_ret == 0){
5434+
pthread_cond_signal(&trim_cond);
5435+
pthread_mutex_unlock(&trim_mutex);
5436+
}
5437+
else {
5438+
//Trim thread is signaled previously, just skip
5439+
}
5440+
}
5441+
}
5442+
else {
5443+
//add new object
5444+
trimmap_add(trimmap, fdtem, my_trim_freq_config);
5445+
}
5446+
}// end if(trimmap->oid == TRIM_INDEX_NOT_SET
5447+
}
5448+
#endif //defined (TDN_TRIM5)
53635449

53645450
/*
53655451
* __rec_write_wrapup --

0 commit comments

Comments
 (0)