linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] mm/shmem: fix shmem folio swapoff hang
@ 2022-05-22  2:53 Hugh Dickins
  2022-05-23  1:50 ` Miaohe Lin
  0 siblings, 1 reply; 2+ messages in thread
From: Hugh Dickins @ 2022-05-22  2:53 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: Andrew Morton, linux-kernel, linux-mm

Shmem swapoff makes no progress: the index to indices is not incremented.
But "ret" is no longer a return value, so use folio_batch_count() instead.

Fixes: da08e9b79323 ("mm/shmem: convert shmem_swapin_page() to shmem_swapin_folio()")
Signed-off-by: Hugh Dickins <hughd@google.com>
---

 mm/shmem.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1171,7 +1171,6 @@ static int shmem_find_swap_entries(struc
 	XA_STATE(xas, &mapping->i_pages, start);
 	struct folio *folio;
 	swp_entry_t entry;
-	unsigned int ret = 0;
 
 	rcu_read_lock();
 	xas_for_each(&xas, folio, ULONG_MAX) {
@@ -1189,7 +1188,7 @@ static int shmem_find_swap_entries(struc
 		if (swp_type(entry) != type)
 			continue;
 
-		indices[ret] = xas.xa_index;
+		indices[folio_batch_count(fbatch)] = xas.xa_index;
 		if (!folio_batch_add(fbatch, folio))
 			break;
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH next] mm/shmem: fix shmem folio swapoff hang
  2022-05-22  2:53 [PATCH next] mm/shmem: fix shmem folio swapoff hang Hugh Dickins
@ 2022-05-23  1:50 ` Miaohe Lin
  0 siblings, 0 replies; 2+ messages in thread
From: Miaohe Lin @ 2022-05-23  1:50 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: Andrew Morton, linux-kernel, linux-mm, Matthew Wilcox

On 2022/5/22 10:53, Hugh Dickins wrote:
> Shmem swapoff makes no progress: the index to indices is not incremented.

Yes, there would be a infinite loop in the while loop in shmem_unuse_inode().

> But "ret" is no longer a return value, so use folio_batch_count() instead.
> 
> Fixes: da08e9b79323 ("mm/shmem: convert shmem_swapin_page() to shmem_swapin_folio()")
> Signed-off-by: Hugh Dickins <hughd@google.com>

This patch looks good to me! Thanks!

Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Tested-by: Miaohe Lin <linmiaohe@huawei.com>

BTW: When I try to fix infinite loop when swap in shmem error at swapoff time, I also found this
issue last Saturday [1]. ;)

[1] https://lore.kernel.org/linux-mm/0f6dc98b-88f4-c0c9-eb7b-5356ad0e08b1@huawei.com/

> ---
> 
>  mm/shmem.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1171,7 +1171,6 @@ static int shmem_find_swap_entries(struc
>  	XA_STATE(xas, &mapping->i_pages, start);
>  	struct folio *folio;
>  	swp_entry_t entry;
> -	unsigned int ret = 0;
>  
>  	rcu_read_lock();
>  	xas_for_each(&xas, folio, ULONG_MAX) {
> @@ -1189,7 +1188,7 @@ static int shmem_find_swap_entries(struc
>  		if (swp_type(entry) != type)
>  			continue;
>  
> -		indices[ret] = xas.xa_index;
> +		indices[folio_batch_count(fbatch)] = xas.xa_index;
>  		if (!folio_batch_add(fbatch, folio))
>  			break;
>  
> 
> .
> 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-23  1:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-22  2:53 [PATCH next] mm/shmem: fix shmem folio swapoff hang Hugh Dickins
2022-05-23  1:50 ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).