From: Xueyuan Chen <[email protected]>
Allow pool compaction to stop after reclaiming a requested number of
pages. This prepares it for budgeted callers while keeping zs_compact()
behavior unchanged.
Signed-off-by: Xueyuan Chen <[email protected]>
---
mm/zsmalloc.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 83f5820c45f9..334d24093c64 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1884,7 +1884,8 @@ static unsigned long zs_can_compact(struct size_class *class)
}
static unsigned long __zs_compact(struct zs_pool *pool,
- struct size_class *class)
+ struct size_class *class,
+ unsigned long max_pages)
{
struct zspage *src_zspage = NULL;
struct zspage *dst_zspage = NULL;
@@ -1896,7 +1897,7 @@ static unsigned long __zs_compact(struct zs_pool *pool,
*/
write_lock(&pool->lock);
spin_lock(&class->lock);
- while (zs_can_compact(class)) {
+ while ((pages_freed < max_pages) && zs_can_compact(class)) {
int fg;
if (!dst_zspage) {
@@ -1947,12 +1948,16 @@ static unsigned long __zs_compact(struct zs_pool *pool,
return pages_freed;
}
-unsigned long zs_compact(struct zs_pool *pool)
+static unsigned long zs_compact_pool(struct zs_pool *pool,
+ unsigned long max_pages)
{
int i;
struct size_class *class;
unsigned long pages_freed = 0;
+ if (!max_pages)
+ return 0;
+
/*
* Pool compaction is performed under pool->lock so it is basically
* single-threaded. Having more than one thread in __zs_compact()
@@ -1966,13 +1971,21 @@ unsigned long zs_compact(struct zs_pool *pool)
class = pool->size_class[i];
if (class->index != i)
continue;
- pages_freed += __zs_compact(pool, class);
+ pages_freed += __zs_compact(pool, class,
+ max_pages - pages_freed);
+ if (pages_freed >= max_pages)
+ break;
}
atomic_long_add(pages_freed, &pool->stats.pages_compacted);
atomic_set(&pool->compaction_in_progress, 0);
return pages_freed;
}
+
+unsigned long zs_compact(struct zs_pool *pool)
+{
+ return zs_compact_pool(pool, ULONG_MAX);
+}
EXPORT_SYMBOL_GPL(zs_compact);
void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats)
--
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.