linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fenghua Yu <fenghua.yu@intel.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] intelrdt: resctrl: recommend locking for resctrlfs
Date: Thu, 1 Dec 2016 13:54:30 -0800	[thread overview]
Message-ID: <20161201215430.GI35583@linux.intel.com> (raw)
In-Reply-To: <20161130222526.GA17750@amt.cnet>

On Wed, Nov 30, 2016 at 08:25:28PM -0200, Marcelo Tosatti wrote:
> On Wed, Nov 30, 2016 at 02:05:31PM -0800, Fenghua Yu wrote:
> > On Wed, Nov 30, 2016 at 01:48:10PM -0200, 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.
> > > 
> > > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> > > 
> > > --- Documentation/x86/intel_rdt_ui.txt.orig	2016-11-30 13:40:33.080233101 -0200
> > > +++ Documentation/x86/intel_rdt_ui.txt	2016-11-30 13:45:01.253703259 -0200
> > > @@ -212,3 +212,30 @@ Finally we move core 4-7 over to the new
> > >  kernel and the tasks running there get 50% of the cache.
> > >  
> > >  # echo C0 > p0/cpus
> > > +
> > > +4) Locking between applications
> > > +
> > > +The allocation of an exclusive reservation
> > > +of L3 cache involves:
> > > +
> > > +        1. read list of cbmmasks for each directory
> > > +        2. find a contiguous set of bits in the global CBM bitmask
> > > +          that is clear in any of the directory cbmmasks
> > > +        3. create a new directory
> > > +        4. set the bits found in step 2 to the new directory "schemata"
> > > +           file
> > 
> > This is one example of why locking is needed. There are other scenarios
> > that need the locking as well. For example, two applications scan each
> > directory to find an empty/less loaded "tasks". Both of them find that
> > directory p1 has empty "tasks" and write their own thread ids into the
> > "tasks" in p1. Turns out the "tasks" in p1 will have crowded threads or
> > workloads. A locking can solve this race scenario too.
> > 
> > As a user interface document, maybe we need a generic explanation why
> > locking plus the example.
> 
> Well, agreed there are other races, but in this particular example
> taking the file lock does not solve the "tasks" race: the contents of
> the tasks file can change in face of fork.

The "tasks" example is only for resolving the race when allocating two tasks
to an empty rdtgroup. Once a task is allocated to a "tasks", the task's forked
children will automatically stay with the task unless they are moved.
Without the locking, task A and task B are allocated to the same directory
because both of them thought "tasks" in the directory is empty. Then
all forked children of both A and B will populate the directory and cause
crowded cache.

Sure the contents of the "tasks" can change in face of fork. But the race
of the allocating two groups of tasks can cause wrong decision to allocate
them at the beginning.

> 
> So i've added your suggestion but can't use this example, if you have
> another one you'd like to see added, please let me know... Replying with
> V2.

Thanks.

-Fenghua

  reply	other threads:[~2016-12-01 21:55 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 [this message]
2016-12-01 14:55   ` [PATCH v2] " Marcelo Tosatti
2016-12-02 11:20     ` Thomas Gleixner
2016-12-02 22:07       ` Marcelo Tosatti
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=20161201215430.GI35583@linux.intel.com \
    --to=fenghua.yu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --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 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).