From: Minchan Kim <minchan@kernel.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [RFC][PATCHv4 6/7] zsmalloc: account the number of compacted pages
Date: Mon, 6 Jul 2015 16:52:41 +0900 [thread overview]
Message-ID: <20150706075241.GA6514@blaptop> (raw)
In-Reply-To: <20150701072952.GA537@swordfish>
Hi Sergey,
On Wed, Jul 01, 2015 at 04:29:52PM +0900, Sergey Senozhatsky wrote:
> On (06/30/15 21:35), Sergey Senozhatsky wrote:
> [..]
> > if (src_page)
> > putback_zspage(pool, class, src_page);
> >
> > - pool->num_migrated += cc.nr_migrated;
> > + cc.nr_migrated /= get_maxobj_per_zspage(class->size,
> > + class->pages_per_zspage);
> > +
> > + pool->num_migrated += cc.nr_migrated *
> > + get_pages_per_zspage(class->size);
> >
> > spin_unlock(&class->lock);
>
> Oh, well. This is bloody wrong, sorry. We don't pick up src_page-s that we
> can completely drain. Thus, the fact that we can't compact (!zs_can_compact())
> anymore doesn't mean that we actually have released any zspages.
>
> So...
>
> (a) we can isolate_source_page() more accurately -- iterate list and
> look for pages that have ->inuse less or equal to the amount of unused
> objects. So we can guarantee that this particular zspage will be released
> at the end. It adds O(n) every time we isolate_source_page(), because
> the number of unused objects changes. But it's sort of worth it, I
> think. Otherwise we still can move M objects w/o releasing any pages
> after all. If we consider compaction as a slow path (and I think we do)
> then this option doesn't look so bad.
>
>
>
> (b) if (a) is not an option, then we need to know that we have drained the
> src_page. And it seems that the easiest way to do it is to change
> 'void putback_zspage(...)' to 'bool putback_zspage(...)' and return `true'
> from putback_zspage() when putback resulted in free_zspage() (IOW, the page
> was ZS_EMPTY). And in __zs_compact() do something like
Just nit:
putback_zspage is not related to "free zspage" so I want to handle it in
caller. For it, putback_zspage could return fullness type page is added.
Something like that.
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 99133e8..32e3bb9 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1653,7 +1653,17 @@ static struct page *isolate_target_page(struct size_class *class)
return page;
}
-static void putback_zspage(struct zs_pool *pool, struct size_class *class,
+/*
+ * putback_zspage - add @first_page into right class's fullness list
+ * @pool: target pool
+ * @class: destination class
+ * @first_page: target page
+ *
+ * Return:
+ * The fullness_group @fist_page is added
+ */
+static enum fullness_group putback_zspage(struct zs_pool *pool,
+ struct size_class *class,
struct page *first_page)
{
enum fullness_group fullness;
@@ -1672,6 +1682,8 @@ static void putback_zspage(struct zs_pool *pool, struct size_class *class,
free_zspage(first_page);
}
+
+ return fullness;
}
static struct page *isolate_source_page(struct size_class *class)
@@ -1707,11 +1719,13 @@ static unsigned long zs_can_compact(struct size_class *class)
return obj_wasted * get_pages_per_zspage(class->size);
}
-static void __zs_compact(struct zs_pool *pool, struct size_class *class)
+static unsigned long __zs_compact(struct zs_pool *pool,
+ struct size_class *class)
{
struct zs_compact_control cc;
struct page *src_page;
struct page *dst_page = NULL;
+ unsigned long nr_freed = 0;
cc.nr_migrated = 0;
spin_lock(&class->lock);
@@ -1742,7 +1756,8 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)
break;
putback_zspage(pool, class, dst_page);
- putback_zspage(pool, class, src_page);
+ if (ZS_EMPTY == putback_zspage(pool, class, src_page))
+ nr_freed += get_pages_per_zspage(class->size);
spin_unlock(&class->lock);
cond_resched();
spin_lock(&class->lock);
@@ -1758,22 +1773,36 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)
get_pages_per_zspage(class->size);
spin_unlock(&class->lock);
+
+ return nr_freed;
}
+/*
+ * zs_compact - migrate objects and free empty zspage in the @pool
+ * @pool: target pool for compaction
+ *
+ * Return:
+ * The number of freed pages by compaction
+ */
unsigned long zs_compact(struct zs_pool *pool)
{
int i;
struct size_class *class;
+ unsigned long nr_freed = 0;
for (i = zs_size_classes - 1; i >= 0; i--) {
+
class = pool->size_class[i];
if (!class)
continue;
+
if (class->index != i)
continue;
- __zs_compact(pool, class);
+
+ nr_freed += __zs_compact(pool, class);
}
- return pool->num_migrated;
+
+ return nr_freed;
}
EXPORT_SYMBOL_GPL(zs_compact);
--
1.9.3
--
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>
WARNING: multiple messages have this Message-ID (diff)
From: Minchan Kim <minchan@kernel.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [RFC][PATCHv4 6/7] zsmalloc: account the number of compacted pages
Date: Mon, 6 Jul 2015 16:52:41 +0900 [thread overview]
Message-ID: <20150706075241.GA6514@blaptop> (raw)
In-Reply-To: <20150701072952.GA537@swordfish>
Hi Sergey,
On Wed, Jul 01, 2015 at 04:29:52PM +0900, Sergey Senozhatsky wrote:
> On (06/30/15 21:35), Sergey Senozhatsky wrote:
> [..]
> > if (src_page)
> > putback_zspage(pool, class, src_page);
> >
> > - pool->num_migrated += cc.nr_migrated;
> > + cc.nr_migrated /= get_maxobj_per_zspage(class->size,
> > + class->pages_per_zspage);
> > +
> > + pool->num_migrated += cc.nr_migrated *
> > + get_pages_per_zspage(class->size);
> >
> > spin_unlock(&class->lock);
>
> Oh, well. This is bloody wrong, sorry. We don't pick up src_page-s that we
> can completely drain. Thus, the fact that we can't compact (!zs_can_compact())
> anymore doesn't mean that we actually have released any zspages.
>
> So...
>
> (a) we can isolate_source_page() more accurately -- iterate list and
> look for pages that have ->inuse less or equal to the amount of unused
> objects. So we can guarantee that this particular zspage will be released
> at the end. It adds O(n) every time we isolate_source_page(), because
> the number of unused objects changes. But it's sort of worth it, I
> think. Otherwise we still can move M objects w/o releasing any pages
> after all. If we consider compaction as a slow path (and I think we do)
> then this option doesn't look so bad.
>
>
>
> (b) if (a) is not an option, then we need to know that we have drained the
> src_page. And it seems that the easiest way to do it is to change
> 'void putback_zspage(...)' to 'bool putback_zspage(...)' and return `true'
> from putback_zspage() when putback resulted in free_zspage() (IOW, the page
> was ZS_EMPTY). And in __zs_compact() do something like
Just nit:
putback_zspage is not related to "free zspage" so I want to handle it in
caller. For it, putback_zspage could return fullness type page is added.
Something like that.
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 99133e8..32e3bb9 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1653,7 +1653,17 @@ static struct page *isolate_target_page(struct size_class *class)
return page;
}
-static void putback_zspage(struct zs_pool *pool, struct size_class *class,
+/*
+ * putback_zspage - add @first_page into right class's fullness list
+ * @pool: target pool
+ * @class: destination class
+ * @first_page: target page
+ *
+ * Return:
+ * The fullness_group @fist_page is added
+ */
+static enum fullness_group putback_zspage(struct zs_pool *pool,
+ struct size_class *class,
struct page *first_page)
{
enum fullness_group fullness;
@@ -1672,6 +1682,8 @@ static void putback_zspage(struct zs_pool *pool, struct size_class *class,
free_zspage(first_page);
}
+
+ return fullness;
}
static struct page *isolate_source_page(struct size_class *class)
@@ -1707,11 +1719,13 @@ static unsigned long zs_can_compact(struct size_class *class)
return obj_wasted * get_pages_per_zspage(class->size);
}
-static void __zs_compact(struct zs_pool *pool, struct size_class *class)
+static unsigned long __zs_compact(struct zs_pool *pool,
+ struct size_class *class)
{
struct zs_compact_control cc;
struct page *src_page;
struct page *dst_page = NULL;
+ unsigned long nr_freed = 0;
cc.nr_migrated = 0;
spin_lock(&class->lock);
@@ -1742,7 +1756,8 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)
break;
putback_zspage(pool, class, dst_page);
- putback_zspage(pool, class, src_page);
+ if (ZS_EMPTY == putback_zspage(pool, class, src_page))
+ nr_freed += get_pages_per_zspage(class->size);
spin_unlock(&class->lock);
cond_resched();
spin_lock(&class->lock);
@@ -1758,22 +1773,36 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)
get_pages_per_zspage(class->size);
spin_unlock(&class->lock);
+
+ return nr_freed;
}
+/*
+ * zs_compact - migrate objects and free empty zspage in the @pool
+ * @pool: target pool for compaction
+ *
+ * Return:
+ * The number of freed pages by compaction
+ */
unsigned long zs_compact(struct zs_pool *pool)
{
int i;
struct size_class *class;
+ unsigned long nr_freed = 0;
for (i = zs_size_classes - 1; i >= 0; i--) {
+
class = pool->size_class[i];
if (!class)
continue;
+
if (class->index != i)
continue;
- __zs_compact(pool, class);
+
+ nr_freed += __zs_compact(pool, class);
}
- return pool->num_migrated;
+
+ return nr_freed;
}
EXPORT_SYMBOL_GPL(zs_compact);
--
1.9.3
--
Kind regards,
Minchan Kim
next prev parent reply other threads:[~2015-07-06 7:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-30 12:35 [RFC][PATCHv4 0/7] mm/zsmalloc: introduce automatic pool compaction Sergey Senozhatsky
2015-06-30 12:35 ` Sergey Senozhatsky
2015-06-30 12:35 ` [RFC][PATCHv4 1/7] zsmalloc: drop unused variable `nr_to_migrate' Sergey Senozhatsky
2015-06-30 12:35 ` Sergey Senozhatsky
2015-06-30 12:35 ` [RFC][PATCHv4 2/7] zsmalloc: always keep per-class stats Sergey Senozhatsky
2015-06-30 12:35 ` Sergey Senozhatsky
2015-06-30 12:35 ` [RFC][PATCHv4 3/7] zsmalloc: introduce zs_can_compact() function Sergey Senozhatsky
2015-06-30 12:35 ` Sergey Senozhatsky
2015-06-30 12:35 ` [RFC][PATCHv4 4/7] zsmalloc: cosmetic compaction code adjustments Sergey Senozhatsky
2015-06-30 12:35 ` Sergey Senozhatsky
2015-06-30 12:35 ` [RFC][PATCHv4 5/7] zsmalloc/zram: store compaction stats in zspool Sergey Senozhatsky
2015-06-30 12:35 ` Sergey Senozhatsky
2015-06-30 12:35 ` [RFC][PATCHv4 6/7] zsmalloc: account the number of compacted pages Sergey Senozhatsky
2015-06-30 12:35 ` Sergey Senozhatsky
2015-07-01 7:29 ` Sergey Senozhatsky
2015-07-01 7:29 ` Sergey Senozhatsky
2015-07-02 2:13 ` Sergey Senozhatsky
2015-07-02 2:13 ` Sergey Senozhatsky
2015-07-06 7:52 ` Minchan Kim [this message]
2015-07-06 7:52 ` Minchan Kim
2015-06-30 12:35 ` [RFC][PATCHv4 7/7] zsmalloc: register a shrinker to trigger auto-compaction Sergey Senozhatsky
2015-06-30 12:35 ` 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=20150706075241.GA6514@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 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.