mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro
@ 2024-08-22  1:54 Chen Yufan
  2024-08-22 17:08 ` Mikulas Patocka
  0 siblings, 1 reply; 6+ messages in thread
From: Chen Yufan @ 2024-08-22  1:54 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, dm-devel, linux-kernel
  Cc: opensource.kernel, Chen Yufan

Use time_after_eq macro instead of opening it for readability.

Signed-off-by: Chen Yufan <chenyufan@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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro
  2024-08-22  1:54 [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro Chen Yufan
@ 2024-08-22 17:08 ` Mikulas Patocka
  2024-08-23  9:18   ` 陈玉凡
  0 siblings, 1 reply; 6+ messages in thread
From: Mikulas Patocka @ 2024-08-22 17:08 UTC (permalink / raw)
  To: Chen Yufan
  Cc: Alasdair Kergon, Mike Snitzer, dm-devel, linux-kernel, opensource.kernel



On Thu, 22 Aug 2024, Chen Yufan wrote:

> Use time_after_eq macro instead of opening it for readability.
> 
> Signed-off-by: Chen Yufan <chenyufan@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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro
  2024-08-22 17:08 ` Mikulas Patocka
@ 2024-08-23  9:18   ` 陈玉凡
  2024-08-23 19:01     ` Mikulas Patocka
  0 siblings, 1 reply; 6+ messages in thread
From: 陈玉凡 @ 2024-08-23  9:18 UTC (permalink / raw)
  To: Mikulas Patocka, 陈玉凡
  Cc: Alasdair Kergon, Mike Snitzer, dm-devel, linux-kernel, opensource.kernel

在 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 <chenyufan@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
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro
  2024-08-23  9:18   ` 陈玉凡
@ 2024-08-23 19:01     ` Mikulas Patocka
       [not found]       ` <de43d61e-05c0-466f-b004-a97f2bf2ec39@vivo.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Mikulas Patocka @ 2024-08-23 19:01 UTC (permalink / raw)
  To: 陈玉凡
  Cc: Alasdair Kergon, Mike Snitzer, dm-devel, linux-kernel, opensource.kernel

[-- Attachment #1: Type: text/plain, Size: 1887 bytes --]



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 <chenyufan@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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro
       [not found]       ` <de43d61e-05c0-466f-b004-a97f2bf2ec39@vivo.com>
@ 2024-08-26  9:23         ` Mikulas Patocka
       [not found]           ` <e9a9f9f7-6c38-4ca7-8ccf-40275662cd34@vivo.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Mikulas Patocka @ 2024-08-26  9:23 UTC (permalink / raw)
  To: 陈玉凡
  Cc: Alasdair Kergon, Mike Snitzer, dm-devel, linux-kernel, opensource.kernel

[-- Attachment #1: Type: text/plain, Size: 2557 bytes --]



On Mon, 26 Aug 2024, 陈玉凡 wrote:

> 在 2024/8/24 3:01, Mikulas Patocka 写道:
> 
> 
> 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 <chenyufan@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
> 
> When jiffies increased beyond the maximum value of unsigned long, it 
> wraps around to zero, and the value of jiffies would be smaller than the 
> container_of(wc->lru.prev, struct wc_entry, lru)->age value despite 
> logically being larger. Eventurally, because of the wraparound, the 
> result of the condition would be wrong.
> 
> Chen

For example, if "jiffies" is 0x10 (because it wrapped around) and 
"container_of(wc->lru.prev, struct wc_entry, lru)->age" is 0xfffffff0, 
then the expression "jiffies - container_of(wc->lru.prev, struct wc_entry, 
lru)->age" would be 0x20. That is the correct value, I don't see any 
problem with this.

Mikulas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro
       [not found]           ` <e9a9f9f7-6c38-4ca7-8ccf-40275662cd34@vivo.com>
@ 2024-08-29 16:36             ` Mikulas Patocka
  0 siblings, 0 replies; 6+ messages in thread
From: Mikulas Patocka @ 2024-08-29 16:36 UTC (permalink / raw)
  To: 陈玉凡
  Cc: Alasdair Kergon, Mike Snitzer, dm-devel, linux-kernel, opensource.kernel

[-- Attachment #1: Type: text/plain, Size: 376 bytes --]



On Thu, 29 Aug 2024, 陈玉凡 wrote:

> When "jiffies" is 0x10 (because of wraparound) and 
> "container_of(wc->lru.prev, struct wc_entry, lru)->age" is 0x1(I'm not 
> sure if it can be such a small value), the result will change from a 
> large value to a small value.
> 
> Chen

So, the when you subtract the numbers, you get 0xf. There's nothing wrong 
with it.

Mikulas

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-08-29 16:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-22  1:54 [PATCH v1] Device-mapper(LVM): Convert to use time_after_eq macro Chen Yufan
2024-08-22 17:08 ` Mikulas Patocka
2024-08-23  9:18   ` 陈玉凡
2024-08-23 19:01     ` Mikulas Patocka
     [not found]       ` <de43d61e-05c0-466f-b004-a97f2bf2ec39@vivo.com>
2024-08-26  9:23         ` Mikulas Patocka
     [not found]           ` <e9a9f9f7-6c38-4ca7-8ccf-40275662cd34@vivo.com>
2024-08-29 16:36             ` Mikulas Patocka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®