* [PATCH] direct-io: Fix unsigned comparison overflow
@ 2017-12-05 15:57 Harish Kasiviswanathan
2017-12-05 15:57 ` Harish Kasiviswanathan
0 siblings, 1 reply; 3+ messages in thread
From: Harish Kasiviswanathan @ 2017-12-05 15:57 UTC (permalink / raw)
To: guaneryu, linux-fsdevel, Felix.Kuehling; +Cc: Harish Kasiviswanathan
The following issue was noticed while running some Peer-2-Peer
benchmarks on NVMe SSD (EXT4 fs).
The first write after file create is very slow. The cause for this
is that for the first time the code doesn't take the direct P2P path and
instead falls back to software copy. The function get_more_block() sets
'create' to 0 after comparing 'unsigned long fs_startblk = 0' with 'long
long (i_size_read(dio->inode) - 1) >> i_blkbits = 0x0xfffffffffffff'.
I understand this previous change 'direct-io: fix direct write stale
data exposure from concurrent buffered read' was introduced to handle a
corner case for sparse file. I am not too familiar with sparse file.
Please let me know if this change would break it
Harish Kasiviswanathan (1):
direct-io: Fix unsigned comparison overflow
fs/direct-io.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] direct-io: Fix unsigned comparison overflow
2017-12-05 15:57 [PATCH] direct-io: Fix unsigned comparison overflow Harish Kasiviswanathan
@ 2017-12-05 15:57 ` Harish Kasiviswanathan
2017-12-05 17:26 ` Eryu Guan
0 siblings, 1 reply; 3+ messages in thread
From: Harish Kasiviswanathan @ 2017-12-05 15:57 UTC (permalink / raw)
To: guaneryu, linux-fsdevel, Felix.Kuehling; +Cc: Harish Kasiviswanathan
The first write after file create fails to take the direct IO
(Peer-to-Peer) path and falls back to slower software copy. The function
get_more_block() sets 'create' to 0 after comparing 'unsigned long
fs_startblk = 0' with 'long long (i_size_read(dio->inode) - 1) >>
i_blkbits = 0xfffffffffffff'.
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
---
fs/direct-io.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 3aafb33..588aa17 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -687,8 +687,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
*/
create = dio->op == REQ_OP_WRITE;
if (dio->flags & DIO_SKIP_HOLES) {
- if (fs_startblk <= ((i_size_read(dio->inode) - 1) >>
- i_blkbits))
+ if ((loff_t)fs_startblk <=
+ ((i_size_read(dio->inode) - 1) >> i_blkbits))
create = 0;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] direct-io: Fix unsigned comparison overflow
2017-12-05 15:57 ` Harish Kasiviswanathan
@ 2017-12-05 17:26 ` Eryu Guan
0 siblings, 0 replies; 3+ messages in thread
From: Eryu Guan @ 2017-12-05 17:26 UTC (permalink / raw)
To: Harish Kasiviswanathan; +Cc: linux-fsdevel, Felix.Kuehling
On Tue, Dec 05, 2017 at 10:57:53AM -0500, Harish Kasiviswanathan wrote:
> The first write after file create fails to take the direct IO
> (Peer-to-Peer) path and falls back to slower software copy. The function
> get_more_block() sets 'create' to 0 after comparing 'unsigned long
> fs_startblk = 0' with 'long long (i_size_read(dio->inode) - 1) >>
> i_blkbits = 0xfffffffffffff'.
>
> Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
> ---
> fs/direct-io.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/direct-io.c b/fs/direct-io.c
> index 3aafb33..588aa17 100644
> --- a/fs/direct-io.c
> +++ b/fs/direct-io.c
> @@ -687,8 +687,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
> */
> create = dio->op == REQ_OP_WRITE;
> if (dio->flags & DIO_SKIP_HOLES) {
I think the major problem here is that the original code didn't consider
the i_size=0 case (my bad). Perhaps we can make sure i_size is greater
than 0 first? As what we want to avoid is "fill holes inside i_size",
and i_size == 0 means we're guaranteed not to allocate new blocks inside
i_size.
Thanks,
Eryu
> - if (fs_startblk <= ((i_size_read(dio->inode) - 1) >>
> - i_blkbits))
> + if ((loff_t)fs_startblk <=
> + ((i_size_read(dio->inode) - 1) >> i_blkbits))
> create = 0;
> }
>
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-12-05 17:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-05 15:57 [PATCH] direct-io: Fix unsigned comparison overflow Harish Kasiviswanathan
2017-12-05 15:57 ` Harish Kasiviswanathan
2017-12-05 17:26 ` Eryu Guan
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).