From: Dave Chinner <david@fromorbit.com>
To: Vitaly Wool <vitalywool@gmail.com>
Cc: Linux-MM <linux-mm@kvack.org>,
linux-kernel@vger.kernel.org, Seth Jennings <sjenning@redhat.com>,
Dan Streetman <ddstreet@ieee.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v2] z3fold: add shrinker
Date: Wed, 12 Oct 2016 09:52:06 +1100 [thread overview]
Message-ID: <20161011225206.GJ23194@dastard> (raw)
In-Reply-To: <20161012001827.53ae55723e67d1dee2a2f839@gmail.com>
On Wed, Oct 12, 2016 at 12:18:27AM +0200, Vitaly Wool wrote:
>
> Here comes the correct shrinker patch for z3fold. This shrinker
> implementation does not free up any pages directly but it allows
> for a denser placement of compressed objects which results in
> less actual pages consumed and higher compression ratio therefore.
>
> This patch has been checked with the latest Linus's tree.
>
> Signed-off-by: Vitaly Wool <vitalywool@gmail.com>
> ---
> mm/z3fold.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 127 insertions(+), 24 deletions(-)
>
> diff --git a/mm/z3fold.c b/mm/z3fold.c
> index 8f9e89c..4841972 100644
> --- a/mm/z3fold.c
> +++ b/mm/z3fold.c
> @@ -30,6 +30,7 @@
> #include <linux/slab.h>
> #include <linux/spinlock.h>
> #include <linux/zpool.h>
> +#include <linux/shrinker.h>
>
> /*****************
> * Structures
> @@ -69,8 +70,11 @@ struct z3fold_ops {
> * @lru: list tracking the z3fold pages in LRU order by most recently
> * added buddy.
> * @pages_nr: number of z3fold pages in the pool.
> + * @unbuddied_nr: number of unbuddied z3fold pages in the pool.
> * @ops: pointer to a structure of user defined operations specified at
> * pool creation time.
> + * @shrinker: shrinker structure to optimize page layout in background
> + * @no_shrinker: flag showing if we run with shrinker or not
Ugh.
>
> +/* Has to be called with lock held */
> +static int z3fold_compact_page(struct z3fold_header *zhdr, bool sync)
> +{
> + struct page *page = virt_to_page(zhdr);
> + void *beg = zhdr;
> +
[snip using memmove() to shift chunks around]
> +static unsigned long z3fold_shrink_scan(struct shrinker *shrink,
> + struct shrink_control *sc)
> +{
> + struct z3fold_pool *pool = container_of(shrink, struct z3fold_pool,
> + shrinker);
> + struct z3fold_header *zhdr;
> + int i, nr_to_scan = sc->nr_to_scan;
> +
> + spin_lock(&pool->lock);
Do not do this. Shrinkers should not run entirely under a spin lock
like this - it causes scheduling latency problems and when the
shrinker is run concurrently on different CPUs it will simply burn
CPU doing no useful work. Especially, in this case, as each call to
z3fold_compact_page() may be copying a significant amount of data
around and so there is potentially a /lot/ of work being done on
each call to the shrinker.
If you need compaction exclusion for the shrinker invocation, then
please use a sleeping lock to protect the compaction work.
> *****************/
> @@ -234,6 +335,13 @@ static struct z3fold_pool *z3fold_create_pool(gfp_t gfp,
> INIT_LIST_HEAD(&pool->unbuddied[i]);
> INIT_LIST_HEAD(&pool->buddied);
> INIT_LIST_HEAD(&pool->lru);
> + pool->shrinker.count_objects = z3fold_shrink_count;
> + pool->shrinker.scan_objects = z3fold_shrink_scan;
> + pool->shrinker.seeks = DEFAULT_SEEKS;
> + if (register_shrinker(&pool->shrinker)) {
> + pr_warn("z3fold: could not register shrinker\n");
> + pool->no_shrinker = true;
> + }
Just fail creation of the pool. If you can't register a shrinker,
then much bigger problems are about to happen to your system, and
running a new memory consumer that /can't be shrunk/ is not going to
help anyone.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2016-10-11 22:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-11 22:18 [PATCH v2] z3fold: add shrinker Vitaly Wool
2016-10-11 22:52 ` Dave Chinner [this message]
2016-10-12 8:26 ` Vitaly Wool
2016-10-13 0:20 ` Dave Chinner
2016-10-13 13:15 ` Vitaly Wool
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=20161011225206.GJ23194@dastard \
--to=david@fromorbit.com \
--cc=akpm@linux-foundation.org \
--cc=ddstreet@ieee.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sjenning@redhat.com \
--cc=vitalywool@gmail.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;
as well as URLs for NNTP newsgroup(s).