From: Marcelo Tosatti <mtosatti@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] intelrdt: resctrl: recommend locking for resctrlfs
Date: Fri, 2 Dec 2016 20:07:04 -0200 [thread overview]
Message-ID: <20161202220702.GA31213@amt.cnet> (raw)
In-Reply-To: <alpine.DEB.2.20.1612021211050.4295@nanos>
On Fri, Dec 02, 2016 at 12:20:29PM +0100, Thomas Gleixner wrote:
> On Thu, 1 Dec 2016, Marcelo Tosatti wrote:
> >
> > There is a locking problem between different applications
> > reading/writing to resctrlfs directory at the same time (read the patch
> > below for details).
> >
> > Suggest a standard locking scheme for applications to use.
>
> ....
>
> > +To coordinate atomic operations on resctrl and avoid the problem
> > +above, the following locking procedure is recommended:
> > +
> > +A) open /var/lock/resctrl/fs.lock with O_CREAT|O_EXCL.
> > +B) if success, write pid of program accessing the directory
> > + structure to this file.
> > +C) read/write the directory structure.
> > +D) remove file.
>
> What's wrong with using flock, which works from shell scripts as well?
>
> Thanks,
>
> tglx
Hi Thomas,
Nothing wrong with it... I'm just copying the behaviour of other
programs.
Actually, using flock(2) allows one to use LOCK_SH for readers and
this allows consistent writer/reader behaviour (say, a reader
won't see a partially written directory).
NAME
flock - apply or remove an advisory lock on an open file
SYNOPSIS
#include <sys/file.h>
int flock(int fd, int operation);
DESCRIPTION
Apply or remove an advisory lock on the open file specified by
fd. The argument operation is one of
the following:
LOCK_SH Place a shared lock. More than one process may hold
a shared lock for a given file at a
given time.
LOCK_EX Place an exclusive lock. Only one process may
hold an exclusive lock for a given file
at a given time.
LOCK_UN Remove an existing lock held by this process.
---
So the procedure would be:
/var/lock/resctrl/fs.lock created previously in the filesystem.
WRITE LOCK:
A) Take flock(EXCLUSIVE) on /var/lock/resctrl/fs.lock
B) If success, write pid of the program to the file.
C) read/write the directory structure.
D) funlock
READ LOCK:
A) Take flock(SHARED) on /var/lock/resctrl/fs.lock
B) If success read the directory structure.
C) funlock
How about that?
next prev parent reply other threads:[~2016-12-02 22:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-30 15:48 [PATCH] intelrdt: resctrl: recommend locking for resctrlfs Marcelo Tosatti
2016-11-30 21:10 ` Thomas Gleixner
2016-11-30 22:05 ` Fenghua Yu
2016-11-30 22:25 ` Marcelo Tosatti
2016-12-01 21:54 ` Fenghua Yu
2016-12-01 14:55 ` [PATCH v2] " Marcelo Tosatti
2016-12-02 11:20 ` Thomas Gleixner
2016-12-02 22:07 ` Marcelo Tosatti [this message]
2016-12-09 9:35 ` Thomas Gleixner
2016-12-14 17:08 ` [PATCH v3] " Marcelo Tosatti
2016-12-15 13:49 ` [tip:x86/cache] Documentation, x86, resctrl: Recommend " tip-bot for Marcelo Tosatti
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=20161202220702.GA31213@amt.cnet \
--to=mtosatti@redhat.com \
--cc=fenghua.yu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.