From 84b4f9d5b5c5228a28dd9dda821e7b45e4dfc693 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Tue, 29 May 2007 13:34:15 +0000 Subject: lib: don't create new thread for each FORGET request... --- ChangeLog | 6 ++++++ lib/fuse_loop_mt.c | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4415a33..9879cb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-05-25 Miklos Szeredi + + * lib: don't create new thread for each FORGET request. FORGET + messages sometimes caused so many threads to be created, that + process virtual memory space ran out. Reported by Chris AtLee + 2007-05-24 Miklos Szeredi * lib: fix memory leak on thread creation failure in multithreaded diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index e9e04b3..7bcc1c2 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -8,6 +8,7 @@ #include "fuse_lowlevel.h" #include "fuse_misc.h" +#include "fuse_kernel.h" #include #include @@ -64,6 +65,7 @@ static void *fuse_do_work(void *data) struct fuse_mt *mt = w->mt; while (!fuse_session_exited(mt->se)) { + int isforget = 0; struct fuse_chan *ch = mt->prevch; int res = fuse_chan_recv(&ch, w->buf, w->bufsize); if (res == -EINTR) @@ -81,7 +83,16 @@ static void *fuse_do_work(void *data) pthread_mutex_unlock(&mt->lock); return NULL; } - mt->numavail--; + + /* + * This disgusting hack is needed so that zillions of threads + * are not created on a burst of FORGET messages + */ + if (((struct fuse_in_header *) w->buf)->opcode == FUSE_FORGET) + isforget = 1; + + if (!isforget) + mt->numavail--; if (mt->numavail == 0) fuse_start_thread(mt); pthread_mutex_unlock(&mt->lock); @@ -89,7 +100,8 @@ static void *fuse_do_work(void *data) fuse_session_process(mt->se, w->buf, res, ch); pthread_mutex_lock(&mt->lock); - mt->numavail ++; + if (!isforget) + mt->numavail++; if (mt->numavail > 10) { if (mt->exit) { pthread_mutex_unlock(&mt->lock); -- cgit v1.2.3