summaryrefslogtreecommitdiff
path: root/vtysh
diff options
context:
space:
mode:
authorSrujana <skanchisamud@nvidia.com>2024-07-30 20:39:33 +0000
committerRajasekar Raja <rajasekarr@nvidia.com>2024-08-27 12:47:00 -0700
commit9112fb367b1ae0168b4e7a81f41c2ca621979199 (patch)
tree134a10f33a7069ca9025cf2f46726ff3bd227559 /vtysh
parentfa7c77f2939b4be9649ee95a78ed3a307aeac342 (diff)
lib: Memory spike reduction for sh cmds at scale
The output buffer vty->obuf is a linked list where each element is of 4KB. Currently, when a huge sh command like <show ip route json> is executed on a large scale, all the vty_outs are processed and the entire data is accumulated. After the entire vty execution, vtysh_flush proceeses and puts this data in the socket (131KB at a time). Problem here is the memory spike for such heavy duty show commands. The fix here is to chunkify the output on VTY shell by flushing it intermediately for every 128 KB of output accumulated and free the memory allocated for the buffer data. This way, we achieve ~25-30% reduction in the memory spike. Fixes: #16498 Note: This is a continuation of MR #16498 Signed-off-by: Srujana <skanchisamud@nvidia.com> Signed-off-by: Rajasekar Raja <rajasekarr@nvidia.com>
Diffstat (limited to 'vtysh')
-rw-r--r--vtysh/vtysh.c17
-rw-r--r--vtysh/vtysh.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index c43e1909e3..2d80feef6c 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -4639,6 +4639,7 @@ static int vtysh_connect(struct vtysh_client *vclient)
struct sockaddr_un addr;
struct stat s_stat;
const char *path;
+ uint32_t rcvbufsize = VTYSH_RCV_BUF_MAX;
if (!vclient->path[0])
snprintf(vclient->path, sizeof(vclient->path), "%s/%s.vty",
@@ -4688,6 +4689,22 @@ static int vtysh_connect(struct vtysh_client *vclient)
close(sock);
return -1;
}
+
+ /*
+ * Increasing the RECEIVE socket buffer size so that the socket can hold
+ * after receving from other process.
+ */
+ ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&rcvbufsize,
+ sizeof(rcvbufsize));
+ if (ret < 0) {
+#ifdef DEBUG
+ fprintf(stderr, "Cannot set socket %d rcv buffer size, %s\n",
+ sock, safe_strerror(errno));
+#endif /* DEBUG */
+ close(sock);
+ return -1;
+ }
+
vclient->fd = sock;
return 0;
diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h
index b1d57aa3c2..3c532b99a8 100644
--- a/vtysh/vtysh.h
+++ b/vtysh/vtysh.h
@@ -36,6 +36,8 @@ extern struct event_loop *master;
#define VTYSH_PIM6D 0x100000
#define VTYSH_MGMTD 0x200000
+#define VTYSH_RCV_BUF_MAX 16777216
+
#define VTYSH_WAS_ACTIVE (-2)
/* commands in REALLYALL are crucial to correct vtysh operation */