mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oskar Andero <oskar.andero@sonymobile.com>
To: David Rientjes <rientjes@google.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
	Brian Swetland <swetland@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Dolkow, Snild" <Snild.Dolkow@sonymobile.com>,
	"Lekanovic, Radovan" <Radovan.Lekanovic@sonymobile.com>
Subject: Re: [PATCH] lowmemorykiller: prevent multiple instances of low memory killer
Date: Tue, 23 Apr 2013 23:54:13 +0200	[thread overview]
Message-ID: <20130423215413.GB12983@caracas.corpusers.net> (raw)
In-Reply-To: <alpine.DEB.2.02.1304161254270.30779@chino.kir.corp.google.com>

On 22:00 Tue 16 Apr     , David Rientjes wrote:
> On Tue, 16 Apr 2013, Oskar Andero wrote:
> 
> > > > The comment in shrinker.h is misleading, not the source code.
> > > > do_shrinker_shrink() will fail for anything negative and 0.
> > > 
> > > The comment is correct.  The only acceptable negative return is -1.
> > > Look at the second time do_shrinker_shrink() is called from
> > > shrink_slab().
> > > 
> > >    283                  while (total_scan >= batch_size) {
> > >    284                          int nr_before;
> > >    285  
> > >    286                          nr_before = do_shrinker_shrink(shrinker, shrink, 0);
> > >    287                          shrink_ret = do_shrinker_shrink(shrinker, shrink,
> > >    288                                                          batch_size);
> > >    289                          if (shrink_ret == -1)
> > >    290                                  break;
> > >    291                          if (shrink_ret < nr_before)
> > >    292                                  ret += nr_before - shrink_ret;
> > >    293                          count_vm_events(SLABS_SCANNED, batch_size);
> > 
> > Yes, the comment is correct with what is implemented in the code, but
> > that doesn't mean the code is right. IMHO, relaying on magical numbers is highly
> > questionable coding style.
> > 
> 
> No, it's not.  This is controlled higher in shrink_slab() by this:
> 
> 	max_pass = do_shrinker_shrink(shrinker, shrink, 0);
> 	if (max_pass <= 0)
> 		continue;
> 

Sure, that looks ok, but that doesn't change the fact that line 289
above has a magical number and I guess that explains the comment:
> > >    289                          if (shrink_ret == -1)
> > >    290                                  break;

Just to be clear - this is not about lowmemkiller, but rather a generic
clean-up of shrinkers that is needed IMO.

> and your patch is implemented incorrectly, i.e. it does not return 
> LMK_BUSY if the spinlock is contended which needlessly recalls the 
> shrinker later.
> 
> You have a couple of options:
> 
>  - return -1 when the spinlock is contended immediately when
>    !sc->nr_to_scan (although it should really be a cmpxchg since a
>    spinlock isn't needed), or

I leave it to Snild to comment on the patch, but could you elaborate on why
you think cmpxchg is a better alternative than a spin_trylock? I just had a
brief look at the implementation for ARM and it looks like cmpxchg means
two unconditional memory barriers, whereas spin_trylock has one
conditional memory barrier. See arch/arm/include/asm/spinlock.h:
	if (tmp == 0) {
		smp_mb();
		return 1;
	} else {
		return 0;
	}

...and arch/arm/include/asm/cmpxchg.h:
	smp_mb();
	ret = __cmpxchg(ptr, old, new, size);
	smp_mb();

AFAIK a memory barrier is pretty costly.

-Oskar

  reply	other threads:[~2013-04-23 22:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-15 13:03 Oskar Andero
2013-04-15 13:18 ` Dan Carpenter
2013-04-15 13:38   ` Dolkow, Snild
2013-04-15 14:13     ` Dan Carpenter
2013-04-15 15:03       ` Oskar Andero
2013-04-15 18:28         ` Dolkow, Snild
2013-04-15 19:49           ` Greg Kroah-Hartman
2013-04-15 23:11             ` David Rientjes
2013-04-16  6:19               ` Dan Carpenter
2013-04-16 10:59                 ` Oskar Andero
2013-04-16 20:00                   ` David Rientjes
2013-04-23 21:54                     ` Oskar Andero [this message]
2013-04-24  8:33                     ` Dolkow, Snild

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=20130423215413.GB12983@caracas.corpusers.net \
    --to=oskar.andero@sonymobile.com \
    --cc=Radovan.Lekanovic@sonymobile.com \
    --cc=Snild.Dolkow@sonymobile.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=swetland@google.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

all inboxes | Powered by JetHome®