On Fri, 23 Aug 2024, 陈玉凡 wrote:

> 在 2024/8/23 1:08, Mikulas Patocka 写道:
> >
> > On Thu, 22 Aug 2024, Chen Yufan wrote:
> >
> >> Use time_after_eq macro instead of opening it for readability.
> >>
> >> Signed-off-by: Chen Yufan <chenyu...@vivo.com>
> >> ---
> >>   drivers/md/dm-writecache.c | 5 +++--
> >>   1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
> >> index 7ce8847b3..548d4d37e 100644
> >> --- a/drivers/md/dm-writecache.c
> >> +++ b/drivers/md/dm-writecache.c
> >> @@ -16,6 +16,7 @@
> >>   #include <linux/pfn_t.h>
> >>   #include <linux/libnvdimm.h>
> >>   #include <linux/delay.h>
> >> +#include <linux/jiffies.h>
> >>   #include "dm-io-tracker.h"
> >>   
> >>   #define DM_MSG_PREFIX "writecache"
> >> @@ -1994,8 +1995,8 @@ static void writecache_writeback(struct work_struct 
> >> *work)
> >>    while (!list_empty(&wc->lru) &&
> >>           (wc->writeback_all ||
> >>            wc->freelist_size + wc->writeback_size <= 
> >> wc->freelist_low_watermark ||
> >> -          (jiffies - container_of(wc->lru.prev, struct wc_entry, 
> >> lru)->age >=
> >> -           wc->max_age - wc->max_age / MAX_AGE_DIV))) {
> >> +          (time_after_eq(jiffies, container_of(wc->lru.prev, struct 
> >> wc_entry, lru)->age +
> >> +           (wc->max_age - wc->max_age / MAX_AGE_DIV))))) {
> >>   
> >>            n_walked++;
> >>            if (unlikely(n_walked > WRITEBACK_LATENCY) &&
> >> -- 
> >> 2.39.0
> > I'm not sure about this. The old and new code is not really equivalent.
> >
> > Mikulas
> 
> The code here is susceptible to overflow issues, and the time_*() macros 
> can handle this.
> 
> Chen

So, describe some case (i.e. the values of jiffies, 
container_of(wc->lru.prev, struct wc_entry, lru)->age and wc->max_age) 
where the old code misbehaves and the new code doesn't.

If we want to fix a bug, we need to know what the bug actually is.

Mikulas

Reply via email to