* [PATCH v2] f2fs: fix wrong inflight page stats for directIO
@ 2021-07-19 8:45 Chao Yu
2021-07-22 0:46 ` [f2fs-dev] " Eric Biggers
0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2021-07-19 8:45 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, Chao Yu, Chao Yu
Previously, we use sbi->nr_pages[] to account direct IO, the count should
be based on page granularity rather than bio granularity, fix it.
Fixes: 02b16d0a34a1 ("f2fs: add to account direct IO")
Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- There is one missing line when I reorder in development patches,
so just resend the patch as v2, sorry.
fs/f2fs/data.c | 11 +++++++----
fs/f2fs/f2fs.h | 13 +++++++++++++
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index e6f107de4c92..095350ccf80d 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3494,8 +3494,9 @@ static void f2fs_dio_end_io(struct bio *bio)
{
struct f2fs_private_dio *dio = bio->bi_private;
- dec_page_count(F2FS_I_SB(dio->inode),
- dio->write ? F2FS_DIO_WRITE : F2FS_DIO_READ);
+ dec_page_counts(F2FS_I_SB(dio->inode),
+ dio->write ? F2FS_DIO_WRITE : F2FS_DIO_READ,
+ dio->blkcnt);
bio->bi_private = dio->orig_private;
bio->bi_end_io = dio->orig_end_io;
@@ -3510,6 +3511,7 @@ static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode,
{
struct f2fs_private_dio *dio;
bool write = (bio_op(bio) == REQ_OP_WRITE);
+ unsigned int blkcnt = bio_sectors(bio) >> F2FS_LOG_SECTORS_PER_BLOCK;
dio = f2fs_kzalloc(F2FS_I_SB(inode),
sizeof(struct f2fs_private_dio), GFP_NOFS);
@@ -3519,13 +3521,14 @@ static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode,
dio->inode = inode;
dio->orig_end_io = bio->bi_end_io;
dio->orig_private = bio->bi_private;
+ dio->blkcnt = blkcnt;
dio->write = write;
bio->bi_end_io = f2fs_dio_end_io;
bio->bi_private = dio;
- inc_page_count(F2FS_I_SB(inode),
- write ? F2FS_DIO_WRITE : F2FS_DIO_READ);
+ inc_page_counts(F2FS_I_SB(inode),
+ write ? F2FS_DIO_WRITE : F2FS_DIO_READ, dio->blkcnt);
submit_bio(bio);
return;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 867f2c5d9559..7369f8087f64 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1759,6 +1759,7 @@ struct f2fs_private_dio {
struct inode *inode;
void *orig_private;
bio_end_io_t *orig_end_io;
+ unsigned int blkcnt;
bool write;
};
@@ -2267,6 +2268,12 @@ static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
set_sbi_flag(sbi, SBI_IS_DIRTY);
}
+static inline void inc_page_counts(struct f2fs_sb_info *sbi, int count_type,
+ unsigned int count)
+{
+ atomic_add(count, &sbi->nr_pages[count_type]);
+}
+
static inline void inode_inc_dirty_pages(struct inode *inode)
{
atomic_inc(&F2FS_I(inode)->dirty_pages);
@@ -2281,6 +2288,12 @@ static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
atomic_dec(&sbi->nr_pages[count_type]);
}
+static inline void dec_page_counts(struct f2fs_sb_info *sbi, int count_type,
+ unsigned int count)
+{
+ atomic_sub(count, &sbi->nr_pages[count_type]);
+}
+
static inline void inode_dec_dirty_pages(struct inode *inode)
{
if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
--
2.22.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: fix wrong inflight page stats for directIO
2021-07-19 8:45 [PATCH v2] f2fs: fix wrong inflight page stats for directIO Chao Yu
@ 2021-07-22 0:46 ` Eric Biggers
2021-07-22 1:42 ` Eric Biggers
0 siblings, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2021-07-22 0:46 UTC (permalink / raw)
To: Chao Yu; +Cc: jaegeuk, Chao Yu, linux-kernel, linux-f2fs-devel
On Mon, Jul 19, 2021 at 04:45:48PM +0800, Chao Yu wrote:
> Previously, we use sbi->nr_pages[] to account direct IO, the count should
> be based on page granularity rather than bio granularity, fix it.
>
> Fixes: 02b16d0a34a1 ("f2fs: add to account direct IO")
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> v2:
> - There is one missing line when I reorder in development patches,
> so just resend the patch as v2, sorry.
> fs/f2fs/data.c | 11 +++++++----
> fs/f2fs/f2fs.h | 13 +++++++++++++
> 2 files changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index e6f107de4c92..095350ccf80d 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -3494,8 +3494,9 @@ static void f2fs_dio_end_io(struct bio *bio)
> {
> struct f2fs_private_dio *dio = bio->bi_private;
>
> - dec_page_count(F2FS_I_SB(dio->inode),
> - dio->write ? F2FS_DIO_WRITE : F2FS_DIO_READ);
> + dec_page_counts(F2FS_I_SB(dio->inode),
> + dio->write ? F2FS_DIO_WRITE : F2FS_DIO_READ,
> + dio->blkcnt);
>
> bio->bi_private = dio->orig_private;
> bio->bi_end_io = dio->orig_end_io;
> @@ -3510,6 +3511,7 @@ static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode,
> {
> struct f2fs_private_dio *dio;
> bool write = (bio_op(bio) == REQ_OP_WRITE);
> + unsigned int blkcnt = bio_sectors(bio) >> F2FS_LOG_SECTORS_PER_BLOCK;
>
> dio = f2fs_kzalloc(F2FS_I_SB(inode),
> sizeof(struct f2fs_private_dio), GFP_NOFS);
> @@ -3519,13 +3521,14 @@ static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode,
> dio->inode = inode;
> dio->orig_end_io = bio->bi_end_io;
> dio->orig_private = bio->bi_private;
> + dio->blkcnt = blkcnt;
> dio->write = write;
>
> bio->bi_end_io = f2fs_dio_end_io;
> bio->bi_private = dio;
>
> - inc_page_count(F2FS_I_SB(inode),
> - write ? F2FS_DIO_WRITE : F2FS_DIO_READ);
> + inc_page_counts(F2FS_I_SB(inode),
> + write ? F2FS_DIO_WRITE : F2FS_DIO_READ, dio->blkcnt);
>
> submit_bio(bio);
> return;
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 867f2c5d9559..7369f8087f64 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1759,6 +1759,7 @@ struct f2fs_private_dio {
> struct inode *inode;
> void *orig_private;
> bio_end_io_t *orig_end_io;
> + unsigned int blkcnt;
> bool write;
> };
>
> @@ -2267,6 +2268,12 @@ static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
> set_sbi_flag(sbi, SBI_IS_DIRTY);
> }
>
> +static inline void inc_page_counts(struct f2fs_sb_info *sbi, int count_type,
> + unsigned int count)
> +{
> + atomic_add(count, &sbi->nr_pages[count_type]);
> +}
> +
> static inline void inode_inc_dirty_pages(struct inode *inode)
> {
> atomic_inc(&F2FS_I(inode)->dirty_pages);
> @@ -2281,6 +2288,12 @@ static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
> atomic_dec(&sbi->nr_pages[count_type]);
> }
>
> +static inline void dec_page_counts(struct f2fs_sb_info *sbi, int count_type,
> + unsigned int count)
> +{
> + atomic_sub(count, &sbi->nr_pages[count_type]);
> +}
> +
Please give these proper names like add_to_page_count() and
sub_from_page_count(). They change one counter, not multiple.
- Eric
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: fix wrong inflight page stats for directIO
2021-07-22 0:46 ` [f2fs-dev] " Eric Biggers
@ 2021-07-22 1:42 ` Eric Biggers
2021-07-22 13:18 ` Chao Yu
0 siblings, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2021-07-22 1:42 UTC (permalink / raw)
To: Chao Yu; +Cc: jaegeuk, linux-f2fs-devel, linux-kernel, Chao Yu
On Wed, Jul 21, 2021 at 05:46:26PM -0700, Eric Biggers wrote:
> On Mon, Jul 19, 2021 at 04:45:48PM +0800, Chao Yu wrote:
> > Previously, we use sbi->nr_pages[] to account direct IO, the count should
> > be based on page granularity rather than bio granularity, fix it.
> >
> > Fixes: 02b16d0a34a1 ("f2fs: add to account direct IO")
> > Signed-off-by: Chao Yu <chao@kernel.org>
Also, do we have to do this, as opposed to just moving F2FS_DIO_WRITE and
F2FS_DIO_READ out of ->nr_pages[] and into separate counters that are clearly
defined to be per-request? As Christoph pointed out
(https://lkml.kernel.org/r/YPU+3inGclUtcSpJ@infradead.org), these counters are
only used to check whether there is any in-flight direct I/O at all. (They're
also shown in /sys/kernel/debug/f2fs/status, but that doesn't really matter.)
As Christoph mentioned, there is a way to avoid needing f2fs_dio_submit_bio()
(which would save a memory allocation for every bio, which can fail). But it
will only work if the counters remain per-request.
Can we leave these as per-request?
- Eric
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: fix wrong inflight page stats for directIO
2021-07-22 1:42 ` Eric Biggers
@ 2021-07-22 13:18 ` Chao Yu
0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2021-07-22 13:18 UTC (permalink / raw)
To: Eric Biggers; +Cc: jaegeuk, linux-f2fs-devel, linux-kernel, Chao Yu
On 2021/7/22 9:42, Eric Biggers wrote:
> On Wed, Jul 21, 2021 at 05:46:26PM -0700, Eric Biggers wrote:
>> On Mon, Jul 19, 2021 at 04:45:48PM +0800, Chao Yu wrote:
>>> Previously, we use sbi->nr_pages[] to account direct IO, the count should
>>> be based on page granularity rather than bio granularity, fix it.
>>>
>>> Fixes: 02b16d0a34a1 ("f2fs: add to account direct IO")
>>> Signed-off-by: Chao Yu <chao@kernel.org>
>
> Also, do we have to do this, as opposed to just moving F2FS_DIO_WRITE and
> F2FS_DIO_READ out of ->nr_pages[] and into separate counters that are clearly
> defined to be per-request? As Christoph pointed out
> (https://lkml.kernel.org/r/YPU+3inGclUtcSpJ@infradead.org), these counters are
> only used to check whether there is any in-flight direct I/O at all. (They're
> also shown in /sys/kernel/debug/f2fs/status, but that doesn't really matter.)
>
> As Christoph mentioned, there is a way to avoid needing f2fs_dio_submit_bio()
> (which would save a memory allocation for every bio, which can fail). But it
> will only work if the counters remain per-request.
>
> Can we leave these as per-request?
I updated the patch, could you please check that?
Thanks,
>
> - Eric
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-22 13:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-19 8:45 [PATCH v2] f2fs: fix wrong inflight page stats for directIO Chao Yu
2021-07-22 0:46 ` [f2fs-dev] " Eric Biggers
2021-07-22 1:42 ` Eric Biggers
2021-07-22 13:18 ` 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).