[PATCH 1/3] zpool: extend API to match zsmalloc

From: Vitaly Wool
Date: Thu Oct 10 2019 - 16:09:22 EST


This patch adds the following functions to the zpool API:
- zpool_compact()
- zpool_get_num_compacted()
- zpool_huge_class_size()

The first one triggers compaction for the underlying allocator, the
second retrieves the number of pages migrated due to compaction for
the whole time of this pool's existence and the third one returns
the huge class size.

This API extension is done to align zpool API with zsmalloc API.

Signed-off-by: Vitaly Wool <vitalywool@xxxxxxxxx>
---
include/linux/zpool.h | 14 +++++++++++++-
mm/zpool.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/include/linux/zpool.h b/include/linux/zpool.h
index 51bf43076165..31f0c1360569 100644
--- a/include/linux/zpool.h
+++ b/include/linux/zpool.h
@@ -61,8 +61,13 @@ void *zpool_map_handle(struct zpool *pool, unsigned long handle,

void zpool_unmap_handle(struct zpool *pool, unsigned long handle);

+unsigned long zpool_compact(struct zpool *pool);
+
+unsigned long zpool_get_num_compacted(struct zpool *pool);
+
u64 zpool_get_total_size(struct zpool *pool);

+size_t zpool_huge_class_size(struct zpool *zpool);

/**
* struct zpool_driver - driver implementation for zpool
@@ -75,7 +80,10 @@ u64 zpool_get_total_size(struct zpool *pool);
* @shrink: shrink the pool.
* @map: map a handle.
* @unmap: unmap a handle.
- * @total_size: get total size of a pool.
+ * @compact: try to run compaction over a pool
+ * @get_num_compacted: get amount of compacted pages for a pool
+ * @total_size: get total size of a pool
+ * @huge_class_size: huge class threshold for pool pages.
*
* This is created by a zpool implementation and registered
* with zpool.
@@ -104,7 +112,11 @@ struct zpool_driver {
enum zpool_mapmode mm);
void (*unmap)(void *pool, unsigned long handle);

+ unsigned long (*compact)(void *pool);
+ unsigned long (*get_num_compacted)(void *pool);
+
u64 (*total_size)(void *pool);
+ size_t (*huge_class_size)(void *pool);
};

void zpool_register_driver(struct zpool_driver *driver);
diff --git a/mm/zpool.c b/mm/zpool.c
index 863669212070..55e69213c2eb 100644
--- a/mm/zpool.c
+++ b/mm/zpool.c
@@ -362,6 +362,30 @@ void zpool_unmap_handle(struct zpool *zpool, unsigned long handle)
zpool->driver->unmap(zpool->pool, handle);
}

+ /**
+ * zpool_compact() - try to run compaction over zpool
+ * @pool The zpool to compact
+ *
+ * Returns: the number of migrated pages
+ */
+unsigned long zpool_compact(struct zpool *zpool)
+{
+ return zpool->driver->compact ? zpool->driver->compact(zpool->pool) : 0;
+}
+
+
+/**
+ * zpool_get_num_compacted() - get the number of migrated/compacted pages
+ * @pool The zpool to get compaction statistic for
+ *
+ * Returns: the total number of migrated pages for the pool
+ */
+unsigned long zpool_get_num_compacted(struct zpool *zpool)
+{
+ return zpool->driver->get_num_compacted ?
+ zpool->driver->get_num_compacted(zpool->pool) : 0;
+}
+
/**
* zpool_get_total_size() - The total size of the pool
* @zpool: The zpool to check
@@ -375,6 +399,18 @@ u64 zpool_get_total_size(struct zpool *zpool)
return zpool->driver->total_size(zpool->pool);
}

+/**
+ * zpool_huge_class_size() - get size for the "huge" class
+ * @pool The zpool to check
+ *
+ * Returns: size of the huge class
+ */
+size_t zpool_huge_class_size(struct zpool *zpool)
+{
+ return zpool->driver->huge_class_size ?
+ zpool->driver->huge_class_size(zpool->pool) : 0;
+}
+
/**
* zpool_evictable() - Test if zpool is potentially evictable
* @zpool: The zpool to test
--
2.20.1