[PATCH][G/Unstable] ext4: implement swap_activate aops using iomap

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH][G/Unstable] ext4: implement swap_activate aops using iomap

Seth Forshee
From: Ritesh Harjani <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1892728

After moving ext4's bmap to iomap interface, swapon functionality
on files created using fallocate (which creates unwritten extents) are
failing. This is since iomap_bmap interface returns 0 for unwritten
extents and thus generic_swapfile_activate considers this as holes
and hence bail out with below kernel msg :-

[340.915835] swapon: swapfile has holes

To fix this we need to implement ->swap_activate aops in ext4
which will use ext4_iomap_report_ops. Since we only need to return
the list of extents so ext4_iomap_report_ops should be enough.

Reported-by: Yuxuan Shui <[hidden email]>
Fixes: ac58e4fb03f ("ext4: move ext4 bmap to use iomap infrastructure")
Signed-off-by: Ritesh Harjani <[hidden email]>
Link: https://lore.kernel.org/r/20200904091653.1014334-1-riteshh@...
Signed-off-by: Theodore Ts'o <[hidden email]>
(cherry picked from commit 424de74af0d0679e99660904a5f472acd85bdb73 linux-next)
Signed-off-by: Seth Forshee <[hidden email]>
---
 fs/ext4/inode.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9c0629ffb426..30177c5a9b97 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3601,6 +3601,13 @@ static int ext4_set_page_dirty(struct page *page)
  return __set_page_dirty_buffers(page);
 }
 
+static int ext4_iomap_swap_activate(struct swap_info_struct *sis,
+    struct file *file, sector_t *span)
+{
+ return iomap_swapfile_activate(sis, file, span,
+       &ext4_iomap_report_ops);
+}
+
 static const struct address_space_operations ext4_aops = {
  .readpage = ext4_readpage,
  .readahead = ext4_readahead,
@@ -3616,6 +3623,7 @@ static const struct address_space_operations ext4_aops = {
  .migratepage = buffer_migrate_page,
  .is_partially_uptodate  = block_is_partially_uptodate,
  .error_remove_page = generic_error_remove_page,
+ .swap_activate = ext4_iomap_swap_activate,
 };
 
 static const struct address_space_operations ext4_journalled_aops = {
@@ -3632,6 +3640,7 @@ static const struct address_space_operations ext4_journalled_aops = {
  .direct_IO = noop_direct_IO,
  .is_partially_uptodate  = block_is_partially_uptodate,
  .error_remove_page = generic_error_remove_page,
+ .swap_activate = ext4_iomap_swap_activate,
 };
 
 static const struct address_space_operations ext4_da_aops = {
@@ -3649,6 +3658,7 @@ static const struct address_space_operations ext4_da_aops = {
  .migratepage = buffer_migrate_page,
  .is_partially_uptodate  = block_is_partially_uptodate,
  .error_remove_page = generic_error_remove_page,
+ .swap_activate = ext4_iomap_swap_activate,
 };
 
 static const struct address_space_operations ext4_dax_aops = {
@@ -3657,6 +3667,7 @@ static const struct address_space_operations ext4_dax_aops = {
  .set_page_dirty = noop_set_page_dirty,
  .bmap = ext4_bmap,
  .invalidatepage = noop_invalidatepage,
+ .swap_activate = ext4_iomap_swap_activate,
 };
 
 void ext4_set_aops(struct inode *inode)
--
2.27.0


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [PATCH][G/Unstable] ext4: implement swap_activate aops using iomap

Andrea Righi
On Wed, Oct 14, 2020 at 03:32:32PM -0500, Seth Forshee wrote:

> From: Ritesh Harjani <[hidden email]>
>
> BugLink: https://bugs.launchpad.net/bugs/1892728
>
> After moving ext4's bmap to iomap interface, swapon functionality
> on files created using fallocate (which creates unwritten extents) are
> failing. This is since iomap_bmap interface returns 0 for unwritten
> extents and thus generic_swapfile_activate considers this as holes
> and hence bail out with below kernel msg :-
>
> [340.915835] swapon: swapfile has holes
>
> To fix this we need to implement ->swap_activate aops in ext4
> which will use ext4_iomap_report_ops. Since we only need to return
> the list of extents so ext4_iomap_report_ops should be enough.
>
> Reported-by: Yuxuan Shui <[hidden email]>
> Fixes: ac58e4fb03f ("ext4: move ext4 bmap to use iomap infrastructure")
> Signed-off-by: Ritesh Harjani <[hidden email]>
> Link: https://lore.kernel.org/r/20200904091653.1014334-1-riteshh@...
> Signed-off-by: Theodore Ts'o <[hidden email]>
> (cherry picked from commit 424de74af0d0679e99660904a5f472acd85bdb73 linux-next)
> Signed-off-by: Seth Forshee <[hidden email]>

The fix looks pretty safe to me and it prevents breaking swap files on
ext4. I tested it with the latest AWS kernel (hibernation) with positive
results.

Acked-by: Andrea Righi <[hidden email]>

> ---
>  fs/ext4/inode.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 9c0629ffb426..30177c5a9b97 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3601,6 +3601,13 @@ static int ext4_set_page_dirty(struct page *page)
>   return __set_page_dirty_buffers(page);
>  }
>  
> +static int ext4_iomap_swap_activate(struct swap_info_struct *sis,
> +    struct file *file, sector_t *span)
> +{
> + return iomap_swapfile_activate(sis, file, span,
> +       &ext4_iomap_report_ops);
> +}
> +
>  static const struct address_space_operations ext4_aops = {
>   .readpage = ext4_readpage,
>   .readahead = ext4_readahead,
> @@ -3616,6 +3623,7 @@ static const struct address_space_operations ext4_aops = {
>   .migratepage = buffer_migrate_page,
>   .is_partially_uptodate  = block_is_partially_uptodate,
>   .error_remove_page = generic_error_remove_page,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  static const struct address_space_operations ext4_journalled_aops = {
> @@ -3632,6 +3640,7 @@ static const struct address_space_operations ext4_journalled_aops = {
>   .direct_IO = noop_direct_IO,
>   .is_partially_uptodate  = block_is_partially_uptodate,
>   .error_remove_page = generic_error_remove_page,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  static const struct address_space_operations ext4_da_aops = {
> @@ -3649,6 +3658,7 @@ static const struct address_space_operations ext4_da_aops = {
>   .migratepage = buffer_migrate_page,
>   .is_partially_uptodate  = block_is_partially_uptodate,
>   .error_remove_page = generic_error_remove_page,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  static const struct address_space_operations ext4_dax_aops = {
> @@ -3657,6 +3667,7 @@ static const struct address_space_operations ext4_dax_aops = {
>   .set_page_dirty = noop_set_page_dirty,
>   .bmap = ext4_bmap,
>   .invalidatepage = noop_invalidatepage,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  void ext4_set_aops(struct inode *inode)
> --
> 2.27.0
>
>
> --
> kernel-team mailing list
> [hidden email]
> https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [PATCH][G/Unstable] ext4: implement swap_activate aops using iomap

Kelsey Skunberg
In reply to this post by Seth Forshee
Clean cherry pick. lgtm

Acked-by: Kelsey Skunberg <[hidden email]>

On 2020-10-14 15:32:32 , Seth Forshee wrote:

> From: Ritesh Harjani <[hidden email]>
>
> BugLink: https://bugs.launchpad.net/bugs/1892728
>
> After moving ext4's bmap to iomap interface, swapon functionality
> on files created using fallocate (which creates unwritten extents) are
> failing. This is since iomap_bmap interface returns 0 for unwritten
> extents and thus generic_swapfile_activate considers this as holes
> and hence bail out with below kernel msg :-
>
> [340.915835] swapon: swapfile has holes
>
> To fix this we need to implement ->swap_activate aops in ext4
> which will use ext4_iomap_report_ops. Since we only need to return
> the list of extents so ext4_iomap_report_ops should be enough.
>
> Reported-by: Yuxuan Shui <[hidden email]>
> Fixes: ac58e4fb03f ("ext4: move ext4 bmap to use iomap infrastructure")
> Signed-off-by: Ritesh Harjani <[hidden email]>
> Link: https://lore.kernel.org/r/20200904091653.1014334-1-riteshh@...
> Signed-off-by: Theodore Ts'o <[hidden email]>
> (cherry picked from commit 424de74af0d0679e99660904a5f472acd85bdb73 linux-next)
> Signed-off-by: Seth Forshee <[hidden email]>
> ---
>  fs/ext4/inode.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 9c0629ffb426..30177c5a9b97 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3601,6 +3601,13 @@ static int ext4_set_page_dirty(struct page *page)
>   return __set_page_dirty_buffers(page);
>  }
>  
> +static int ext4_iomap_swap_activate(struct swap_info_struct *sis,
> +    struct file *file, sector_t *span)
> +{
> + return iomap_swapfile_activate(sis, file, span,
> +       &ext4_iomap_report_ops);
> +}
> +
>  static const struct address_space_operations ext4_aops = {
>   .readpage = ext4_readpage,
>   .readahead = ext4_readahead,
> @@ -3616,6 +3623,7 @@ static const struct address_space_operations ext4_aops = {
>   .migratepage = buffer_migrate_page,
>   .is_partially_uptodate  = block_is_partially_uptodate,
>   .error_remove_page = generic_error_remove_page,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  static const struct address_space_operations ext4_journalled_aops = {
> @@ -3632,6 +3640,7 @@ static const struct address_space_operations ext4_journalled_aops = {
>   .direct_IO = noop_direct_IO,
>   .is_partially_uptodate  = block_is_partially_uptodate,
>   .error_remove_page = generic_error_remove_page,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  static const struct address_space_operations ext4_da_aops = {
> @@ -3649,6 +3658,7 @@ static const struct address_space_operations ext4_da_aops = {
>   .migratepage = buffer_migrate_page,
>   .is_partially_uptodate  = block_is_partially_uptodate,
>   .error_remove_page = generic_error_remove_page,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  static const struct address_space_operations ext4_dax_aops = {
> @@ -3657,6 +3667,7 @@ static const struct address_space_operations ext4_dax_aops = {
>   .set_page_dirty = noop_set_page_dirty,
>   .bmap = ext4_bmap,
>   .invalidatepage = noop_invalidatepage,
> + .swap_activate = ext4_iomap_swap_activate,
>  };
>  
>  void ext4_set_aops(struct inode *inode)
> --
> 2.27.0
>
>
> --
> kernel-team mailing list
> [hidden email]
> https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team