Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: Refactor the structure of additional item in mblck #756

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions mc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void do_mblck_pool_init(mblck_pool_t *pool, uint32_t blck_len)
pool->tail = NULL;
pool->head = NULL;
pool->blck_len = blck_len;
pool->body_len = blck_len - sizeof(void *);
pool->body_len = blck_len - (sizeof(void *) + sizeof(uint32_t));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(void *)์™€ sizeof(uint32_t)๋Š” ๊ฐ๊ฐ ์–ด๋–ค ๊ฐ’์˜ ํฌ๊ธฐ์ธ๊ฐ€์š”?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old

| <----- blck_len -----> |
        | <- body_len -> |
--------------------------
| *next |      data      |

new

| <-------- blck_len --------> |
        | <--- value_item ---> |
              | <- body_len -> |
--------------------------
| *next | len |       ptr      |
  • value_item.len๊ณผ pool->body_len์€ ๊ฒฐ๊ตญ์—๋Š” ๊ฐ™์€ ๊ฐ’์„ ๊ฐ–๊ฒŒ ๋œ๋‹ค๊ณ  ํ•จ

pool->used_cnt = 0;
pool->free_cnt = 0;
}
Expand Down Expand Up @@ -107,16 +107,29 @@ int mblck_list_alloc(mblck_pool_t *pool, uint32_t item_len, uint32_t item_cnt,
}
assert(pool->free_cnt >= blck_cnt);

if (blck_cnt > 1) {
list->addnl = (value_item **)malloc(sizeof(value_item *) * (blck_cnt - 1));
if (list->addnl == NULL) {
return -1;
}
} else {
list->addnl = NULL;
}

uint32_t cnt = 0;
list->pool = (void*)pool;
list->head = pool->head;
list->tail = list->head;
list->blck_cnt = 1;
while (list->blck_cnt < blck_cnt) {
while (list->blck_cnt + cnt < blck_cnt) {
list->tail = list->tail->next;
list->blck_cnt += 1;
list->addnl[cnt] = &list->tail->data;
list->addnl[cnt]->len = nitems_per_blck * item_len;
cnt += 1;
}
pool->head = list->tail->next;
list->tail->next = NULL;
list->blck_cnt += cnt;

if (pool->head == NULL) {
pool->tail = NULL;
Expand All @@ -141,7 +154,11 @@ void mblck_list_merge(mblck_list_t *pri_list, mblck_list_t *add_list)
add_list->head = NULL;
add_list->tail = NULL;
add_list->blck_cnt = 0;
/* FIXME: item_cnt and item_len: how to merge them ? */
if (add_list->addnl != NULL) {
free(add_list->addnl);
add_list->addnl = NULL;
}
/* FIXME: item_cnt, item_len and addnl: how to merge them ? */
}

void mblck_list_free(mblck_pool_t *pool, mblck_list_t *list)
Expand All @@ -160,6 +177,10 @@ void mblck_list_free(mblck_pool_t *pool, mblck_list_t *list)
list->head = NULL;
list->tail = NULL;
list->blck_cnt = 0;
if (list->addnl != NULL) {
free(list->addnl);
list->addnl = NULL;
}
}
list->pool = NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions mc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ typedef struct _token_buff {
*/
typedef struct _mblck_node {
struct _mblck_node *next;
char data[1];
value_item data;
} mblck_node_t;

typedef struct _mblck_list {
void *pool;
mblck_node_t *head;
mblck_node_t *tail;
value_item **addnl;
Comment on lines 45 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • head์˜ next๋ฅผ ํ†ตํ•ด ์ „์ฒด item์— ์ ‘๊ทผ ๊ฐ€๋Šฅํ•  ๊ฒƒ์ธ๋ฐ, addnl์„ ๋‘๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?
  • value_item array๋ฅผ ๋‘”๋‹ค๋ฉด, tail ๋“ฑ ๋งํฌ๋“œ๋ฆฌ์ŠคํŠธ ๊ด€๋ จ field๋ฅผ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹Œ์ง€?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. addnl์€ ritem read ์‹œ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ์ถ”๊ฐ€ํ•œ ๊ฒƒ (HINFO, EINFO์™€ ์œ ์‚ฌํ•œ ๊ตฌ์กฐ๋ฅผ ๊ฐ–๋„๋ก)
  2. mblck์€ ritem read ์™ธ์—๋„ ํ™œ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๋ฐ (tokenize_XXX()), ์ด ๋•Œ list ๋ฐฉ์‹์˜ ๊ตฌํ˜„์ด ํ•„์š”ํ•˜๋‹ค๊ณ  ํ•จ
  3. ๋”ฐ๋ผ์„œ PR ๊ตฌํ˜„์—์„œ๋Š” ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ array ๋ฐฉ์‹์œผ๋กœ๋„ ์ ‘๊ทผ(ritem_set_XXX())ํ•  ์ˆ˜ ์žˆ๊ณ ,
    ๊ธฐ์กด list ๋ฐฉ์‹์œผ๋กœ๋„ ์ ‘๊ทผ(tokenize_XXX())ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌํ˜„ํ•œ ์ƒํƒœ

uint32_t blck_cnt;
uint32_t body_len;
uint32_t item_cnt;
Expand All @@ -68,8 +69,9 @@ typedef struct _mblck_pool {
#define MBLCK_GET_BODYLEN(l) ((l)->body_len)
#define MBLCK_GET_ITEMCNT(l) ((l)->item_cnt)
#define MBLCK_GET_ITEMLEN(l) ((l)->item_len)
#define MBLCK_GET_ADDLIST(l) ((l)->addnl)
#define MBLCK_GET_NEXTBLK(b) ((b)->next)
#define MBLCK_GET_BODYPTR(b) ((b)->data)
#define MBLCK_GET_BODYPTR(b) ((b)->data.ptr)

/* memory block functions */
int mblck_pool_create(mblck_pool_t *pool, uint32_t blck_len, uint32_t blck_cnt);
Expand Down
34 changes: 16 additions & 18 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,11 @@ static void ritem_set_first(conn *c, int rtype, int vleng)
c->rtype = rtype;

if (c->rtype == CONN_RTYPE_MBLCK) {
c->membk = MBLCK_GET_HEADBLK(&c->memblist);
c->ritem = MBLCK_GET_BODYPTR(c->membk);
c->ritem = MBLCK_GET_BODYPTR(MBLCK_GET_HEADBLK(&c->memblist));
c->rlbytes = vleng < MBLCK_GET_BODYLEN(&c->memblist)
? vleng : MBLCK_GET_BODYLEN(&c->memblist);
c->rltotal = vleng;
c->rindex = 0;
}
else if (c->rtype == CONN_RTYPE_HINFO) {
if (c->hinfo.naddnl == 0) {
Expand Down Expand Up @@ -1069,24 +1069,22 @@ static void ritem_set_next(conn *c)
{
assert(c->rltotal > 0);

value_item *ritem = NULL;

if (c->rtype == CONN_RTYPE_MBLCK) {
c->membk = MBLCK_GET_NEXTBLK(c->membk);
c->ritem = MBLCK_GET_BODYPTR(c->membk);
c->rlbytes = c->rltotal < MBLCK_GET_BODYLEN(&c->memblist)
? c->rltotal : MBLCK_GET_BODYLEN(&c->memblist);
}
else if (c->rtype == CONN_RTYPE_HINFO) {
c->ritem = c->hinfo.addnl[c->rindex]->ptr;
c->rlbytes = c->rltotal < c->hinfo.addnl[c->rindex]->len
? c->rltotal : c->hinfo.addnl[c->rindex]->len;
c->rindex += 1;
}
else if (c->rtype == CONN_RTYPE_EINFO) {
c->ritem = c->einfo.addnl[c->rindex]->ptr;
c->rlbytes = c->rltotal < c->einfo.addnl[c->rindex]->len
? c->rltotal : c->einfo.addnl[c->rindex]->len;
c->rindex += 1;
ritem = MBLCK_GET_ADDLIST(&c->memblist)[c->rindex];
} else if (c->rtype == CONN_RTYPE_HINFO) {
ritem = c->hinfo.addnl[c->rindex];
} else if (c->rtype == CONN_RTYPE_EINFO) {
ritem = c->einfo.addnl[c->rindex];
} else {
/* Invalid rtype */
return;
}

c->ritem = ritem->ptr;
c->rlbytes = c->rltotal < ritem->len ? c->rltotal : ritem->len;
c->rindex += 1;
}

/**
Expand Down
1 change: 0 additions & 1 deletion memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ struct conn {
uint32_t rlbytes;
/* use memory blocks */
uint32_t rltotal; /* Used when read data with memory block */
mblck_node_t *membk; /* current memory block pointer */
mblck_list_t memblist; /* (key or field) string memory block list */

/* hash item and elem item info */
Expand Down
Loading