[f2fs-dev] [PATCH v4 2/2] f2fs: fix missing inplace count in overwrite with direct io

2021-09-21 Thread Fengnan Chang via Linux-f2fs-devel
For now, overwrite file with direct io use inplace policy, but
not counted, fix it. And use stat_add_inplace_blocks(sbi, 1, )
instead of stat_inc_inplace_blocks(sb, ).

Signed-off-by: Fengnan Chang 
---
 fs/f2fs/data.c| 4 +++-
 fs/f2fs/f2fs.h| 8 
 fs/f2fs/segment.c | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index c1490b9a1345..7798f7236376 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1553,7 +1553,9 @@ int f2fs_map_blocks(struct inode *inode, struct 
f2fs_map_blocks *map,
goto sync_out;
blkaddr = dn.data_blkaddr;
set_inode_flag(inode, FI_APPEND_WRITE);
-   }
+   } else if (!f2fs_lfs_mode(sbi) && flag == 
F2FS_GET_BLOCK_PRE_DIO &&
+   map->m_may_create && create)
+   stat_add_inplace_blocks(sbi, 1, true);
} else {
if (create) {
if (unlikely(f2fs_cp_error(sbi))) {
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 20d715cacf49..3895a4f44ecf 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3785,12 +3785,12 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct 
f2fs_sb_info *sbi)
else
\
((sbi)->block_count[1][(curseg)->alloc_type]++);
\
} while (0)
-#define stat_inc_inplace_blocks(sbi, direct_io)
\
+#define stat_add_inplace_blocks(sbi, count, direct_io) \
do {\
if (direct_io)  \
-   (atomic_inc(&(sbi)->inplace_count[0])); \
+   (atomic_add(count, &(sbi)->inplace_count[0]));  \
else
\
-   (atomic_inc(&(sbi)->inplace_count[1])); \
+   (atomic_add(count, &(sbi)->inplace_count[1]));  \
} while (0)
 #define stat_update_max_atomic_write(inode)\
do {\
@@ -3877,7 +3877,7 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
 #define stat_inc_meta_count(sbi, blkaddr)  do { } while (0)
 #define stat_inc_seg_type(sbi, curseg) do { } while (0)
 #define stat_inc_block_count(sbi, curseg, direct_io)   do { } while (0)
-#define stat_inc_inplace_blocks(sbi, direct_io)do { } 
while (0)
+#define stat_add_inplace_blocks(sbi, count, direct_io) do { } while (0)
 #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0)
 #define stat_inc_tot_blk_count(si, blks)   do { } while (0)
 #define stat_inc_data_blk_count(sbi, blks, gc_type)do { } while (0)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index ded744e880d0..c542c4b687ca 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3611,7 +3611,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
goto drop_bio;
}
 
-   stat_inc_inplace_blocks(fio->sbi, false);
+   stat_add_inplace_blocks(sbi, 1, false);
 
if (fio->bio && !(SM_I(sbi)->ipu_policy & (1 << F2FS_IPU_NOCACHE)))
err = f2fs_merge_page_bio(fio);
-- 
2.32.0



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


[f2fs-dev] [PATCH v4 1/2] f2fs: separate buffer and direct io in block allocation statistics

2021-09-21 Thread Fengnan Chang via Linux-f2fs-devel
separate buffer and direct io in block allocation statistics.

New output will like this:
   buffer direct   segments
IPU:0  0N/A
SSR:0  0  0
LFS:0  0  0

Signed-off-by: Fengnan Chang 
---
 fs/f2fs/data.c| 10 ++
 fs/f2fs/debug.c   | 24 +++-
 fs/f2fs/f2fs.h| 32 +---
 fs/f2fs/gc.c  |  2 +-
 fs/f2fs/segment.c |  8 
 5 files changed, 47 insertions(+), 29 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index f4fd6c246c9a..c1490b9a1345 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1342,7 +1342,7 @@ struct page *f2fs_get_new_data_page(struct inode *inode,
return page;
 }
 
-static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
+static int __allocate_data_block(struct dnode_of_data *dn, int seg_type, bool 
direct_io)
 {
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
struct f2fs_summary sum;
@@ -1369,7 +1369,7 @@ static int __allocate_data_block(struct dnode_of_data 
*dn, int seg_type)
set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
old_blkaddr = dn->data_blkaddr;
f2fs_allocate_data_block(sbi, NULL, old_blkaddr, &dn->data_blkaddr,
-   &sum, seg_type, NULL);
+   &sum, seg_type, NULL, direct_io);
if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) {
invalidate_mapping_pages(META_MAPPING(sbi),
old_blkaddr, old_blkaddr);
@@ -1548,7 +1548,7 @@ int f2fs_map_blocks(struct inode *inode, struct 
f2fs_map_blocks *map,
/* use out-place-update for driect IO under LFS mode */
if (f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO &&
map->m_may_create) {
-   err = __allocate_data_block(&dn, map->m_seg_type);
+   err = __allocate_data_block(&dn, map->m_seg_type, true);
if (err)
goto sync_out;
blkaddr = dn.data_blkaddr;
@@ -1569,7 +1569,9 @@ int f2fs_map_blocks(struct inode *inode, struct 
f2fs_map_blocks *map,
WARN_ON(flag != F2FS_GET_BLOCK_PRE_DIO &&
flag != F2FS_GET_BLOCK_DIO);
err = __allocate_data_block(&dn,
-   map->m_seg_type);
+   map->m_seg_type,
+   flag == F2FS_GET_BLOCK_PRE_DIO ||
+   flag == F2FS_GET_BLOCK_DIO);
if (!err)
set_inode_flag(inode, FI_APPEND_WRITE);
}
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 8c50518475a9..e1aa843b067c 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -64,7 +64,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
 {
struct f2fs_stat_info *si = F2FS_STAT(sbi);
struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
-   int i;
+   int i, j;
 
/* these will be changed if online resize is done */
si->main_area_segs = le32_to_cpu(raw_super->segment_count_main);
@@ -210,10 +210,12 @@ static void update_general_status(struct f2fs_sb_info 
*sbi)
 
for (i = 0; i < 2; i++) {
si->segment_count[i] = sbi->segment_count[i];
-   si->block_count[i] = sbi->block_count[i];
+   for (j = 0; j < 2; j++)
+   si->block_count[i][j] = sbi->block_count[i][j];
}
 
-   si->inplace_count = atomic_read(&sbi->inplace_count);
+   for (i = 0; i < 2; i++)
+   si->inplace_count[i] = atomic_read(&sbi->inplace_count[i]);
 }
 
 /*
@@ -551,11 +553,14 @@ static int stat_show(struct seq_file *s, void *v)
for (j = 0; j < si->util_free; j++)
seq_putc(s, '-');
seq_puts(s, "]\n\n");
-   seq_printf(s, "IPU: %u blocks\n", si->inplace_count);
-   seq_printf(s, "SSR: %u blocks in %u segments\n",
-  si->block_count[SSR], si->segment_count[SSR]);
-   seq_printf(s, "LFS: %u blocks in %u segments\n",
-  si->block_count[LFS], si->segment_count[LFS]);
+
+   seq_printf(s, "   %10s %10s %10s\n", "buffer", "direct", 
"segments");
+   seq_printf(s,   "IPU:   %10d %10dN/A\n", 
si->inplace_count[1],
+   si->inplace_count[0]);
+   seq_printf(s,   "SSR:   %10d %10d %10d\n", 
si->block_count[1][SSR],
+   si->block_count[0][SSR], 
si->segment_count[SSR]);
+   seq_printf(s,   "LFS:   %10d %10d %10d\n", 
si->blo

[f2fs-dev] [Bug 214299] A deadlock problem caused by the quota_sem set in db6ec53b7e0

2021-09-21 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=214299

--- Comment #2 from zhuang...@huawei.com ---
(In reply to Chao Yu from comment #1)
> I've sent a patch for this bug, could you please test with it?
> 
> https://lore.kernel.org/linux-f2fs-devel/20210903023811.3458-1-chao@kernel.
> org/T/#u

Thanks, I will verify this patch as soon as possible.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

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


Re: [f2fs-dev] [PATCH v2 2/2] f2fs: fix missing inplace count in overwrite with direct io

2021-09-21 Thread 常凤楠 via Linux-f2fs-devel

> -Original Message-
> From: changfeng...@vivo.com  On Behalf Of
> Chao Yu
> Sent: Sunday, September 19, 2021 6:34 AM
> To: 常凤楠 ; jaeg...@kernel.org
> Cc: linux-f2fs-devel@lists.sourceforge.net
> Subject: Re: [PATCH v2 2/2] f2fs: fix missing inplace count in overwrite with
> direct io
> 
> On 2021/9/18 14:46, 常凤楠 wrote:
> >
> >
> >> -Original Message-
> >> From: changfeng...@vivo.com  On Behalf Of
> Chao
> >> Yu
> >> Sent: Friday, September 17, 2021 9:00 PM
> >> To: 常凤楠 ; jaeg...@kernel.org
> >> Cc: linux-f2fs-devel@lists.sourceforge.net
> >> Subject: Re: [PATCH v2 2/2] f2fs: fix missing inplace count in
> >> overwrite with direct io
> >>
> >> On 2021/9/17 18:19, 常凤楠 wrote:
> >>>
> >>>
>  -Original Message-
>  From: 常凤楠
>  Sent: Thursday, September 16, 2021 8:46 PM
>  To: Chao Yu ; jaeg...@kernel.org
>  Cc: linux-f2fs-devel@lists.sourceforge.net
>  Subject: RE: [PATCH v2 2/2] f2fs: fix missing inplace count in
>  overwrite with direct io
> 
> 
> 
> > -Original Message-
> > From: changfeng...@vivo.com  On Behalf
> Of
>  Chao
> > Yu
> > Sent: Thursday, September 16, 2021 8:10 PM
> > To: 常凤楠 ; jaeg...@kernel.org
> > Cc: linux-f2fs-devel@lists.sourceforge.net
> > Subject: Re: [PATCH v2 2/2] f2fs: fix missing inplace count in
> > overwrite with direct io
> >
> > On 2021/9/16 19:30, Fengnan Chang wrote:
> >> For now, overwrite file with direct io use inplace policy, but
> >> not counted, fix it. And use stat_add_inplace_blocks(sbi, 1, )
> >> instead of stat_inc_inplace_blocks(sb, ).
> >>
> >> Signed-off-by: Fengnan Chang 
> >> ---
> >> fs/f2fs/data.c| 7 ++-
> >> fs/f2fs/f2fs.h| 8 
> >> fs/f2fs/segment.c | 2 +-
> >> 3 files changed, 11 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index
> >> c1490b9a1345..0c5728d63c33 100644
> >> --- a/fs/f2fs/data.c
> >> +++ b/fs/f2fs/data.c
> >> @@ -1491,6 +1491,9 @@ int f2fs_map_blocks(struct inode *inode,
> >> struct
> > f2fs_map_blocks *map,
> >>if (flag == F2FS_GET_BLOCK_DIO)
> >>f2fs_wait_on_block_writeback_range(inode,
> >>map->m_pblk, 
> >> map->m_len);
> >> +  if (!f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO &&
> >> +  map->m_may_create)
> >> +  stat_add_inplace_blocks(sbi, map->m_len, true);
> >>goto out;
> >>}
> >>
> >> @@ -1553,7 +1556,9 @@ int f2fs_map_blocks(struct inode *inode,
> >> struct
> > f2fs_map_blocks *map,
> >>goto sync_out;
> >>blkaddr = dn.data_blkaddr;
> >>set_inode_flag(inode, FI_APPEND_WRITE);
> >> -  }
> >> +  } else if (!create && !f2fs_lfs_mode(sbi) && flag ==
> > F2FS_GET_BLOCK_DIO &&
> >> +  map->m_may_create)
> >
> > Why not
> >
> > } else if {!f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO &&
> > map->m_may_create)
> >
> 
>  You are right, no need to check create .
> 
> >>> There is a problem here, if remove create check, when create file
> >>> and write with direct io, It will count in LFS and IPU both, because
> >>> preallocate block addr first. So, We still need check create.
> >>> Am I right?
> >>
> >> Could you please check below case w/ your original patch:
> >>
> >> xfs_io -f file -c "pwrite 0 8k" -c "fsync"
> >> xfs_io file -c "fpunch 0 4k"
> >> xfs_io  -c "open -d file" -c "pwrite -b 4k 0 8k"
> >>
> >> It accounts on both IPU and LFS stats.
> >
> > My origin patch is need check create:
> > @@ -1553,7 +1556,9 @@ int f2fs_map_blocks(struct inode *inode, struct
> f2fs_map_blocks *map,
> > goto sync_out;
> > blkaddr = dn.data_blkaddr;
> > set_inode_flag(inode, FI_APPEND_WRITE);
> > -   }
> > +   } else if (!create && !f2fs_lfs_mode(sbi) && flag ==
> F2FS_GET_BLOCK_DIO &&
> > +   map->m_may_create)
> > +   stat_add_inplace_blocks(sbi, 1, true);
> >
> > And below case looks correct, So I think check create is necessary.
> >
> > root@kvm-xfstests:/mnt/test# cat /sys/kernel/debug/f2fs/status |grep
> > SSR -C 3
> >
> > buffer direct   segments
> > IPU:0  0N/A
> > SSR:0  0  0
> > LFS:  542  0  1
> >
> > BDF: 99, avg. vblocks: 488
> > root@kvm-xfstests:/mnt/test# xfs_io -f file -c "pwrite 0 8k" -c "fsync"
> > wrote 8192/8192 bytes at offset 0
> > 8 KiB, 2 ops; 0.0078 sec (1014.070 KiB/sec and 253.5176 ops/sec)
> 

[f2fs-dev] [PATCH] f2fs: fix up f2fs_lookup tracepoints

2021-09-21 Thread Gao Xiang
Fix up a misuse that the filename pointer isn't always valid in
the ring buffer, and we should copy the content instead.

Fixes: 0c5e36db17f5 ("f2fs: trace f2fs_lookup")
Signed-off-by: Gao Xiang 
---
 include/trace/events/f2fs.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 4e881d9..4cb055a 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -807,20 +807,20 @@
TP_STRUCT__entry(
__field(dev_t,  dev)
__field(ino_t,  ino)
-   __field(const char *,   name)
+   __string(name,  dentry->d_name.name)
__field(unsigned int, flags)
),
 
TP_fast_assign(
__entry->dev= dir->i_sb->s_dev;
__entry->ino= dir->i_ino;
-   __entry->name   = dentry->d_name.name;
+   __assign_str(name, dentry->d_name.name);
__entry->flags  = flags;
),
 
TP_printk("dev = (%d,%d), pino = %lu, name:%s, flags:%u",
show_dev_ino(__entry),
-   __entry->name,
+   __get_str(name),
__entry->flags)
 );
 
@@ -834,7 +834,7 @@
TP_STRUCT__entry(
__field(dev_t,  dev)
__field(ino_t,  ino)
-   __field(const char *,   name)
+   __string(name,  dentry->d_name.name)
__field(nid_t,  cino)
__field(int,err)
),
@@ -842,14 +842,14 @@
TP_fast_assign(
__entry->dev= dir->i_sb->s_dev;
__entry->ino= dir->i_ino;
-   __entry->name   = dentry->d_name.name;
+   __assign_str(name, dentry->d_name.name);
__entry->cino   = ino;
__entry->err= err;
),
 
TP_printk("dev = (%d,%d), pino = %lu, name:%s, ino:%u, err:%d",
show_dev_ino(__entry),
-   __entry->name,
+   __get_str(name),
__entry->cino,
__entry->err)
 );
-- 
1.8.3.1



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