From: Minchan Kim <minchan@kernel.org>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [PATCH v6 3/7] zsmalloc: introduce zs_can_compact() function
Date: Tue, 7 Jul 2015 22:21:36 +0900 [thread overview]
Message-ID: <20150707132136.GA3898@blaptop> (raw)
In-Reply-To: <1436270221-17844-4-git-send-email-sergey.senozhatsky@gmail.com>
On Tue, Jul 07, 2015 at 08:56:57PM +0900, Sergey Senozhatsky wrote:
> This function checks if class compaction will free any pages.
> Rephrasing -- do we have enough unused objects to form at least
> one ZS_EMPTY page and free it. It aborts compaction if class
> compaction will not result in any (further) savings.
>
> EXAMPLE (this debug output is not part of this patch set):
>
> -- class size
> -- number of allocated objects
> -- number of used objects
> -- max objects per zspage
> -- pages per zspage
> -- estimated number of pages that will be freed
>
> [..]
> class-512 objs:544 inuse:540 maxobj-per-zspage:8 pages-per-zspage:1 zspages-to-free:0
> ... class-512 compaction is useless. break
> class-496 objs:660 inuse:570 maxobj-per-zspage:33 pages-per-zspage:4 zspages-to-free:2
> class-496 objs:627 inuse:570 maxobj-per-zspage:33 pages-per-zspage:4 zspages-to-free:1
> class-496 objs:594 inuse:570 maxobj-per-zspage:33 pages-per-zspage:4 zspages-to-free:0
> ... class-496 compaction is useless. break
> class-448 objs:657 inuse:617 maxobj-per-zspage:9 pages-per-zspage:1 zspages-to-free:4
> class-448 objs:648 inuse:617 maxobj-per-zspage:9 pages-per-zspage:1 zspages-to-free:3
> class-448 objs:639 inuse:617 maxobj-per-zspage:9 pages-per-zspage:1 zspages-to-free:2
> class-448 objs:630 inuse:617 maxobj-per-zspage:9 pages-per-zspage:1 zspages-to-free:1
> class-448 objs:621 inuse:617 maxobj-per-zspage:9 pages-per-zspage:1 zspages-to-free:0
> ... class-448 compaction is useless. break
> class-432 objs:728 inuse:685 maxobj-per-zspage:28 pages-per-zspage:3 zspages-to-free:1
> class-432 objs:700 inuse:685 maxobj-per-zspage:28 pages-per-zspage:3 zspages-to-free:0
> ... class-432 compaction is useless. break
> class-416 objs:819 inuse:705 maxobj-per-zspage:39 pages-per-zspage:4 zspages-to-free:2
> class-416 objs:780 inuse:705 maxobj-per-zspage:39 pages-per-zspage:4 zspages-to-free:1
> class-416 objs:741 inuse:705 maxobj-per-zspage:39 pages-per-zspage:4 zspages-to-free:0
> ... class-416 compaction is useless. break
> class-400 objs:690 inuse:674 maxobj-per-zspage:10 pages-per-zspage:1 zspages-to-free:1
> class-400 objs:680 inuse:674 maxobj-per-zspage:10 pages-per-zspage:1 zspages-to-free:0
> ... class-400 compaction is useless. break
> class-384 objs:736 inuse:709 maxobj-per-zspage:32 pages-per-zspage:3 zspages-to-free:0
> ... class-384 compaction is useless. break
> [..]
>
> Every "compaction is useless" indicates that we saved CPU cycles.
>
> class-512 has
> 544 object allocated
> 540 objects used
> 8 objects per-page
>
> Even if we have a ALMOST_EMPTY zspage, we still don't have enough room to
> migrate all of its objects and free this zspage; so compaction will not
> make a lot of sense, it's better to just leave it as is.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
A nit below.
> ---
> mm/zsmalloc.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 036baa8..b7410c1 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -1685,6 +1685,28 @@ static struct page *isolate_source_page(struct size_class *class)
> return page;
> }
>
> +/*
> + *
> + * Based on the number of unused allocated objects calculate
> + * and return the number of pages that we can free.
> + *
> + * Should be called under class->lock.
> + */
> +static unsigned long zs_can_compact(struct size_class *class)
> +{
> + unsigned long obj_wasted;
> +
> + if (!zs_stat_get(class, CLASS_ALMOST_EMPTY))
> + return 0;
> +
> + obj_wasted = zs_stat_get(class, OBJ_ALLOCATED) -
> + zs_stat_get(class, OBJ_USED);
> +
> + obj_wasted /= get_maxobj_per_zspage(class->size,
> + class->pages_per_zspage);
Normally, I insert blank line before last return and I look at
other code under mm, it seems to be a common rule.
> + return obj_wasted * get_pages_per_zspage(class->size);
> +}
> +
> static unsigned long __zs_compact(struct zs_pool *pool,
> struct size_class *class)
> {
> @@ -1698,6 +1720,9 @@ static unsigned long __zs_compact(struct zs_pool *pool,
>
> BUG_ON(!is_first_page(src_page));
>
> + if (!zs_can_compact(class))
> + break;
> +
> cc.index = 0;
> cc.s_page = src_page;
>
> --
> 2.4.5
>
--
Kind regards,
Minchan Kim
--
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:[~2015-07-07 13:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 11:56 [PATCH v6 0/7] mm/zsmalloc: introduce automatic pool compaction Sergey Senozhatsky
2015-07-07 11:56 ` [PATCH v6 1/7] zsmalloc: drop unused variable `nr_to_migrate' Sergey Senozhatsky
2015-07-07 11:56 ` [PATCH v6 2/7] zsmalloc: always keep per-class stats Sergey Senozhatsky
2015-07-07 11:56 ` [PATCH v6 3/7] zsmalloc: introduce zs_can_compact() function Sergey Senozhatsky
2015-07-07 13:21 ` Minchan Kim [this message]
2015-07-07 11:56 ` [PATCH v6 4/7] zsmalloc: cosmetic compaction code adjustments Sergey Senozhatsky
2015-07-07 11:56 ` [PATCH v6 5/7] zsmalloc/zram: introduce zs_pool_stats api Sergey Senozhatsky
2015-07-07 13:36 ` Minchan Kim
2015-07-07 14:32 ` Sergey Senozhatsky
2015-07-07 14:48 ` Minchan Kim
2015-07-07 15:02 ` Sergey Senozhatsky
2015-07-07 11:57 ` [PATCH v6 6/7] zsmalloc: account the number of compacted pages Sergey Senozhatsky
2015-07-07 13:39 ` Minchan Kim
2015-07-07 14:21 ` Sergey Senozhatsky
2015-07-07 14:33 ` Minchan Kim
2015-07-07 11:57 ` [PATCH v6 7/7] zsmalloc: use shrinker to trigger auto-compaction Sergey Senozhatsky
2015-07-07 13:44 ` Minchan Kim
2015-07-07 14:41 ` Sergey Senozhatsky
2015-07-07 15:01 ` Minchan Kim
2015-07-07 15:12 ` Sergey Senozhatsky
2015-07-08 2:18 ` Sergey Senozhatsky
2015-07-08 3:04 ` Minchan Kim
2015-07-08 3:49 ` Sergey Senozhatsky
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=20150707132136.GA3898@blaptop \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@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