linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] f2fs: let's allow compression for mmap files
@ 2021-05-25 20:49 Jaegeuk Kim
  2021-05-25 20:49 ` [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit Jaegeuk Kim
  2021-05-26  9:09 ` [f2fs-dev] [PATCH 1/2] f2fs: let's allow compression for mmap files Chao Yu
  0 siblings, 2 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2021-05-25 20:49 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim

This patch allows to compress mmap files. E.g., for so files.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/compress.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 1189740aa141..bec92ff5ee7d 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -955,8 +955,6 @@ static bool cluster_may_compress(struct compress_ctx *cc)
 		return false;
 	if (f2fs_is_atomic_file(cc->inode))
 		return false;
-	if (f2fs_is_mmap_file(cc->inode))
-		return false;
 	if (!f2fs_cluster_is_full(cc))
 		return false;
 	if (unlikely(f2fs_cp_error(F2FS_I_SB(cc->inode))))
-- 
2.32.0.rc0.204.g9fa02ecfa5-goog


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

* [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit
  2021-05-25 20:49 [PATCH 1/2] f2fs: let's allow compression for mmap files Jaegeuk Kim
@ 2021-05-25 20:49 ` Jaegeuk Kim
  2021-06-06 13:53   ` [f2fs-dev] " Chao Yu
  2021-05-26  9:09 ` [f2fs-dev] [PATCH 1/2] f2fs: let's allow compression for mmap files Chao Yu
  1 sibling, 1 reply; 8+ messages in thread
From: Jaegeuk Kim @ 2021-05-25 20:49 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim

Once we release compressed blocks, we used to set IMMUTABLE bit. But it turned
out it disallows every fs operations which we don't need for compression.

Let's just prevent writing data only.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/compress.c      |  3 ++-
 fs/f2fs/f2fs.h          |  6 ++++++
 fs/f2fs/file.c          | 18 ++++++++++++------
 include/linux/f2fs_fs.h |  1 +
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index bec92ff5ee7d..1c3e98085591 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -928,7 +928,8 @@ static int __f2fs_cluster_blocks(struct inode *inode,
 		}
 
 		f2fs_bug_on(F2FS_I_SB(inode),
-			!compr && ret != cluster_size && !IS_IMMUTABLE(inode));
+			!compr && ret != cluster_size &&
+			!is_inode_flag_set(inode, FI_COMPRESS_RELEASED));
 	}
 fail:
 	f2fs_put_dnode(&dn);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 2c6913261586..9ad502f92529 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -707,6 +707,7 @@ enum {
 	FI_COMPRESS_CORRUPT,	/* indicate compressed cluster is corrupted */
 	FI_MMAP_FILE,		/* indicate file was mmapped */
 	FI_ENABLE_COMPRESS,	/* enable compression in "user" compression mode */
+	FI_COMPRESS_RELEASED,	/* compressed blocks were released */
 	FI_MAX,			/* max flag, never be used */
 };
 
@@ -2748,6 +2749,7 @@ static inline void __mark_inode_dirty_flag(struct inode *inode,
 	case FI_DATA_EXIST:
 	case FI_INLINE_DOTS:
 	case FI_PIN_FILE:
+	case FI_COMPRESS_RELEASED:
 		f2fs_mark_inode_dirty_sync(inode, true);
 	}
 }
@@ -2869,6 +2871,8 @@ static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
 		set_bit(FI_EXTRA_ATTR, fi->flags);
 	if (ri->i_inline & F2FS_PIN_FILE)
 		set_bit(FI_PIN_FILE, fi->flags);
+	if (ri->i_inline & F2FS_COMPRESS_RELEASED)
+		set_bit(FI_COMPRESS_RELEASED, fi->flags);
 }
 
 static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
@@ -2889,6 +2893,8 @@ static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
 		ri->i_inline |= F2FS_EXTRA_ATTR;
 	if (is_inode_flag_set(inode, FI_PIN_FILE))
 		ri->i_inline |= F2FS_PIN_FILE;
+	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
+		ri->i_inline |= F2FS_COMPRESS_RELEASED;
 }
 
 static inline int f2fs_has_extra_attr(struct inode *inode)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4a8c3128b5a5..4714925e1974 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -63,6 +63,9 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 	if (unlikely(IS_IMMUTABLE(inode)))
 		return VM_FAULT_SIGBUS;
 
+	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
+		return VM_FAULT_SIGBUS;
+
 	if (unlikely(f2fs_cp_error(sbi))) {
 		err = -EIO;
 		goto err;
@@ -3420,7 +3423,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
 		goto out;
 	}
 
-	if (IS_IMMUTABLE(inode)) {
+	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
 		ret = -EINVAL;
 		goto out;
 	}
@@ -3429,8 +3432,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
 	if (ret)
 		goto out;
 
-	F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL;
-	f2fs_set_inode_flags(inode);
+	set_inode_flag(inode, FI_COMPRESS_RELEASED);
 	inode->i_ctime = current_time(inode);
 	f2fs_mark_inode_dirty_sync(inode, true);
 
@@ -3585,7 +3587,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
 
 	inode_lock(inode);
 
-	if (!IS_IMMUTABLE(inode)) {
+	if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
 		ret = -EINVAL;
 		goto unlock_inode;
 	}
@@ -3630,8 +3632,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
 	up_write(&F2FS_I(inode)->i_mmap_sem);
 
 	if (ret >= 0) {
-		F2FS_I(inode)->i_flags &= ~F2FS_IMMUTABLE_FL;
-		f2fs_set_inode_flags(inode);
+		clear_inode_flag(inode, FI_COMPRESS_RELEASED);
 		inode->i_ctime = current_time(inode);
 		f2fs_mark_inode_dirty_sync(inode, true);
 	}
@@ -4249,6 +4250,11 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 		goto unlock;
 	}
 
+	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
+		ret = -EPERM;
+		goto unlock;
+	}
+
 	ret = generic_write_checks(iocb, from);
 	if (ret > 0) {
 		bool preallocated = false;
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 5487a80617a3..f93000c3a127 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -229,6 +229,7 @@ struct f2fs_extent {
 #define F2FS_INLINE_DOTS	0x10	/* file having implicit dot dentries */
 #define F2FS_EXTRA_ATTR		0x20	/* file having extra attribute */
 #define F2FS_PIN_FILE		0x40	/* file should not be gced */
+#define F2FS_COMPRESS_RELEASED	0x80	/* file released compressed blocks */
 
 struct f2fs_inode {
 	__le16 i_mode;			/* file mode */
-- 
2.32.0.rc0.204.g9fa02ecfa5-goog


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

* Re: [f2fs-dev] [PATCH 1/2] f2fs: let's allow compression for mmap files
  2021-05-25 20:49 [PATCH 1/2] f2fs: let's allow compression for mmap files Jaegeuk Kim
  2021-05-25 20:49 ` [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit Jaegeuk Kim
@ 2021-05-26  9:09 ` Chao Yu
  1 sibling, 0 replies; 8+ messages in thread
From: Chao Yu @ 2021-05-26  9:09 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel

On 2021/5/26 4:49, Jaegeuk Kim wrote:
> This patch allows to compress mmap files. E.g., for so files.
> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

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

* Re: [f2fs-dev] [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit
  2021-05-25 20:49 ` [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit Jaegeuk Kim
@ 2021-06-06 13:53   ` Chao Yu
  2021-06-07 16:56     ` Jaegeuk Kim
  0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2021-06-06 13:53 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel

On 2021/5/26 4:49, Jaegeuk Kim wrote:
> Once we release compressed blocks, we used to set IMMUTABLE bit. But it turned
> out it disallows every fs operations which we don't need for compression.
> 
> Let's just prevent writing data only.
> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

BTW, we need to expose .i_inline field to userspace since there is no
way to check status of inode whether it has released blocks?

Thanks,


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

* Re: [f2fs-dev] [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit
  2021-06-06 13:53   ` [f2fs-dev] " Chao Yu
@ 2021-06-07 16:56     ` Jaegeuk Kim
  2021-06-07 23:17       ` Chao Yu
  0 siblings, 1 reply; 8+ messages in thread
From: Jaegeuk Kim @ 2021-06-07 16:56 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

On 06/06, Chao Yu wrote:
> On 2021/5/26 4:49, Jaegeuk Kim wrote:
> > Once we release compressed blocks, we used to set IMMUTABLE bit. But it turned
> > out it disallows every fs operations which we don't need for compression.
> > 
> > Let's just prevent writing data only.
> > 
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> 
> Reviewed-by: Chao Yu <yuchao0@huawei.com>
> 
> BTW, we need to expose .i_inline field to userspace since there is no
> way to check status of inode whether it has released blocks?

Need to add some in F2FS_IOC_GET_COMPRESS_OPTION?

> 
> Thanks,

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

* Re: [f2fs-dev] [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit
  2021-06-07 16:56     ` Jaegeuk Kim
@ 2021-06-07 23:17       ` Chao Yu
  2021-06-09 18:43         ` Jaegeuk Kim
  0 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2021-06-07 23:17 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-kernel, linux-f2fs-devel

On 2021/6/8 0:56, Jaegeuk Kim wrote:
> On 06/06, Chao Yu wrote:
>> On 2021/5/26 4:49, Jaegeuk Kim wrote:
>>> Once we release compressed blocks, we used to set IMMUTABLE bit. But it turned
>>> out it disallows every fs operations which we don't need for compression.
>>>
>>> Let's just prevent writing data only.
>>>
>>> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
>>
>> Reviewed-by: Chao Yu <yuchao0@huawei.com>
>>
>> BTW, we need to expose .i_inline field to userspace since there is no
>> way to check status of inode whether it has released blocks?
> 
> Need to add some in F2FS_IOC_GET_COMPRESS_OPTION?

We should not change this interface, in order to keep its compatibility for
userspace usage. How about adding it in F2FS_IOC_GET_COMPRESS_OPTION_EX?

Thanks,

> 
>>
>> Thanks,

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

* Re: [f2fs-dev] [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit
  2021-06-07 23:17       ` Chao Yu
@ 2021-06-09 18:43         ` Jaegeuk Kim
  2021-06-10 15:24           ` Chao Yu
  0 siblings, 1 reply; 8+ messages in thread
From: Jaegeuk Kim @ 2021-06-09 18:43 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel

On 06/08, Chao Yu wrote:
> On 2021/6/8 0:56, Jaegeuk Kim wrote:
> > On 06/06, Chao Yu wrote:
> > > On 2021/5/26 4:49, Jaegeuk Kim wrote:
> > > > Once we release compressed blocks, we used to set IMMUTABLE bit. But it turned
> > > > out it disallows every fs operations which we don't need for compression.
> > > > 
> > > > Let's just prevent writing data only.
> > > > 
> > > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > > 
> > > Reviewed-by: Chao Yu <yuchao0@huawei.com>
> > > 
> > > BTW, we need to expose .i_inline field to userspace since there is no
> > > way to check status of inode whether it has released blocks?
> > 
> > Need to add some in F2FS_IOC_GET_COMPRESS_OPTION?
> 
> We should not change this interface, in order to keep its compatibility for
> userspace usage. How about adding it in F2FS_IOC_GET_COMPRESS_OPTION_EX?

Hmm, or need to add it in getflags?

> 
> Thanks,
> 
> > 
> > > 
> > > Thanks,

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

* Re: [f2fs-dev] [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit
  2021-06-09 18:43         ` Jaegeuk Kim
@ 2021-06-10 15:24           ` Chao Yu
  0 siblings, 0 replies; 8+ messages in thread
From: Chao Yu @ 2021-06-10 15:24 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-kernel, linux-f2fs-devel

On 2021/6/10 2:43, Jaegeuk Kim wrote:
> On 06/08, Chao Yu wrote:
>> On 2021/6/8 0:56, Jaegeuk Kim wrote:
>>> On 06/06, Chao Yu wrote:
>>>> On 2021/5/26 4:49, Jaegeuk Kim wrote:
>>>>> Once we release compressed blocks, we used to set IMMUTABLE bit. But it turned
>>>>> out it disallows every fs operations which we don't need for compression.
>>>>>
>>>>> Let's just prevent writing data only.
>>>>>
>>>>> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
>>>>
>>>> Reviewed-by: Chao Yu <yuchao0@huawei.com>
>>>>
>>>> BTW, we need to expose .i_inline field to userspace since there is no
>>>> way to check status of inode whether it has released blocks?
>>>
>>> Need to add some in F2FS_IOC_GET_COMPRESS_OPTION?
>>
>> We should not change this interface, in order to keep its compatibility for
>> userspace usage. How about adding it in F2FS_IOC_GET_COMPRESS_OPTION_EX?
> 
> Hmm, or need to add it in getflags?

Not sure whether the flag may conflict with the bit FS_*_FL used in
lsattr/chattr.

Thanks,

> 
>>
>> Thanks,
>>
>>>
>>>>
>>>> Thanks,

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

end of thread, other threads:[~2021-06-10 15:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 20:49 [PATCH 1/2] f2fs: let's allow compression for mmap files Jaegeuk Kim
2021-05-25 20:49 ` [PATCH 2/2] f2fs: introduce FI_COMPRESS_RELEASED instead of using IMMUTABLE bit Jaegeuk Kim
2021-06-06 13:53   ` [f2fs-dev] " Chao Yu
2021-06-07 16:56     ` Jaegeuk Kim
2021-06-07 23:17       ` Chao Yu
2021-06-09 18:43         ` Jaegeuk Kim
2021-06-10 15:24           ` Chao Yu
2021-05-26  9:09 ` [f2fs-dev] [PATCH 1/2] f2fs: let's allow compression for mmap files Chao Yu

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).