From a7c6ddcea3da98bbb21fbdb97e5a7892a68a9ac7 Mon Sep 17 00:00:00 2001 From: jschmieg Date: Mon, 6 Jul 2020 11:54:41 +0200 Subject: [PATCH 1/2] SdsMakeRoom always in DRAM Introduces 2 variants for SdsMakeRoom funtion: on DRAM and General Can be used in networking.c --- src/sds.c | 14 ++++++++++++-- src/sds.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sds.c b/src/sds.c index d7c657268f1..458e8d76b58 100644 --- a/src/sds.c +++ b/src/sds.c @@ -219,7 +219,7 @@ void sdsclear(sds s) { * * Note: this does not change the *length* of the sds string as returned * by sdslen(), but only the free buffer space we have. */ -sds sdsMakeRoomFor(sds s, size_t addlen) { +static sds _sdsMakeRoomFor(sds s, size_t addlen, int on_dram) { void *sh, *newsh; size_t avail = sdsavail(s); size_t len, newlen; @@ -252,7 +252,8 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { } else { /* Since the header size changes, need to move the string forward, * and can't use realloc */ - newsh = s_malloc(hdrlen+newlen+1); + newsh = (on_dram == SDS_DRAM_VARIANT) ? s_dram_malloc(hdrlen+newlen+1) + : s_malloc(hdrlen+newlen+1); if (newsh == NULL) return NULL; memcpy((char*)newsh+hdrlen, s, len+1); s_free(sh); @@ -264,6 +265,15 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { return s; } +sds sdsMakeRoomFor(sds s, size_t addlen) { + return _sdsMakeRoomFor(s, addlen, SDS_GENERAL_VARIANT); +} + +sds sdsDramMakeRoomFor(sds s, size_t addlen) { + return _sdsMakeRoomFor(s, addlen, SDS_DRAM_VARIANT); +} + + /* Reallocate the sds string so that it has no free space at the end. The * contained string remains not altered, but next concatenation operations * will require a reallocation. diff --git a/src/sds.h b/src/sds.h index 5bdeedad78c..dd523f0777e 100644 --- a/src/sds.h +++ b/src/sds.h @@ -255,6 +255,7 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen); /* Low level functions exposed to the user API */ sds sdsMakeRoomFor(sds s, size_t addlen); +sds sdsDramMakeRoomFor(sds s, size_t addlen); void sdsIncrLen(sds s, ssize_t incr); sds sdsRemoveFreeSpace(sds s); size_t sdsAllocSize(sds s); From 83ce51ac13827e4a7093229c538719a0075f6cef Mon Sep 17 00:00:00 2001 From: jschmieg Date: Mon, 6 Jul 2020 11:59:32 +0200 Subject: [PATCH 2/2] Allocate queryBuff from DRAM (additional path) --- src/networking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/networking.c b/src/networking.c index 41c98cb4a4e..bdff45cdf66 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1825,7 +1825,7 @@ void readQueryFromClient(connection *conn) { qblen = sdslen(c->querybuf); if (c->querybuf_peak < qblen) c->querybuf_peak = qblen; - c->querybuf = sdsMakeRoomFor(c->querybuf, readlen); + c->querybuf = sdsDramMakeRoomFor(c->querybuf, readlen); nread = connRead(c->conn, c->querybuf+qblen, readlen); if (nread == -1) { if (connGetState(conn) == CONN_STATE_CONNECTED) {