Skip to content

Commit 860c707

Browse files
sergey-senozhatskytorvalds
authored andcommitted
zsmalloc: account the number of compacted pages
Compaction returns back to zram the number of migrated objects, which is quite uninformative -- we have objects of different sizes so user space cannot obtain any valuable data from that number. Change compaction to operate in terms of pages and return back to compaction issuer the number of pages that were freed during compaction. So from now on we will export more meaningful value in zram<id>/mm_stat -- the number of freed (compacted) pages. This requires: (a) a rename of `num_migrated' to 'pages_compacted' (b) a internal API change -- return first_page's fullness_group from putback_zspage(), so we know when putback_zspage() did free_zspage(). It helps us to account compaction stats correctly. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Acked-by: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7d3f393 commit 860c707

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎Documentation/blockdev/zram.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ mem_used_max RW the maximum amount memory zram have consumed to
144144
store compressed data
145145
mem_limit RW the maximum amount of memory ZRAM can use to store
146146
the compressed data
147-
num_migrated RO the number of objects migrated migrated by compaction
147+
pages_compacted RO the number of pages freed during compaction
148+
(available only via zram<id>/mm_stat node)
148149
compact WO trigger memory compaction
149150

150151
WARNING

‎drivers/block/zram/zram_drv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static ssize_t mm_stat_show(struct device *dev,
450450
zram->limit_pages << PAGE_SHIFT,
451451
max_used << PAGE_SHIFT,
452452
(u64)atomic64_read(&zram->stats.zero_pages),
453-
pool_stats.num_migrated);
453+
pool_stats.pages_compacted);
454454
up_read(&zram->init_lock);
455455

456456
return ret;

‎include/linux/zsmalloc.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ enum zs_mapmode {
3535
};
3636

3737
struct zs_pool_stats {
38-
/* How many objects were migrated */
39-
unsigned long num_migrated;
38+
/* How many pages were migrated (freed) */
39+
unsigned long pages_compacted;
4040
};
4141

4242
struct zs_pool;

‎mm/zsmalloc.c‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,6 @@ struct zs_compact_control {
15791579
/* Starting object index within @s_page which used for live object
15801580
* in the subpage. */
15811581
int index;
1582-
/* How many of objects were migrated */
1583-
int nr_migrated;
15841582
};
15851583

15861584
static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
@@ -1617,7 +1615,6 @@ static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
16171615
record_obj(handle, free_obj);
16181616
unpin_tag(handle);
16191617
obj_free(pool, class, used_obj);
1620-
cc->nr_migrated++;
16211618
}
16221619

16231620
/* Remember last position in this iteration */
@@ -1643,8 +1640,17 @@ static struct page *isolate_target_page(struct size_class *class)
16431640
return page;
16441641
}
16451642

1646-
static void putback_zspage(struct zs_pool *pool, struct size_class *class,
1647-
struct page *first_page)
1643+
/*
1644+
* putback_zspage - add @first_page into right class's fullness list
1645+
* @pool: target pool
1646+
* @class: destination class
1647+
* @first_page: target page
1648+
*
1649+
* Return @fist_page's fullness_group
1650+
*/
1651+
static enum fullness_group putback_zspage(struct zs_pool *pool,
1652+
struct size_class *class,
1653+
struct page *first_page)
16481654
{
16491655
enum fullness_group fullness;
16501656

@@ -1662,6 +1668,8 @@ static void putback_zspage(struct zs_pool *pool, struct size_class *class,
16621668

16631669
free_zspage(first_page);
16641670
}
1671+
1672+
return fullness;
16651673
}
16661674

16671675
static struct page *isolate_source_page(struct size_class *class)
@@ -1704,7 +1712,6 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)
17041712
struct page *src_page;
17051713
struct page *dst_page = NULL;
17061714

1707-
cc.nr_migrated = 0;
17081715
spin_lock(&class->lock);
17091716
while ((src_page = isolate_source_page(class))) {
17101717

@@ -1733,7 +1740,9 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)
17331740
break;
17341741

17351742
putback_zspage(pool, class, dst_page);
1736-
putback_zspage(pool, class, src_page);
1743+
if (putback_zspage(pool, class, src_page) == ZS_EMPTY)
1744+
pool->stats.pages_compacted +=
1745+
get_pages_per_zspage(class->size);
17371746
spin_unlock(&class->lock);
17381747
cond_resched();
17391748
spin_lock(&class->lock);
@@ -1742,8 +1751,6 @@ static void __zs_compact(struct zs_pool *pool, struct size_class *class)
17421751
if (src_page)
17431752
putback_zspage(pool, class, src_page);
17441753

1745-
pool->stats.num_migrated += cc.nr_migrated;
1746-
17471754
spin_unlock(&class->lock);
17481755
}
17491756

@@ -1761,7 +1768,7 @@ unsigned long zs_compact(struct zs_pool *pool)
17611768
__zs_compact(pool, class);
17621769
}
17631770

1764-
return pool->stats.num_migrated;
1771+
return pool->stats.pages_compacted;
17651772
}
17661773
EXPORT_SYMBOL_GPL(zs_compact);
17671774

0 commit comments

Comments
 (0)