Skip to contentSkip to conversation

Implement writeback for zsmalloc (fix)

PATCH Superseded Nhat Pham 1 participant 3 messages Nov 23, 2022

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Nhat Pham

author
#0 lore raw

v6 cover Implement writeback for zsmalloc (fix)

This contains two small fixes that should be applied on top of patch 4 and patch 6 of my zsmalloc writeback series, respectively.

Changelog:
v6-fix:
* Add a comment explaining LRU update logic in zs_map_object. (patch 4)
(sugegested by Sergey Senozhatsky and Johannes Weiner).
* Use get_first_page() and add cond_resched() in retry-loop. (patch 6) (sugegested by Sergey Senozhatsky).
v6:
* Move the move-to-front logic into zs_map_object (patch 4) (suggested by Minchan Kim).
* Small clean up for free_zspage at free_handles() call site (patch 6) (suggested by Minchan Kim).
v5:
* Add a new patch that eliminates unused code in zpool and simplify the logic for storing evict handler in zbud/z3fold (patch 2)
* Remove redudant fields in zs_pool (previously required by zpool)

    (patch 3)

* Wrap under_reclaim and deferred handle freeing logic in CONFIG_ZPOOL (patch 6) (suggested by Minchan Kim)
* Move a small piece of refactoring from patch 6 to patch 4.
v4:
* Wrap the new LRU logic in CONFIG_ZPOOL (patch 3). (suggested by Minchan Kim)
v3:
* Set pool->ops = NULL when pool->zpool_ops is null (patch 4).
* Stop holding pool's lock when calling lock_zspage() (patch 5). (suggested by Sergey Senozhatsky)
* Stop holding pool's lock when checking pool->ops and retries. (patch 5) (suggested by Sergey Senozhatsky)
* Fix formatting issues (.shrink, extra spaces in casting removed). (patch 5) (suggested by Sergey Senozhatsky)
v2:
* Add missing CONFIG_ZPOOL ifdefs (patch 5)
(detected by kernel test robot).

--
2.30.2

author
#1 lore raw

PATCH v6 4/6 zsmalloc: Add a LRU to zs_pool to keep track of zspages in LRU order (fix)

Add a comment explaining the mapping check for LRU update.

---
 mm/zsmalloc.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
mm/zsmalloc.c +17 -1
index 7dd464b5a6a5..d9bd865047e2 100644
@@ -1268,7 +1268,23 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle,
 	zspage = get_zspage(page);
 
 #ifdef CONFIG_ZPOOL
-	/* Move the zspage to front of pool's LRU */
+	/*
+	 * Move the zspage to front of pool's LRU.
+	 *
+	 * Note that this is swap-specific, so by definition there are no ongoing
+	 * accesses to the memory while the page is swapped out that would make
+	 * it "hot". A new entry is hot, then ages to the tail until it gets either
+	 * written back or swaps back in.
+	 *
+	 * Furthermore, map is also called during writeback. We must not put an
+	 * isolated page on the LRU mid-reclaim.
+	 *
+	 * As a result, only update the LRU when the page is mapped for write
+	 * when it's first instantiated.
+	 *
+	 * This is a deviation from the other backends, which perform this update
+	 * in the allocation function (zbud_alloc, z3fold_alloc).
+	 */
 	if (mm == ZS_MM_WO) {
 		if (!list_empty(&zspage->lru))
 			list_del(&zspage->lru);

--
2.30.2

author
#2 lore raw

PATCH v6 6/6 zsmalloc: Implement writeback mechanism for zsmalloc (fix)

In reply to Nhat Pham

Use get_first_page(), and add cond_resched() in retry loop.

---
 mm/zsmalloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/zsmalloc.c +2 -1
index e2bd41f37b5b..ab4fa17a0fad 100644
@@ -2488,12 +2488,13 @@ static int zs_reclaim_page(struct zs_pool *pool, unsigned int retries)
 		remove_zspage(class, zspage, fullness);
 
 		spin_unlock(&pool->lock);
+		cond_resched();
 
 		/* Lock backing pages into place */
 		lock_zspage(zspage);
 
 		obj_idx = 0;
-		page = zspage->first_page;
+		page = get_first_page(zspage);
 		while (1) {
 			handle = find_alloced_obj(class, page, &obj_idx);
 			if (!handle) {

--
2.30.2