All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Glauber Costa <glommer@parallels.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	containers@lists.linux-foundation.org,
	Pavel Emelyanov <xemul@parallels.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Hugh Dickins <hughd@google.com>, Nick Piggin <npiggin@kernel.dk>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Rik van Riel <riel@redhat.com>,
	Dave Hansen <dave@linux.vnet.ibm.com>,
	James Bottomley <JBottomley@parallels.com>,
	Eric Dumazet <eric.dumazet@gmail.com>
Subject: Re: [PATCH v3 3/4] limit nr_dentries per superblock
Date: Mon, 15 Aug 2011 17:03:51 +1000	[thread overview]
Message-ID: <20110815070350.GE26978@dastard> (raw)
In-Reply-To: <1313334832-1150-4-git-send-email-glommer@parallels.com>

On Sun, Aug 14, 2011 at 07:13:51PM +0400, Glauber Costa wrote:
> This patch lays the foundation for us to limit the dcache size.
> Each super block can have only a maximum amount of dentries under its
> sub-tree. Allocation fails if we we're over limit and the cache
> can't be pruned to free up space for the newcomers.
> 
> Signed-off-by: Glauber Costa <glommer@parallels.com>
> CC: Dave Chinner <david@fromorbit.com>
> CC: Eric Dumazet <eric.dumazet@gmail.com>
> ---
>  fs/dcache.c        |   28 ++++++++++++++++++++++++++++
>  fs/super.c         |    1 +
>  include/linux/fs.h |    1 +
>  3 files changed, 30 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/dcache.c b/fs/dcache.c
> index 815d9fd..ddd02a2 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -1180,6 +1180,31 @@ void shrink_dcache_parent(struct dentry * parent)
>  }
>  EXPORT_SYMBOL(shrink_dcache_parent);
>  
> +static inline int dcache_mem_check(struct super_block *sb)
> +{
> +	struct shrink_control sc = {
> +		.gfp_mask = GFP_KERNEL,
> +	};
> +
> +	if (sb->s_nr_dentry_max == INT_MAX)
> +		return 0;
> +
> +	do {
> +		int nr_dentry;
> +
> +		nr_dentry = percpu_counter_read_positive(&sb->s_nr_dentry);
> +		if (nr_dentry > sb->s_nr_dentry_max)
> +			nr_dentry =
> +				percpu_counter_sum_positive(&sb->s_nr_dentry);
> +		if (nr_dentry < sb->s_nr_dentry_max)
> +			return 0;
> +
> +	/* nr_pages = 1, lru_pages = 0 should get delta ~ 2 */
> +	} while (shrink_one_shrinker(&sb->s_shrink, &sc, 1, 0));
> +
> +	return -ENOMEM;
> +}

The changes here don't address the comments I made previously about
the error range of the per-cpu counter and update frequency of the
the global counter. w.r.t to small delta changes of the counted
amount.

That is, you cannot expect percpu_counter_read_positive() to change
when you decrement a counter by 2 counts (assuming both objects are
freed), and there's no guarantee that percpu_counter_sum_positive()
will drop below the threshold either while
percpu_counter_read_positive() is returning numbers above the
threshold. That makes this a very expensive and oft-repeated loop.

Indeed, that even assumes that 2 objects that are freed are
dentries. If there are more inodes that dentries in memory, the the
dentries won't even be trimmed, and you'll get stuck in the horribly
expensive loop trimming the cache 2 inodes at a time until the
caches start to balance. Shrinking must be done in large batches to
be effective, not one object at a time.

Further, the shrinker may not make progress freeing items, which
will result in this code returning ENOMEM when the shrinker may
simply have been passing over referenced (i.e. cache hot) dentries.
That will return spurious ENOMEM results back to d_alloc, resulting
in spurious failures that will be impossible to track down...

This also demonstrates my comment about where you factored
shrink_one_shrinker() to be the wrong place. You've already got a
shrink-control structure, so adding a value to .nr_to_scan to the
initialisation gets around the entire need to do all that guess work
of running through the vmscan specific algorithms to get 2 objects
freed.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  parent reply	other threads:[~2011-08-15  7:03 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-14 15:13 [PATCH v3 0/4] Per-container dcache limitation Glauber Costa
2011-08-14 15:13 ` Glauber Costa
     [not found] ` <1313334832-1150-1-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-14 15:13   ` [PATCH v3 1/4] factor out single-shrinker code Glauber Costa
2011-08-14 15:13     ` Glauber Costa
2011-08-15  6:43     ` Dave Chinner
     [not found]     ` <1313334832-1150-2-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-15  6:43       ` Dave Chinner
2011-08-14 15:13   ` [PATCH v3 2/4] Keep nr_dentry per super block Glauber Costa
2011-08-14 15:13     ` Glauber Costa
2011-08-14 17:38     ` Eric Dumazet
2011-08-14 17:38       ` Eric Dumazet
     [not found]     ` <1313334832-1150-3-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-14 17:38       ` Eric Dumazet
2011-08-14 15:13   ` [PATCH v3 3/4] limit nr_dentries per superblock Glauber Costa
2011-08-14 15:13     ` Glauber Costa
     [not found]     ` <1313334832-1150-4-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-15  7:03       ` Dave Chinner
2011-08-15  7:12       ` Pekka Enberg
2011-08-15  7:03     ` Dave Chinner [this message]
2011-08-15  7:12     ` Pekka Enberg
     [not found]       ` <CAOJsxLFYD9DkEU5R+9fZr-uaznteP8-BUC_Ti+FnNFqtbOCHSw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 10:46         ` Dave Chinner
2011-08-15 10:46       ` Dave Chinner
2011-08-15 10:58         ` Pekka Enberg
     [not found]           ` <CAOJsxLGFJmqO-W=itQbO4Mh4DxSD4wrHOC8gQ5bWL5aE1YYeQw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 11:05             ` Pavel Emelyanov
2011-08-15 11:05           ` Pavel Emelyanov
2011-08-15 11:05             ` Pavel Emelyanov
2011-08-15 11:14             ` Pekka Enberg
2011-08-15 11:14               ` Pekka Enberg
2011-08-15 11:32               ` Pavel Emelyanov
2011-08-15 11:32                 ` Pavel Emelyanov
2011-08-15 11:55                 ` Pekka Enberg
2011-08-15 11:55                   ` Pekka Enberg
2011-08-15 12:12                   ` Pavel Emelyanov
2011-08-15 12:12                     ` Pavel Emelyanov
2011-08-15 12:23                     ` Pekka Enberg
2011-08-15 12:23                       ` Pekka Enberg
2011-08-15 12:37                       ` Pavel Emelyanov
2011-08-15 12:37                         ` Pavel Emelyanov
     [not found]                       ` <CAOJsxLEVfGrzUQv0fOpOyw3AaOLOHcWbvLJL1NdrHS6M2j5o1g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 12:37                         ` Pavel Emelyanov
     [not found]                     ` <4E490D47.8050105-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-15 12:23                       ` Pekka Enberg
     [not found]                   ` <CAOJsxLErFcxuuqnWkRbOAHEFbeGrKp3YMZ-144=m16oBXCHJ2g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 12:12                     ` Pavel Emelyanov
     [not found]                 ` <4E4903C1.9050207-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-15 11:55                   ` Pekka Enberg
     [not found]               ` <CAOJsxLFjZffC9i5kQsBWjGy3eWdj3VMB5awz=yPcwgeKb5BG0Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-15 11:32                 ` Pavel Emelyanov
2011-08-16  2:11                 ` Dave Chinner
2011-08-16  2:11               ` Dave Chinner
2011-08-16  2:11                 ` Dave Chinner
     [not found]             ` <4E48FD8A.90401-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-15 11:14               ` Pekka Enberg
2011-08-15 10:58         ` Pekka Enberg
2011-08-14 15:13   ` [PATCH v3 4/4] parse options in the vfs level Glauber Costa
2011-08-14 15:13     ` Glauber Costa
2011-08-14 15:39     ` Vasiliy Kulikov
2011-08-15  0:03       ` Glauber Costa
2011-08-15  0:03       ` Glauber Costa
     [not found]     ` <1313334832-1150-5-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-14 15:39       ` Vasiliy Kulikov
2011-08-15  7:09       ` Dave Chinner
2011-08-15  7:09     ` Dave Chinner
2011-08-24  2:19       ` Glauber Costa
2011-08-24  2:19       ` Glauber Costa
2011-08-17  5:43   ` [PATCH v3 0/4] Per-container dcache limitation Dave Chinner
2011-08-17  5:43 ` Dave Chinner
2011-08-17 18:44   ` Glauber Costa
2011-08-17 18:44   ` Glauber Costa
2011-08-18  1:27     ` Dave Chinner
2011-08-18  1:27       ` Dave Chinner
2011-08-22 11:42       ` Glauber Costa
2011-08-22 11:42       ` Glauber Costa
2011-08-22 11:42         ` Glauber Costa
     [not found]     ` <4E4C0C25.3-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2011-08-18  1:27       ` Dave Chinner

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=20110815070350.GE26978@dastard \
    --to=david@fromorbit.com \
    --cc=JBottomley@parallels.com \
    --cc=aarcange@redhat.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=dave@linux.vnet.ibm.com \
    --cc=eric.dumazet@gmail.com \
    --cc=glommer@parallels.com \
    --cc=hughd@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=npiggin@kernel.dk \
    --cc=riel@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xemul@parallels.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 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.