[PATCH 10/10] zsmalloc: implement zs_zpool_shrink() with zs_shrink()

From: Dan Streetman
Date: Thu Sep 11 2014 - 16:56:04 EST


Implement the zs_zpool_shrink() function, which previously just returned
EINVAL, by calling the zs_shrink() function to shrink the zs_pool by one
zspage. The zs_shrink() function is called in a loop until the requested
number of pages have been reclaimed, or an error occurs.

Signed-off-by: Dan Streetman <ddstreet@xxxxxxxx>
Cc: Minchan Kim <minchan@xxxxxxxxxx>
---
mm/zsmalloc.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index f769c21..4937b2b 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -292,7 +292,20 @@ static void zs_zpool_free(void *pool, unsigned long handle)
static int zs_zpool_shrink(void *pool, unsigned int pages,
unsigned int *reclaimed)
{
- return -EINVAL;
+ int total = 0, ret = 0;
+
+ while (total < pages) {
+ ret = zs_shrink(pool);
+ WARN_ON(!ret);
+ if (ret <= 0)
+ break;
+ total += ret;
+ ret = 0;
+ }
+
+ if (reclaimed)
+ *reclaimed = total;
+ return ret;
}

static void *zs_zpool_map(void *pool, unsigned long handle,
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/