linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] zsmalloc: move pages_allocated to zs_pool
@ 2014-08-14  1:12 Minchan Kim
  2014-08-14  1:12 ` [PATCH 2/3] zram: limit memory size for zram Minchan Kim
  2014-08-14  1:12 ` [PATCH 3/3] zram: add mem_used_max via sysfs Minchan Kim
  0 siblings, 2 replies; 12+ messages in thread
From: Minchan Kim @ 2014-08-14  1:12 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, Sergey Senozhatsky, Jerome Marchand,
	juno.choi, seungho1.park, Luigi Semenzato, Nitin Gupta,
	Seth Jennings, Dan Streetman, ds2horner, Minchan Kim

Pages_allocated has counted in size_class structure and when user
want to see total_size_bytes, it gathers all of value from each
size_class to report the sum.

It's not bad if user don't see the value often but if user start
to see the value frequently, it would be not a good deal for
performance POV.

Even, this patch moves the variable from size_class to zs_pool
so it reduces memory footprint (from [255 * 8byte] to
[sizeof(atomic_t)]) but it introduce new atomic opearation
but it's not a big deal because atomic operation is called on
slow path of zsmalloc where it allocates/free zspage unit,
not object.

Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 mm/zsmalloc.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 4e2fc83cb394..2f21ea8921dc 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -199,9 +199,6 @@ struct size_class {
 
 	spinlock_t lock;
 
-	/* stats */
-	u64 pages_allocated;
-
 	struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS];
 };
 
@@ -220,6 +217,7 @@ struct zs_pool {
 	struct size_class size_class[ZS_SIZE_CLASSES];
 
 	gfp_t flags;	/* allocation flags used when growing pool */
+	atomic_t pages_allocated;
 };
 
 /*
@@ -1027,8 +1025,8 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size)
 			return 0;
 
 		set_zspage_mapping(first_page, class->index, ZS_EMPTY);
+		atomic_add(class->pages_per_zspage, &pool->pages_allocated);
 		spin_lock(&class->lock);
-		class->pages_allocated += class->pages_per_zspage;
 	}
 
 	obj = (unsigned long)first_page->freelist;
@@ -1081,14 +1079,12 @@ void zs_free(struct zs_pool *pool, unsigned long obj)
 
 	first_page->inuse--;
 	fullness = fix_fullness_group(pool, first_page);
-
-	if (fullness == ZS_EMPTY)
-		class->pages_allocated -= class->pages_per_zspage;
-
 	spin_unlock(&class->lock);
 
-	if (fullness == ZS_EMPTY)
+	if (fullness == ZS_EMPTY) {
+		atomic_sub(class->pages_per_zspage, &pool->pages_allocated);
 		free_zspage(first_page);
+	}
 }
 EXPORT_SYMBOL_GPL(zs_free);
 
@@ -1184,12 +1180,9 @@ EXPORT_SYMBOL_GPL(zs_unmap_object);
 
 u64 zs_get_total_size_bytes(struct zs_pool *pool)
 {
-	int i;
-	u64 npages = 0;
-
-	for (i = 0; i < ZS_SIZE_CLASSES; i++)
-		npages += pool->size_class[i].pages_allocated;
+	u64 npages;
 
+	npages = atomic_read(&pool->pages_allocated);
 	return npages << PAGE_SHIFT;
 }
 EXPORT_SYMBOL_GPL(zs_get_total_size_bytes);
-- 
2.0.0

--
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>

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-08-17 23:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-14  1:12 [PATCH 1/3] zsmalloc: move pages_allocated to zs_pool Minchan Kim
2014-08-14  1:12 ` [PATCH 2/3] zram: limit memory size for zram Minchan Kim
2014-08-14  1:12 ` [PATCH 3/3] zram: add mem_used_max via sysfs Minchan Kim
2014-08-14 10:29   ` David Horner
2014-08-17 23:37     ` Minchan Kim
2014-08-14 15:09   ` Dan Streetman
2014-08-14 15:32     ` David Horner
2014-08-14 16:23       ` David Horner
2014-08-14 19:11         ` Dan Streetman
2014-08-14 20:07           ` David Horner
2014-08-17 23:53       ` Minchan Kim
2014-08-17 23:39     ` Minchan Kim

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).