* [PATCH,1/2] genhd: avoid overflow of sectors in disk_stats
[not found] <CGME20181130093318eucas1p24feb8e649c8f244ce149a7f87e43c828@eucas1p2.samsung.com>
@ 2018-11-30 9:32 ` Huijin Park
[not found] ` <CGME20181130093322eucas1p2aab6a9716469d9d2a9de1ffa91dd42f0@eucas1p2.samsung.com>
2018-11-30 19:56 ` [PATCH,1/2] genhd: avoid overflow of " Omar Sandoval
0 siblings, 2 replies; 4+ messages in thread
From: Huijin Park @ 2018-11-30 9:32 UTC (permalink / raw)
To: Andreas Dilger, Michael Callahan
Cc: Omar Sandoval, js07.lee, Huijin Park, Huijin Park, linux-block,
linux-ext4, linux-kernel
From: "huijin.park" <huijin.park@samsung.com>
This patch changes the 'sectors' type to an u64.
In 32 bit system, the 'sectors' can accumulate up to about 2TiB.
If a 32 bit system makes i/o over 2TiB while running,
the 'sectors' will overflow.
As a result, the part_stat_read(sectors), the diskstats in proc and
the (lifetime|session)_write_kbytes in sysfs return invalid statistic.
Signed-off-by: huijin.park <huijin.park@samsung.com>
---
block/genhd.c | 6 +++---
include/linux/genhd.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 0145bcb..7518dcd 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1343,10 +1343,10 @@ static int diskstats_show(struct seq_file *seqf, void *v)
part_stat_unlock();
part_in_flight(gp->queue, hd, inflight);
seq_printf(seqf, "%4d %7d %s "
- "%lu %lu %lu %u "
- "%lu %lu %lu %u "
+ "%lu %lu %llu %u "
+ "%lu %lu %llu %u "
"%u %u %u "
- "%lu %lu %lu %u\n",
+ "%lu %lu %llu %u\n",
MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
disk_name(gp, hd->partno, buf),
part_stat_read(hd, ios[STAT_READ]),
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 0c5ee17..5bf86f9 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -84,7 +84,7 @@ struct partition {
struct disk_stats {
u64 nsecs[NR_STAT_GROUPS];
- unsigned long sectors[NR_STAT_GROUPS];
+ u64 sectors[NR_STAT_GROUPS];
unsigned long ios[NR_STAT_GROUPS];
unsigned long merges[NR_STAT_GROUPS];
unsigned long io_ticks;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH,2/2] ext4: change type to same as sectors in disk_stats
[not found] ` <CGME20181130093322eucas1p2aab6a9716469d9d2a9de1ffa91dd42f0@eucas1p2.samsung.com>
@ 2018-11-30 9:32 ` Huijin Park
0 siblings, 0 replies; 4+ messages in thread
From: Huijin Park @ 2018-11-30 9:32 UTC (permalink / raw)
To: Andreas Dilger, Michael Callahan
Cc: Omar Sandoval, js07.lee, Huijin Park, Huijin Park, linux-block,
linux-ext4, linux-kernel
From: "huijin.park" <huijin.park@samsung.com>
This patch changes the 's_sectors_written_start' type to u64
same as the 'sectors' type in disk_stats.
Because if the 'sectors' has more than about 2TiB,
the 's_sectors_written_start' will overflow in 32 bit system.
And it makes invalid statistics([session|lifetime]_write_kbytes).
Signed-off-by: huijin.park <huijin.park@samsung.com>
---
fs/ext4/ext4.h | 2 +-
fs/ext4/sysfs.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 3f89d0a..d3a08b2 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1457,7 +1457,7 @@ struct ext4_sb_info {
struct ext4_locality_group __percpu *s_locality_groups;
/* for write statistics */
- unsigned long s_sectors_written_start;
+ u64 s_sectors_written_start;
u64 s_kbytes_written;
/* the size of zero-out chunk */
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index 9212a02..59ac5cf 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -57,7 +57,7 @@ static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
if (!sb->s_bdev->bd_part)
return snprintf(buf, PAGE_SIZE, "0\n");
- return snprintf(buf, PAGE_SIZE, "%lu\n",
+ return snprintf(buf, PAGE_SIZE, "%llu\n",
(part_stat_read(sb->s_bdev->bd_part,
sectors[STAT_WRITE]) -
sbi->s_sectors_written_start) >> 1);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH,1/2] genhd: avoid overflow of sectors in disk_stats
2018-11-30 9:32 ` [PATCH,1/2] genhd: avoid overflow of sectors in disk_stats Huijin Park
[not found] ` <CGME20181130093322eucas1p2aab6a9716469d9d2a9de1ffa91dd42f0@eucas1p2.samsung.com>
@ 2018-11-30 19:56 ` Omar Sandoval
2018-12-09 14:44 ` Huijin Park
1 sibling, 1 reply; 4+ messages in thread
From: Omar Sandoval @ 2018-11-30 19:56 UTC (permalink / raw)
To: Huijin Park
Cc: Andreas Dilger, Michael Callahan, Omar Sandoval, js07.lee,
Huijin Park, linux-block, linux-ext4, linux-kernel
On Fri, Nov 30, 2018 at 04:32:40AM -0500, Huijin Park wrote:
> From: "huijin.park" <huijin.park@samsung.com>
>
> This patch changes the 'sectors' type to an u64.
> In 32 bit system, the 'sectors' can accumulate up to about 2TiB.
> If a 32 bit system makes i/o over 2TiB while running,
> the 'sectors' will overflow.
> As a result, the part_stat_read(sectors), the diskstats in proc and
> the (lifetime|session)_write_kbytes in sysfs return invalid statistic.
What about parsers which expect it to be an unsigned long? E.g., iostat:
https://github.com/sysstat/sysstat/blob/v12.1.1/rd_stats.c#L736
At least with glibc, scanf seems to truncate sanely, but this appears to
be undefined.
> Signed-off-by: huijin.park <huijin.park@samsung.com>
> ---
> block/genhd.c | 6 +++---
> include/linux/genhd.h | 2 +-
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/block/genhd.c b/block/genhd.c
> index 0145bcb..7518dcd 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -1343,10 +1343,10 @@ static int diskstats_show(struct seq_file *seqf, void *v)
> part_stat_unlock();
> part_in_flight(gp->queue, hd, inflight);
> seq_printf(seqf, "%4d %7d %s "
> - "%lu %lu %lu %u "
> - "%lu %lu %lu %u "
> + "%lu %lu %llu %u "
> + "%lu %lu %llu %u "
> "%u %u %u "
> - "%lu %lu %lu %u\n",
> + "%lu %lu %llu %u\n",
> MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
> disk_name(gp, hd->partno, buf),
> part_stat_read(hd, ios[STAT_READ]),
> diff --git a/include/linux/genhd.h b/include/linux/genhd.h
> index 0c5ee17..5bf86f9 100644
> --- a/include/linux/genhd.h
> +++ b/include/linux/genhd.h
> @@ -84,7 +84,7 @@ struct partition {
>
> struct disk_stats {
> u64 nsecs[NR_STAT_GROUPS];
> - unsigned long sectors[NR_STAT_GROUPS];
> + u64 sectors[NR_STAT_GROUPS];
> unsigned long ios[NR_STAT_GROUPS];
> unsigned long merges[NR_STAT_GROUPS];
> unsigned long io_ticks;
> --
> 1.7.9.5
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH,1/2] genhd: avoid overflow of sectors in disk_stats
2018-11-30 19:56 ` [PATCH,1/2] genhd: avoid overflow of " Omar Sandoval
@ 2018-12-09 14:44 ` Huijin Park
0 siblings, 0 replies; 4+ messages in thread
From: Huijin Park @ 2018-12-09 14:44 UTC (permalink / raw)
To: osandov
Cc: huijin.park, adilger.kernel, michaelcallahan, osandov, js07.lee,
linux-block, linux-ext4, linux-kernel
Hi Omar Sandoval,
On Sat, Dec 1, 2018 at 4:56 AM Omar Sandoval <osandov@osandov.com> wrote:
>
> On Fri, Nov 30, 2018 at 04:32:40AM -0500, Huijin Park wrote:
> > From: "huijin.park" <huijin.park@samsung.com>
> >
> > This patch changes the 'sectors' type to an u64.
> > In 32 bit system, the 'sectors' can accumulate up to about 2TiB.
> > If a 32 bit system makes i/o over 2TiB while running,
> > the 'sectors' will overflow.
> > As a result, the part_stat_read(sectors), the diskstats in proc and
> > the (lifetime|session)_write_kbytes in sysfs return invalid statistic.
>
> What about parsers which expect it to be an unsigned long? E.g., iostat:
> https://github.com/sysstat/sysstat/blob/v12.1.1/rd_stats.c#L736
>
> At least with glibc, scanf seems to truncate sanely, but this appears to
> be undefined.
The glibc APIs such as scanf and strtoul set return value and errno
to ULONG_MAX and ERANGE in overflow case.
I think ULONG_MAX and ERANGE are better than reset to zero because
of overflow. At least, application can notice overflow with errno.
Besides nowadays, a 32 bit is not enough size to show
an i/o accumulated size.
I met a problem like below. So I suggested this patch.
sh-3.2# mount | grep p19
/dev/mmcblk0p19 on /ext4_dir type ext4 (rw,relatime,data=ordered)
sh-3.2# cat /sys/fs/ext4/mmcblk0p19/session_write_kbytes
2147467268
sh-3.2# cat /sys/fs/ext4/mmcblk0p19/lifetime_write_kbytes
2147568561
sh-3.2# dd if=/dev/zero of=/ext4_dir/temp.bin bs=1M count=20 oflag=sync
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied,
0.621939 s, 33.7 MB/s
sh-3.2# cat /sys/fs/ext4/mmcblk0p19/session_write_kbytes
4524
sh-3.2# cat /sys/fs/ext4/mmcblk0p19/lifetime_write_kbytes
105817
>
> > Signed-off-by: huijin.park <huijin.park@samsung.com>
> > ---
> > block/genhd.c | 6 +++---
> > include/linux/genhd.h | 2 +-
> > 2 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/block/genhd.c b/block/genhd.c
> > index 0145bcb..7518dcd 100644
> > --- a/block/genhd.c
> > +++ b/block/genhd.c
> > @@ -1343,10 +1343,10 @@ static int diskstats_show(struct seq_file *seqf, void *v)
> > part_stat_unlock();
> > part_in_flight(gp->queue, hd, inflight);
> > seq_printf(seqf, "%4d %7d %s "
> > - "%lu %lu %lu %u "
> > - "%lu %lu %lu %u "
> > + "%lu %lu %llu %u "
> > + "%lu %lu %llu %u "
> > "%u %u %u "
> > - "%lu %lu %lu %u\n",
> > + "%lu %lu %llu %u\n",
> > MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
> > disk_name(gp, hd->partno, buf),
> > part_stat_read(hd, ios[STAT_READ]),
> > diff --git a/include/linux/genhd.h b/include/linux/genhd.h
> > index 0c5ee17..5bf86f9 100644
> > --- a/include/linux/genhd.h
> > +++ b/include/linux/genhd.h
> > @@ -84,7 +84,7 @@ struct partition {
> >
> > struct disk_stats {
> > u64 nsecs[NR_STAT_GROUPS];
> > - unsigned long sectors[NR_STAT_GROUPS];
> > + u64 sectors[NR_STAT_GROUPS];
> > unsigned long ios[NR_STAT_GROUPS];
> > unsigned long merges[NR_STAT_GROUPS];
> > unsigned long io_ticks;
> > --
> > 1.7.9.5
> >
Thanks,
Huijin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-12-09 14:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20181130093318eucas1p24feb8e649c8f244ce149a7f87e43c828@eucas1p2.samsung.com>
2018-11-30 9:32 ` [PATCH,1/2] genhd: avoid overflow of sectors in disk_stats Huijin Park
[not found] ` <CGME20181130093322eucas1p2aab6a9716469d9d2a9de1ffa91dd42f0@eucas1p2.samsung.com>
2018-11-30 9:32 ` [PATCH,2/2] ext4: change type to same as " Huijin Park
2018-11-30 19:56 ` [PATCH,1/2] genhd: avoid overflow of " Omar Sandoval
2018-12-09 14:44 ` Huijin Park
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).