| From: David Hildenbrand <david@redhat.com> |
| Subject: mm/zsmalloc: stop using __ClearPageMovable() |
| Date: Fri, 4 Jul 2025 12:25:06 +0200 |
| |
| Instead, let's check in the callbacks if the page was already destroyed, |
| which can be checked by looking at zpdesc->zspage (see reset_zpdesc()). |
| |
| If we detect that the page was destroyed: |
| |
| (1) Fail isolation, just like the migration core would |
| |
| (2) Fake migration success just like the migration core would |
| |
| In the putback case there is nothing to do, as we don't do anything just |
| like the migration core would do. |
| |
| In the future, we should look into not letting these pages get destroyed |
| while they are isolated -- and instead delaying that to the |
| putback/migration call. Add a TODO for that. |
| |
| Link: https://lkml.kernel.org/r/20250704102524.326966-13-david@redhat.com |
| Signed-off-by: David Hildenbrand <david@redhat.com> |
| Reviewed-by: Harry Yoo <harry.yoo@oracle.com> |
| Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> |
| Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org> |
| Cc: Alistair Popple <apopple@nvidia.com> |
| Cc: Al Viro <viro@zeniv.linux.org.uk> |
| Cc: Arnd Bergmann <arnd@arndb.de> |
| Cc: Brendan Jackman <jackmanb@google.com> |
| Cc: Byungchul Park <byungchul@sk.com> |
| Cc: Chengming Zhou <chengming.zhou@linux.dev> |
| Cc: Christian Brauner <brauner@kernel.org> |
| Cc: Christophe Leroy <christophe.leroy@csgroup.eu> |
| Cc: Eugenio Pé rez <eperezma@redhat.com> |
| Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| Cc: Gregory Price <gourry@gourry.net> |
| Cc: "Huang, Ying" <ying.huang@linux.alibaba.com> |
| Cc: Jan Kara <jack@suse.cz> |
| Cc: Jason Gunthorpe <jgg@ziepe.ca> |
| Cc: Jason Wang <jasowang@redhat.com> |
| Cc: Jerrin Shaji George <jerrin.shaji-george@broadcom.com> |
| Cc: Johannes Weiner <hannes@cmpxchg.org> |
| Cc: John Hubbard <jhubbard@nvidia.com> |
| Cc: Jonathan Corbet <corbet@lwn.net> |
| Cc: Joshua Hahn <joshua.hahnjy@gmail.com> |
| Cc: Liam Howlett <liam.howlett@oracle.com> |
| Cc: Madhavan Srinivasan <maddy@linux.ibm.com> |
| Cc: Mathew Brost <matthew.brost@intel.com> |
| Cc: Matthew Wilcox (Oracle) <willy@infradead.org> |
| Cc: Miaohe Lin <linmiaohe@huawei.com> |
| Cc: Michael Ellerman <mpe@ellerman.id.au> |
| Cc: "Michael S. Tsirkin" <mst@redhat.com> |
| Cc: Michal Hocko <mhocko@suse.com> |
| Cc: Mike Rapoport <rppt@kernel.org> |
| Cc: Minchan Kim <minchan@kernel.org> |
| Cc: Naoya Horiguchi <nao.horiguchi@gmail.com> |
| Cc: Nicholas Piggin <npiggin@gmail.com> |
| Cc: Oscar Salvador <osalvador@suse.de> |
| Cc: Peter Xu <peterx@redhat.com> |
| Cc: Qi Zheng <zhengqi.arch@bytedance.com> |
| Cc: Rakie Kim <rakie.kim@sk.com> |
| Cc: Rik van Riel <riel@surriel.com> |
| Cc: Shakeel Butt <shakeel.butt@linux.dev> |
| Cc: Suren Baghdasaryan <surenb@google.com> |
| Cc: Vlastimil Babka <vbabka@suse.cz> |
| Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com> |
| Cc: xu xin <xu.xin16@zte.com.cn> |
| Cc: Zi Yan <ziy@nvidia.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| mm/zsmalloc.c | 18 ++++++++++++++---- |
| 1 file changed, 14 insertions(+), 4 deletions(-) |
| |
| --- a/mm/zsmalloc.c~mm-zsmalloc-stop-using-__clearpagemovable |
| +++ a/mm/zsmalloc.c |
| @@ -877,7 +877,6 @@ static void reset_zpdesc(struct zpdesc * |
| { |
| struct page *page = zpdesc_page(zpdesc); |
| |
| - __ClearPageMovable(page); |
| ClearPagePrivate(page); |
| zpdesc->zspage = NULL; |
| zpdesc->next = NULL; |
| @@ -1716,10 +1715,11 @@ static void replace_sub_page(struct size |
| static bool zs_page_isolate(struct page *page, isolate_mode_t mode) |
| { |
| /* |
| - * Page is locked so zspage couldn't be destroyed. For detail, look at |
| - * lock_zspage in free_zspage. |
| + * Page is locked so zspage can't be destroyed concurrently |
| + * (see free_zspage()). But if the page was already destroyed |
| + * (see reset_zpdesc()), refuse isolation here. |
| */ |
| - return true; |
| + return page_zpdesc(page)->zspage; |
| } |
| |
| static int zs_page_migrate(struct page *newpage, struct page *page, |
| @@ -1737,6 +1737,16 @@ static int zs_page_migrate(struct page * |
| unsigned long old_obj, new_obj; |
| unsigned int obj_idx; |
| |
| + /* |
| + * TODO: nothing prevents a zspage from getting destroyed while |
| + * it is isolated for migration, as the page lock is temporarily |
| + * dropped after zs_page_isolate() succeeded: we should rework that |
| + * and defer destroying such pages once they are un-isolated (putback) |
| + * instead. |
| + */ |
| + if (!zpdesc->zspage) |
| + return MIGRATEPAGE_SUCCESS; |
| + |
| /* The page is locked, so this pointer must remain valid */ |
| zspage = get_zspage(zpdesc); |
| pool = zspage->pool; |
| _ |