zsmalloc: return -EAGAIN for zspage migration lock contention
Subsystems (2)
PATCH 1/1 zsmalloc: return -EAGAIN for zspage migration lock contention
From: teawater <[email protected]>
movable_operations::migrate_page() should return -EAGAIN for temporary migration failures so the migration core can retry. Other negative errors are treated as permanent failures.
zs_page_migrate() currently returns -EINVAL when zspage_write_trylock() fails. That path reflects transient lock contention, not invalid input. Returning -EINVAL misclassifies the failure and can reduce migration success under contention.
Return -EAGAIN in this path.
--- mm/zsmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/zsmalloc.c +1 -1
@@ -1727,7 +1727,7 @@ static int zs_page_migrate(struct page *newpage, struct page *page,if (!zspage_write_trylock (zspage)) {spin_unlock (&class->lock);write_unlock (&pool->lock); -return -EINVAL ; +return -EAGAIN ; }/* We're committed, tell the world that this is a Zsmalloc page. */
Signature · 1 line
2.43.0
Sergey Senozhatsky
maintainerQuoted 8 lines · Hui Zhu
movable_operations::migrate_page()should return-EAGAINfor temporary migration failures so the migration core can retry. Other negative errors are treated as permanent failures.
zs_page_migrate()currently returns-EINVALwhenzspage_write_trylock()fails. That path reflects transient lock contention, not invalid input. Returning-EINVALmisclassifies the failure and can reduce migration success under contention.
The zspage's reader-lock owner can be preempted for unknown duration, so I don't know if returning -EAGAIN is safe. On one hand, migration attempts are limited by NR_MAX_MIGRATE_PAGES_RETRY, on the other hand, those attempts are performed basically immediately (?), I'm not sure if we have good chances for preempted reader-lock owner to get scheduled and release the lock in time.
Sergey Senozhatsky
maintainerQuoted 10 lines · Sergey Senozhatsky
Quoted 8 lines · Hui Zhu
movable_operations::migrate_page()should return-EAGAINfor temporary migration failures so the migration core can retry. Other negative errors are treated as permanent failures.
zs_page_migrate()currently returns-EINVALwhenzspage_write_trylock()fails. That path reflects transient lock contention, not invalid input. Returning-EINVALmisclassifies the failure and can reduce migration success under contention.
Quoted 6 lines
The zspage's reader-lock owner can be preempted for unknown duration, so I don't know if returning
-EAGAINis safe. On one hand, migration attempts are limited byNR_MAX_MIGRATE_PAGES_RETRY, on the other hand, those attempts are performed basically immediately (?), I'm not sure if we have good chances for preempted reader-lock owner to get scheduled and release the lock in time.
.. or reader-lock owner can simply perform decompression with a very slow algorithm (e.g. deflate) which can taks significantly more time than NR_MAX_MIGRATE_PAGES_RETRY migration atteempts.
So I agree that -EINVAL is not the best error code to return here. Not sure if -EAGAIN is the best one either. Technically, -EBUSY can be a candidate (this is not exactly what migration code expects and -EBUSY is not any better than -EINVAL as it's still going to be a terminal error).