All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: Prevent swap file on zoned block devices
@ 2021-05-10  6:40 Shin'ichiro Kawasaki
  2021-05-10  7:03 ` Chao Yu
  0 siblings, 1 reply; 5+ messages in thread
From: Shin'ichiro Kawasaki @ 2021-05-10  6:40 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu, linux-f2fs-devel; +Cc: Damien Le Moal

When f2fs is set up on zoned block devices, swap files on the file-
system causes unaligned write command errors. The kernel writes to the
swap files directly without the assistance of the filesystem then
it can not fulfill sequential write requirements of zoned block devices.

To avoid the errors, prevent swap file activation when the filesystem
enables block zoned device support.

Fixes: 4969c06a0d83 ("f2fs: support swap file w/ DIO")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: stable@vger.kernel.org # v5.4+
---
 fs/f2fs/data.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 96f1a354f89f..51a832efd8cd 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -4050,6 +4050,12 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
 	if (f2fs_readonly(F2FS_I_SB(inode)->sb))
 		return -EROFS;
 
+	if (f2fs_sb_has_blkzoned(F2FS_I_SB(inode))) {
+		f2fs_err(F2FS_I_SB(inode),
+			"Swapfile not supported on zoned block devices");
+		return -EINVAL;
+	}
+
 	ret = f2fs_convert_inline_inode(inode);
 	if (ret)
 		return ret;
-- 
2.30.2



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: Prevent swap file on zoned block devices
  2021-05-10  6:40 [f2fs-dev] [PATCH] f2fs: Prevent swap file on zoned block devices Shin'ichiro Kawasaki
@ 2021-05-10  7:03 ` Chao Yu
  2021-05-10  8:46   ` Shinichiro Kawasaki
  0 siblings, 1 reply; 5+ messages in thread
From: Chao Yu @ 2021-05-10  7:03 UTC (permalink / raw)
  To: Shin'ichiro Kawasaki, Jaegeuk Kim, linux-f2fs-devel; +Cc: Damien Le Moal

On 2021/5/10 14:40, Shin'ichiro Kawasaki wrote:
> When f2fs is set up on zoned block devices, swap files on the file-
> system causes unaligned write command errors. The kernel writes to the
> swap files directly without the assistance of the filesystem then
> it can not fulfill sequential write requirements of zoned block devices.
> 
> To avoid the errors, prevent swap file activation when the filesystem
> enables block zoned device support.
> 
> Fixes: 4969c06a0d83 ("f2fs: support swap file w/ DIO")
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> Cc: stable@vger.kernel.org # v5.4+
> ---
>   fs/f2fs/data.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 96f1a354f89f..51a832efd8cd 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -4050,6 +4050,12 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
>   	if (f2fs_readonly(F2FS_I_SB(inode)->sb))
>   		return -EROFS;
>   
> +	if (f2fs_sb_has_blkzoned(F2FS_I_SB(inode))) {

Should be f2fs_lfs_mode()? because all LFS mode instances will suffer
the same problem?

Thanks,

> +		f2fs_err(F2FS_I_SB(inode),
> +			"Swapfile not supported on zoned block devices");
> +		return -EINVAL;
> +	}
> +
>   	ret = f2fs_convert_inline_inode(inode);
>   	if (ret)
>   		return ret;
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: Prevent swap file on zoned block devices
  2021-05-10  7:03 ` Chao Yu
@ 2021-05-10  8:46   ` Shinichiro Kawasaki
  2021-05-10  9:03     ` Chao Yu
  0 siblings, 1 reply; 5+ messages in thread
From: Shinichiro Kawasaki @ 2021-05-10  8:46 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, Damien Le Moal, linux-f2fs-devel

On May 10, 2021 / 15:03, Chao Yu wrote:
> On 2021/5/10 14:40, Shin'ichiro Kawasaki wrote:
> > When f2fs is set up on zoned block devices, swap files on the file-
> > system causes unaligned write command errors. The kernel writes to the
> > swap files directly without the assistance of the filesystem then
> > it can not fulfill sequential write requirements of zoned block devices.
> > 
> > To avoid the errors, prevent swap file activation when the filesystem
> > enables block zoned device support.
> > 
> > Fixes: 4969c06a0d83 ("f2fs: support swap file w/ DIO")
> > Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> > Cc: stable@vger.kernel.org # v5.4+
> > ---
> >   fs/f2fs/data.c | 6 ++++++
> >   1 file changed, 6 insertions(+)
> > 
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index 96f1a354f89f..51a832efd8cd 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -4050,6 +4050,12 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
> >   	if (f2fs_readonly(F2FS_I_SB(inode)->sb))
> >   		return -EROFS;
> > +	if (f2fs_sb_has_blkzoned(F2FS_I_SB(inode))) {
> 
> Should be f2fs_lfs_mode()? because all LFS mode instances will suffer
> the same problem?

Hi Chao, thanks for the comment.

The problem this patch addresses is the unaligned write command error that
unique to zoned block devices. Non-zoned, regular block devices do not require
sequential write and do not report the error, even when kernel does
non-sequential write to the swap files.

My understanding is that LFS mode instances allow the non-sequential write to
swap files. At least, I was able to create a swap file with f2fs LFS mode on
a non-zoned device, and observed the swap file worked as swap without error.

    In this trial, I did not pin the swap file before swapon. Depending on the
    steps to prepare the swap file, the file map to blocks was unaligned to
    sections. When the file map was unaligned, swapon failed with message
    "Swapfile does not align to section". When the map was aligned, swapon
    succeeded. After that, swap file was in pinned status.

If such swap file usage with LFS mode is not expected, I will modify the patch
with f2fs_lfs_mode(). It will avoid the unaligned write command error also.

-- 
Best Regards,
Shin'ichiro Kawasaki

_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: Prevent swap file on zoned block devices
  2021-05-10  8:46   ` Shinichiro Kawasaki
@ 2021-05-10  9:03     ` Chao Yu
  2021-05-10 10:35       ` Shinichiro Kawasaki
  0 siblings, 1 reply; 5+ messages in thread
From: Chao Yu @ 2021-05-10  9:03 UTC (permalink / raw)
  To: Shinichiro Kawasaki; +Cc: Jaegeuk Kim, Damien Le Moal, linux-f2fs-devel

Hi Shinichiro,

On 2021/5/10 16:46, Shinichiro Kawasaki wrote:
> On May 10, 2021 / 15:03, Chao Yu wrote:
>> On 2021/5/10 14:40, Shin'ichiro Kawasaki wrote:
>>> When f2fs is set up on zoned block devices, swap files on the file-
>>> system causes unaligned write command errors. The kernel writes to the
>>> swap files directly without the assistance of the filesystem then
>>> it can not fulfill sequential write requirements of zoned block devices.
>>>
>>> To avoid the errors, prevent swap file activation when the filesystem
>>> enables block zoned device support.
>>>
>>> Fixes: 4969c06a0d83 ("f2fs: support swap file w/ DIO")
>>> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
>>> Cc: stable@vger.kernel.org # v5.4+
>>> ---
>>>    fs/f2fs/data.c | 6 ++++++
>>>    1 file changed, 6 insertions(+)
>>>
>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
>>> index 96f1a354f89f..51a832efd8cd 100644
>>> --- a/fs/f2fs/data.c
>>> +++ b/fs/f2fs/data.c
>>> @@ -4050,6 +4050,12 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
>>>    	if (f2fs_readonly(F2FS_I_SB(inode)->sb))
>>>    		return -EROFS;
>>> +	if (f2fs_sb_has_blkzoned(F2FS_I_SB(inode))) {
>>
>> Should be f2fs_lfs_mode()? because all LFS mode instances will suffer
>> the same problem?
> 
> Hi Chao, thanks for the comment.
> 
> The problem this patch addresses is the unaligned write command error that
> unique to zoned block devices. Non-zoned, regular block devices do not require
> sequential write and do not report the error, even when kernel does
> non-sequential write to the swap files.
> 
> My understanding is that LFS mode instances allow the non-sequential write to
> swap files. At least, I was able to create a swap file with f2fs LFS mode on
> a non-zoned device, and observed the swap file worked as swap without error.

Yes, it won't return any error because swap manager knew the L2P mapping info,
and just read or write to LBA bypassing f2fs directly.

But, IMO, it (swap manager triggers IPU) breaks LFS mode's semantics which
only allow sequential write.

> 
>      In this trial, I did not pin the swap file before swapon. Depending on the
>      steps to prepare the swap file, the file map to blocks was unaligned to
>      sections. When the file map was unaligned, swapon failed with message
>      "Swapfile does not align to section". When the map was aligned, swapon
>      succeeded. After that, swap file was in pinned status.

I guess pin feature conflicts with LFS mode...

So that I guess checking f2fs_lfs_mode() here will be more precious, right?

Thanks,

> 
> If such swap file usage with LFS mode is not expected, I will modify the patch
> with f2fs_lfs_mode(). It will avoid the unaligned write command error also.
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: Prevent swap file on zoned block devices
  2021-05-10  9:03     ` Chao Yu
@ 2021-05-10 10:35       ` Shinichiro Kawasaki
  0 siblings, 0 replies; 5+ messages in thread
From: Shinichiro Kawasaki @ 2021-05-10 10:35 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, Damien Le Moal, linux-f2fs-devel

On May 10, 2021 / 17:03, Chao Yu wrote:
> Hi Shinichiro,
> 
> On 2021/5/10 16:46, Shinichiro Kawasaki wrote:
> > On May 10, 2021 / 15:03, Chao Yu wrote:
> > > On 2021/5/10 14:40, Shin'ichiro Kawasaki wrote:
> > > > When f2fs is set up on zoned block devices, swap files on the file-
> > > > system causes unaligned write command errors. The kernel writes to the
> > > > swap files directly without the assistance of the filesystem then
> > > > it can not fulfill sequential write requirements of zoned block devices.
> > > > 
> > > > To avoid the errors, prevent swap file activation when the filesystem
> > > > enables block zoned device support.
> > > > 
> > > > Fixes: 4969c06a0d83 ("f2fs: support swap file w/ DIO")
> > > > Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> > > > Cc: stable@vger.kernel.org # v5.4+
> > > > ---
> > > >    fs/f2fs/data.c | 6 ++++++
> > > >    1 file changed, 6 insertions(+)
> > > > 
> > > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > > > index 96f1a354f89f..51a832efd8cd 100644
> > > > --- a/fs/f2fs/data.c
> > > > +++ b/fs/f2fs/data.c
> > > > @@ -4050,6 +4050,12 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
> > > >    	if (f2fs_readonly(F2FS_I_SB(inode)->sb))
> > > >    		return -EROFS;
> > > > +	if (f2fs_sb_has_blkzoned(F2FS_I_SB(inode))) {
> > > 
> > > Should be f2fs_lfs_mode()? because all LFS mode instances will suffer
> > > the same problem?
> > 
> > Hi Chao, thanks for the comment.
> > 
> > The problem this patch addresses is the unaligned write command error that
> > unique to zoned block devices. Non-zoned, regular block devices do not require
> > sequential write and do not report the error, even when kernel does
> > non-sequential write to the swap files.
> > 
> > My understanding is that LFS mode instances allow the non-sequential write to
> > swap files. At least, I was able to create a swap file with f2fs LFS mode on
> > a non-zoned device, and observed the swap file worked as swap without error.
> 
> Yes, it won't return any error because swap manager knew the L2P mapping info,
> and just read or write to LBA bypassing f2fs directly.
> 
> But, IMO, it (swap manager triggers IPU) breaks LFS mode's semantics which
> only allow sequential write.

Thanks for sharing your thoughts. I agree with your opinion above.

> 
> > 
> >      In this trial, I did not pin the swap file before swapon. Depending on the
> >      steps to prepare the swap file, the file map to blocks was unaligned to
> >      sections. When the file map was unaligned, swapon failed with message
> >      "Swapfile does not align to section". When the map was aligned, swapon
> >      succeeded. After that, swap file was in pinned status.
> 
> I guess pin feature conflicts with LFS mode...
> 
> So that I guess checking f2fs_lfs_mode() here will be more precious, right?

Okay, will post v2 with f2fs_lfs_mode().

-- 
Best Regards,
Shin'ichiro Kawasaki

_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

end of thread, other threads:[~2021-05-10 10:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10  6:40 [f2fs-dev] [PATCH] f2fs: Prevent swap file on zoned block devices Shin'ichiro Kawasaki
2021-05-10  7:03 ` Chao Yu
2021-05-10  8:46   ` Shinichiro Kawasaki
2021-05-10  9:03     ` Chao Yu
2021-05-10 10:35       ` Shinichiro Kawasaki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.