ubifs: drop softlimit and delta fields from struct ubifs_wbuf
Subsystems (2)
PATCH 1/2 ubifs: drop softlimit and delta fields from struct ubifs_wbuf
From: Rafał Miłecki <[email protected]>
Values of these fields are set during init and never modified. They are used (read) in a single function only. There isn't really any reason to keep them in a struct. It only makes struct just a bit bigger without any clear gain.
--- fs/ubifs/io.c | 18 ++++++++++-------- fs/ubifs/ubifs.h | 5 ----- 2 files changed, 10 insertions(+), 13 deletions(-)
fs/ubifs/io.c +10 -8
@@ -452,16 +452,22 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer)*/ static void new_wbuf_timer_nolock (struct ubifs_wbuf *wbuf) { +ktime_t softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); +unsigned long long delta; + + delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; + delta *=1000000000ULL ; +ubifs_assert (!hrtimer_active (&wbuf->timer)); +ubifs_assert (delta <=ULONG_MAX );if (wbuf->no_timer)return ;dbg_io ("set timer for jhead %s, %llu-%llu millisecs" ,dbg_jhead (wbuf->jhead), -div_u64 (ktime_to_ns (wbuf->softlimit),USEC_PER_SEC ), -div_u64 (ktime_to_ns (wbuf->softlimit) + wbuf->delta, -USEC_PER_SEC )); -hrtimer_start_range_ns (&wbuf->timer, wbuf->softlimit, wbuf->delta, +div_u64 (ktime_to_ns (softlimit),USEC_PER_SEC ), +div_u64 (ktime_to_ns (softlimit) + delta,USEC_PER_SEC )); +hrtimer_start_range_ns (&wbuf->timer, softlimit, delta,HRTIMER_MODE_REL ); }
@@ -1059,10 +1065,6 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf)hrtimer_init (&wbuf->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); wbuf->timer.function = wbuf_timer_callback_nolock; - wbuf->softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); - wbuf->delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; - wbuf->delta *=1000000000ULL ; -ubifs_assert (wbuf->delta <=ULONG_MAX );return 0 ; }
fs/ubifs/ubifs.h +0 -5
@@ -644,9 +644,6 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,* @io_mutex: serializes write-buffer I/O * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes * fields -* @softlimit: soft write-buffer timeout interval -* @delta: hard and soft timeouts delta (the timer expire interval is @softlimit -* and @softlimit + @delta) * @timer: write-buffer timer * @no_timer: non-zero if this write-buffer does not have a timer * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing
@@ -675,8 +672,6 @@ struct ubifs_wbuf {int (*sync_callback)(struct ubifs_info *c,int lnum,int free,int pad);struct mutex io_mutex;spinlock_t lock; -ktime_t softlimit; -unsigned long long delta;struct hrtimer timer; unsigned int no_timer:1; unsigned int need_sync:1;
Signature · 1 line
2.9.3
PATCH 2/2 ubifs: use dirty_writeback_interval value for wbuf timer
From: Rafał Miłecki <[email protected]>
Right now wbuf timer has hardcoded timeouts and there is no place for manual adjustments. Some projects / cases many need that though. Few file systems allow doing that by respecting dirty_writeback_interval that can be set using sysctl (dirty_writeback_centisecs).
Lowering dirty_writeback_interval could be some way of dealing with user space apps lacking proper fsyncs. This is definitely *not* a perfect solution but we don't have ideal (user space) world. There were already advanced discussions on this matter, mostly when ext4 was introduced and it wasn't behaving as ext3. Anyway, the final decision was to add some hacks to the ext4, as trying to fix whole user space or adding new API was pointless.
We can't (and shouldn't?) just follow ext4. We can't e.g. sync on close as this would cause too many commits and flash wearing. On the other hand we still should allow some trade-off between -o sync and default wbuf timeout. Respecting dirty_writeback_interval should allow some sane cutomizations if used warily.
--- fs/ubifs/io.c | 7 ++----- fs/ubifs/ubifs.h | 4 ---- 2 files changed, 2 insertions(+), 9 deletions(-)
fs/ubifs/io.c +2 -5
@@ -452,11 +452,8 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer)*/ static void new_wbuf_timer_nolock (struct ubifs_wbuf *wbuf) { -ktime_t softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); -unsigned long long delta; - - delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; - delta *=1000000000ULL ; +ktime_t softlimit =ms_to_ktime (dirty_writeback_interval *10 ); +unsigned long long delta = dirty_writeback_interval;/* 10% delta */ ubifs_assert (!hrtimer_active (&wbuf->timer));ubifs_assert (delta <=ULONG_MAX );
fs/ubifs/ubifs.h +0 -4
@@ -83,10 +83,6 @@*/ #define BGT_NAME_PATTERN "ubifs_bgt%d_%d" -/* Write-buffer synchronization timeout interval in seconds */ -#define WBUF_TIMEOUT_SOFTLIMIT 3 -#define WBUF_TIMEOUT_HARDLIMIT 5 -/* Maximum possible inode number (only 32-bit inodes are supported now) */ #define MAX_INUM 0xFFFFFFFF
Signature · 1 line
2.9.3
Quoted 19 lines · On Wed, 14 Sep 2016 12:24:34 +0200 Rafał Miłecki <[email protected]> wrote:
From: Rafał Miłecki <[email protected]>
Values of these fields are set during init and never modified. They are used (read) in a single function only. There isn't really any reason to keep them in a struct. It only makes struct just a bit bigger without any clear gain.
Signed-off-by Rafał Miłecki <[email protected]>--- fs/ubifs/io.c | 18 ++++++++++-------- fs/ubifs/ubifs.h | 5 ----- 2 files changed, 10 insertions(+), 13 deletions(-)fs/ubifs/io.c +0
-0@@ -452,16 +452,22 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer)*/
fs/ubifs/io.c static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer) · line 462
Quoted 10 lines
fs/ubifs/io.c +7
-0static void new_wbuf_timer_nolock (struct ubifs_wbuf *wbuf) { +ktime_t softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); +unsigned long long delta; + + delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; + delta *=1000000000ULL ; +ubifs_assert (!hrtimer_active (&wbuf->timer)); +ubifs_assert (delta <=ULONG_MAX );
Hm, do we really want to recalculate delta each time we reschedule the wbuf timer?
How about making the softlimit and delta variables static and initializing them once?
Quoted 49 lines
fs/ubifs/io.c +3
-8if (wbuf->no_timer)return ;dbg_io ("set timer for jhead %s, %llu-%llu millisecs" ,dbg_jhead (wbuf->jhead), -div_u64 (ktime_to_ns (wbuf->softlimit),USEC_PER_SEC ), -div_u64 (ktime_to_ns (wbuf->softlimit) + wbuf->delta, -USEC_PER_SEC )); -hrtimer_start_range_ns (&wbuf->timer, wbuf->softlimit, wbuf->delta, +div_u64 (ktime_to_ns (softlimit),USEC_PER_SEC ), +div_u64 (ktime_to_ns (softlimit) + delta,USEC_PER_SEC )); +hrtimer_start_range_ns (&wbuf->timer, softlimit, delta,HRTIMER_MODE_REL ); }@@ -1059,10 +1065,6 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf)hrtimer_init (&wbuf->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); wbuf->timer.function = wbuf_timer_callback_nolock; - wbuf->softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); - wbuf->delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; - wbuf->delta *=1000000000ULL ; -ubifs_assert (wbuf->delta <=ULONG_MAX );return 0 ; }fs/ubifs/ubifs.h +0
-5@@ -644,9 +644,6 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,* @io_mutex: serializes write-buffer I/O * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes * fields -* @softlimit: soft write-buffer timeout interval -* @delta: hard and soft timeouts delta (the timer expire interval is @softlimit -* and @softlimit + @delta) * @timer: write-buffer timer * @no_timer: non-zero if this write-buffer does not have a timer * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing @@ -675,8 +672,6 @@ struct ubifs_wbuf {int (*sync_callback)(struct ubifs_info *c,int lnum,int free,int pad);struct mutex io_mutex;spinlock_t lock; -ktime_t softlimit; -unsigned long long delta;struct hrtimer timer; unsigned int no_timer:1; unsigned int need_sync:1;
Quoted 36 lines · On Wed, 14 Sep 2016 17:24:28 +0200 Boris Brezillon…
Quoted 19 lines · On Wed, 14 Sep 2016 12:24:34 +0200 Rafał Miłecki <[email protected]> wrote:
From: Rafał Miłecki <[email protected]>
Values of these fields are set during init and never modified. They are used (read) in a single function only. There isn't really any reason to keep them in a struct. It only makes struct just a bit bigger without any clear gain.
Signed-off-by Rafał Miłecki <[email protected]>--- fs/ubifs/io.c | 18 ++++++++++-------- fs/ubifs/ubifs.h | 5 ----- 2 files changed, 10 insertions(+), 13 deletions(-)fs/ubifs/io.c +0
-0@@ -452,16 +452,22 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer)*/ fs/ubifs/io.c static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer) · line 462
Quoted 10 lines
fs/ubifs/io.c +7
-0static void new_wbuf_timer_nolock (struct ubifs_wbuf *wbuf) { +ktime_t softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); +unsigned long long delta; + + delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; + delta *=1000000000ULL ; +ubifs_assert (!hrtimer_active (&wbuf->timer)); +ubifs_assert (delta <=ULONG_MAX );Hm, do we really want to recalculate delta each time we reschedule the wbuf timer?
Quoted 2 lines
How about making the softlimit and delta variables static and initializing them once?
Nevermind. I just read patch 2, and these delta and softlimit values have to be recalculated to account for dirty_writeback_interval changes.
Quoted 55 lines
Quoted 42 lines
fs/ubifs/io.c +3
-8if (wbuf->no_timer)return ;dbg_io ("set timer for jhead %s, %llu-%llu millisecs" ,dbg_jhead (wbuf->jhead), -div_u64 (ktime_to_ns (wbuf->softlimit),USEC_PER_SEC ), -div_u64 (ktime_to_ns (wbuf->softlimit) + wbuf->delta, -USEC_PER_SEC )); -hrtimer_start_range_ns (&wbuf->timer, wbuf->softlimit, wbuf->delta, +div_u64 (ktime_to_ns (softlimit),USEC_PER_SEC ), +div_u64 (ktime_to_ns (softlimit) + delta,USEC_PER_SEC )); +hrtimer_start_range_ns (&wbuf->timer, softlimit, delta,HRTIMER_MODE_REL ); }@@ -1059,10 +1065,6 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf)hrtimer_init (&wbuf->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); wbuf->timer.function = wbuf_timer_callback_nolock; - wbuf->softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); - wbuf->delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; - wbuf->delta *=1000000000ULL ; -ubifs_assert (wbuf->delta <=ULONG_MAX );return 0 ; }fs/ubifs/ubifs.h +0
-3@@ -644,9 +644,6 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,* @io_mutex: serializes write-buffer I/O * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes * fields -* @softlimit: soft write-buffer timeout interval -* @delta: hard and soft timeouts delta (the timer expire interval is @softlimit -* and @softlimit + @delta) * @timer: write-buffer timer * @no_timer: non-zero if this write-buffer does not have a timer * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing fs/ubifs/ubifs.h struct ubifs_wbuf { · line 677
Quoted 8 lines
fs/ubifs/ubifs.h +0
-2@@ -675,8 +672,6 @@ struct ubifs_wbuf {int (*sync_callback)(struct ubifs_info *c,int lnum,int free,int pad);struct mutex io_mutex;spinlock_t lock; -ktime_t softlimit; -unsigned long long delta;struct hrtimer timer; unsigned int no_timer:1; unsigned int need_sync:1;______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 8 lines · On Wed, 14 Sep 2016 12:24:34 +0200 Rafał Miłecki <[email protected]> wrote:
From: Rafał Miłecki <[email protected]>
Values of these fields are set during init and never modified. They are used (read) in a single function only. There isn't really any reason to keep them in a struct. It only makes struct just a bit bigger without any clear gain.
Signed-off-by Rafał Miłecki <[email protected]>
Quoted 70 lines
--- fs/ubifs/io.c | 18 ++++++++++-------- fs/ubifs/ubifs.h | 5 ----- 2 files changed, 10 insertions(+), 13 deletions(-)fs/ubifs/io.c +10
-8@@ -452,16 +452,22 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer)*/ static void new_wbuf_timer_nolock (struct ubifs_wbuf *wbuf) { +ktime_t softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); +unsigned long long delta; + + delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; + delta *=1000000000ULL ; +ubifs_assert (!hrtimer_active (&wbuf->timer)); +ubifs_assert (delta <=ULONG_MAX );if (wbuf->no_timer)return ;dbg_io ("set timer for jhead %s, %llu-%llu millisecs" ,dbg_jhead (wbuf->jhead), -div_u64 (ktime_to_ns (wbuf->softlimit),USEC_PER_SEC ), -div_u64 (ktime_to_ns (wbuf->softlimit) + wbuf->delta, -USEC_PER_SEC )); -hrtimer_start_range_ns (&wbuf->timer, wbuf->softlimit, wbuf->delta, +div_u64 (ktime_to_ns (softlimit),USEC_PER_SEC ), +div_u64 (ktime_to_ns (softlimit) + delta,USEC_PER_SEC )); +hrtimer_start_range_ns (&wbuf->timer, softlimit, delta,HRTIMER_MODE_REL ); }@@ -1059,10 +1065,6 @@ int ubifs_wbuf_init(struct ubifs_info *c, struct ubifs_wbuf *wbuf)hrtimer_init (&wbuf->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); wbuf->timer.function = wbuf_timer_callback_nolock; - wbuf->softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); - wbuf->delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; - wbuf->delta *=1000000000ULL ; -ubifs_assert (wbuf->delta <=ULONG_MAX );return 0 ; }fs/ubifs/ubifs.h +0
-5@@ -644,9 +644,6 @@ typedef int (*ubifs_lpt_scan_callback)(struct ubifs_info *c,* @io_mutex: serializes write-buffer I/O * @lock: serializes @buf, @lnum, @offs, @avail, @used, @next_ino and @inodes * fields -* @softlimit: soft write-buffer timeout interval -* @delta: hard and soft timeouts delta (the timer expire interval is @softlimit -* and @softlimit + @delta) * @timer: write-buffer timer * @no_timer: non-zero if this write-buffer does not have a timer * @need_sync: non-zero if the timer expired and the wbuf needs sync'ing @@ -675,8 +672,6 @@ struct ubifs_wbuf {int (*sync_callback)(struct ubifs_info *c,int lnum,int free,int pad);struct mutex io_mutex;spinlock_t lock; -ktime_t softlimit; -unsigned long long delta;struct hrtimer timer; unsigned int no_timer:1; unsigned int need_sync:1;
Re: [PATCH 2/2] ubifs: use dirty_writeback_interval value for wbuf timer
In reply to Rafał MiłeckiQuoted 32 lines · On Wed, 14 Sep 2016 12:24:35 +0200 Rafał Miłecki <[email protected]> wrote:
From: Rafał Miłecki <[email protected]>
Right now wbuf timer has hardcoded timeouts and there is no place for manual adjustments. Some projects / cases many need that though. Few file systems allow doing that by respecting
dirty_writeback_intervalthat can be set using sysctl (dirty_writeback_centisecs).Lowering
dirty_writeback_intervalcould be some way of dealing with user space apps lacking proper fsyncs. This is definitely *not* a perfect solution but we don't have ideal (user space) world. There were already advanced discussions on this matter, mostly when ext4 was introduced and it wasn't behaving as ext3. Anyway, the final decision was to add some hacks to the ext4, as trying to fix whole user space or adding new API was pointless.We can't (and shouldn't?) just follow ext4. We can't e.g. sync on close as this would cause too many commits and flash wearing. On the other hand we still should allow some trade-off between -o sync and default wbuf timeout. Respecting
dirty_writeback_intervalshould allow some sane cutomizations if used warily.Signed-off-by Rafał Miłecki <[email protected]>--- fs/ubifs/io.c | 7 ++----- fs/ubifs/ubifs.h | 4 ---- 2 files changed, 2 insertions(+), 9 deletions(-)fs/ubifs/io.c +0
-0
fs/ubifs/io.c static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer) · line 456
Quoted 10 lines
fs/ubifs/io.c +2
-5@@ -452,11 +452,8 @@ static enum hrtimer_restart wbuf_timer_callback_nolock(struct hrtimer *timer)*/ static void new_wbuf_timer_nolock (struct ubifs_wbuf *wbuf) { -ktime_t softlimit =ktime_set (WBUF_TIMEOUT_SOFTLIMIT ,0 ); -unsigned long long delta; - - delta =WBUF_TIMEOUT_HARDLIMIT -WBUF_TIMEOUT_SOFTLIMIT ; - delta *=1000000000ULL ; +ktime_t softlimit =ms_to_ktime (dirty_writeback_interval *10 ); +unsigned long long delta = dirty_writeback_interval;/* 10% delta */
dirty_writeback_interval is expressed in centiseconds, and delta is in nanoseconds.
I think you miss
delta *= 10000000ULL;
Quoted 18 lines
fs/ubifs/io.c +0
-0ubifs_assert (!hrtimer_active (&wbuf->timer));ubifs_assert (delta <=ULONG_MAX );fs/ubifs/ubifs.h +0
-4@@ -83,10 +83,6 @@*/ #define BGT_NAME_PATTERN "ubifs_bgt%d_%d" -/* Write-buffer synchronization timeout interval in seconds */ -#define WBUF_TIMEOUT_SOFTLIMIT 3 -#define WBUF_TIMEOUT_HARDLIMIT 5 -/* Maximum possible inode number (only 32-bit inodes are supported now) */ #define MAX_INUM 0xFFFFFFFF