[sheepdog] [PATCH] sheep: remove the busy lock in the journal commiting process

Hitoshi Mitake mitake.hitoshi at gmail.com
Fri Dec 27 03:04:02 CET 2013


At Fri, 27 Dec 2013 09:58:07 +0800,
Robin Dong wrote:
> 
> [1  <multipart/alternative (7bit)>]
> [1.1  <text/plain; ISO-8859-1 (7bit)>]
> 2013/12/26 Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> 
> > This patch removes the busy wait which can potentially be large in the
> > journaling mechanism and sleep inside it.
> >
> > Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> > ---
> >  sheep/journal.c |   64
> > ++++++++++++++++++++++++++++---------------------------
> >  1 file changed, 33 insertions(+), 31 deletions(-)
> >
> > diff --git a/sheep/journal.c b/sheep/journal.c
> > index b5f0ff2..17b0b03 100644
> > --- a/sheep/journal.c
> > +++ b/sheep/journal.c
> > @@ -54,7 +54,9 @@ static int jfile_fds[2];
> >  static size_t jfile_size;
> >
> >  static struct journal_file jfile;
> > -static pthread_spinlock_t jfile_lock;
> > +static struct sd_mutex jfile_lock = SD_MUTEX_INITIALIZER;
> > +
> > +static struct work_queue *commit_wq;
> >
> >  static int create_journal_file(const char *root, const char *name)
> >  {
> > @@ -277,7 +279,12 @@ int journal_file_init(const char *path, size_t size,
> > bool skip)
> >         fd = create_journal_file(path, jfile_name[1]);
> >         jfile_fds[1] = fd;
> >
> > -       pthread_spin_init(&jfile_lock, PTHREAD_PROCESS_PRIVATE);
> > +       commit_wq = create_ordered_work_queue("journal commit");
> > +       if (!commit_wq) {
> > +               sd_err("error at creating a workqueue for journal data
> > commit");
> > +               return -1;
> > +       }
> > +
> >         return 0;
> >  }
> >
> > @@ -301,49 +308,43 @@ void clean_journal_file(const char *p)
> >
> >  static inline bool jfile_enough_space(size_t size)
> >  {
> > -       if (jfile.pos + size > jfile_size)
> > -               return false;
> > -       return true;
> > +       return jfile.pos + size < jfile_size;
> >
> 
> IMHO, may be "return (jfile.pos + size) < jfile_size" is much easier for
> reading.

I agree. I'll fix it in the v2 later.

Thanks,
Hitoshi



More information about the sheepdog mailing list