From: Matthias Gatto <matthias.gatto@outscale.com>
To: dev@dpdk.org
Cc: Matthias Gatto <matthias.gatto@outscale.com>,
yuanhan.liu@linux.intel.com
Subject: [dpdk-dev] [PATCH] vhost: try to shrink pfdset when fdset_add fails
Date: Tue, 21 Feb 2017 15:25:30 +0100 [thread overview]
Message-ID: <20170221142530.31472-1-matthias.gatto@outscale.com> (raw)
fdset_add increment pfdset->num, but fdset_del doesn't decrement pfdset->num,
so if we call fdset_add then fdset_del in a loop witout calling
fdset_shrink, we can easily exceed MAX_FDS with only a few number of fds
used.
So my solution is simply to call fdset_shrink in fdset_add
when it exceed MAX_FDS.
Because fdset_shrink and fdset_add locks pfdset->fd_mutex we can't call
fdset_shrink inside fdset_add because that would cause a dead lock,
so this patch split fdset_shrink in two, fdset_shrink amd fdset_shrink_nolock.
Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com>
---
lib/librte_vhost/fd_man.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
index 8a075da..c7a4490 100644
--- a/lib/librte_vhost/fd_man.c
+++ b/lib/librte_vhost/fd_man.c
@@ -65,17 +65,12 @@ fdset_move(struct fdset *pfdset, int dst, int src)
pfdset->rwfds[dst] = pfdset->rwfds[src];
}
-/*
- * Find deleted fd entries and remove them
- */
static void
-fdset_shrink(struct fdset *pfdset)
+fdset_shrink_nolock(struct fdset *pfdset)
{
int i;
int last_valid_idx = get_last_valid_idx(pfdset, pfdset->num - 1);
- pthread_mutex_lock(&pfdset->fd_mutex);
-
for (i = 0; i < last_valid_idx; i++) {
if (pfdset->fd[i].fd != -1)
continue;
@@ -84,7 +79,16 @@ fdset_shrink(struct fdset *pfdset)
last_valid_idx = get_last_valid_idx(pfdset, last_valid_idx - 1);
}
pfdset->num = last_valid_idx + 1;
+}
+/*
+ * Find deleted fd entries and remove them
+ */
+static void
+fdset_shrink(struct fdset *pfdset)
+{
+ pthread_mutex_lock(&pfdset->fd_mutex);
+ fdset_shrink_nolock(pfdset);
pthread_mutex_unlock(&pfdset->fd_mutex);
}
@@ -151,8 +155,12 @@ fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat)
pthread_mutex_lock(&pfdset->fd_mutex);
i = pfdset->num < MAX_FDS ? pfdset->num++ : -1;
if (i == -1) {
- pthread_mutex_unlock(&pfdset->fd_mutex);
- return -2;
+ fdset_shrink_nolock(pfdset);
+ i = pfdset->num < MAX_FDS ? pfdset->num++ : -1;
+ if (i == -1) {
+ pthread_mutex_unlock(&pfdset->fd_mutex);
+ return -2;
+ }
}
fdset_add_fd(pfdset, i, fd, rcb, wcb, dat);
--
2.10.0
next reply other threads:[~2017-02-21 14:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-21 14:25 Matthias Gatto [this message]
2017-02-22 1:59 ` Yuanhan Liu
2017-02-22 10:01 ` Matthias Gatto
2017-02-23 4:37 ` Yuanhan Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170221142530.31472-1-matthias.gatto@outscale.com \
--to=matthias.gatto@outscale.com \
--cc=dev@dpdk.org \
--cc=yuanhan.liu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).