<div dir="ltr">Reviewed-by: Robin Dong <<a href="mailto:sanbai@taobao.com">sanbai@taobao.com</a>></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014/1/15 Liu Yuan <span dir="ltr"><<a href="mailto:namei.unix@gmail.com" target="_blank">namei.unix@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Allocate the buffer size based on the request length so that small request won't<br>
take too much memory.<br>
<br>
Signed-off-by: Liu Yuan <<a href="mailto:namei.unix@gmail.com">namei.unix@gmail.com</a>><br>
---<br>
sheep/http/kv.c | 12 +++++++-----<br>
1 file changed, 7 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/sheep/http/kv.c b/sheep/http/kv.c<br>
index dd5ca56..95c270d 100644<br>
--- a/sheep/http/kv.c<br>
+++ b/sheep/http/kv.c<br>
@@ -673,7 +673,7 @@ static int vdi_read_write(uint32_t vid, char *data, size_t length,<br>
return local_req_wait(iocb);<br>
}<br>
<br>
-#define READ_WRITE_BUFFER (SD_DATA_OBJ_SIZE * 25) /* no rationale */<br>
+#define MAX_RW_BUFFER (SD_DATA_OBJ_SIZE * 25) /* No rationale yet */<br>
<br>
static int onode_populate_extents(struct kv_onode *onode,<br>
struct http_request *req)<br>
@@ -683,6 +683,7 @@ static int onode_populate_extents(struct kv_onode *onode,<br>
int ret;<br>
char *data_buf = NULL;<br>
uint32_t data_vid = onode->data_vid;<br>
+ uint64_t write_buffer_size = MIN(MAX_RW_BUFFER, req->data_length);<br>
<br>
count = DIV_ROUND_UP(req->data_length, SD_DATA_OBJ_SIZE);<br>
sys->cdrv->lock(data_vid);<br>
@@ -694,11 +695,11 @@ static int onode_populate_extents(struct kv_onode *onode,<br>
goto out;<br>
}<br>
<br>
- data_buf = xmalloc(READ_WRITE_BUFFER);<br>
+ data_buf = xmalloc(write_buffer_size);<br>
offset = start * SD_DATA_OBJ_SIZE;<br>
total = req->data_length;<br>
while (done < total) {<br>
- size = http_request_read(req, data_buf, READ_WRITE_BUFFER);<br>
+ size = http_request_read(req, data_buf, write_buffer_size);<br>
ret = vdi_read_write(data_vid, data_buf, size, offset, false);<br>
if (ret != SD_RES_SUCCESS) {<br>
sd_err("Failed to write data object for %s, %s",<br>
@@ -863,15 +864,16 @@ static int onode_read_extents(struct kv_onode *onode, struct http_request *req)<br>
uint64_t size, total, total_size, offset, done = 0, i;<br>
int ret;<br>
char *data_buf = NULL;<br>
+ uint64_t read_buffer_size = MIN(MAX_RW_BUFFER, onode->size);<br>
<br>
- data_buf = xmalloc(READ_WRITE_BUFFER);<br>
+ data_buf = xmalloc(read_buffer_size);<br>
total_size = onode->size;<br>
for (i = 0; i < onode->nr_extent; i++) {<br>
ext = onode->o_extent + i;<br>
total = min(ext->count * SD_DATA_OBJ_SIZE, total_size);<br>
offset = ext->start * SD_DATA_OBJ_SIZE;<br>
while (done < total) {<br>
- size = MIN(total - done, READ_WRITE_BUFFER);<br>
+ size = MIN(total - done, read_buffer_size);<br>
ret = vdi_read_write(onode->data_vid, data_buf,<br>
size, offset, true);<br>
if (ret != SD_RES_SUCCESS) {<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.2<br>
<br>
--<br>
sheepdog mailing list<br>
<a href="mailto:sheepdog@lists.wpkg.org">sheepdog@lists.wpkg.org</a><br>
<a href="http://lists.wpkg.org/mailman/listinfo/sheepdog" target="_blank">http://lists.wpkg.org/mailman/listinfo/sheepdog</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>--<br>Best Regard<br>Robin Dong
</div>