linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V1] mm/damon: Modify damon_rand() macro to static inline function
@ 2021-12-06 12:41 Xin Hao
  2021-12-06 12:45 ` SeongJae Park
  0 siblings, 1 reply; 3+ messages in thread
From: Xin Hao @ 2021-12-06 12:41 UTC (permalink / raw)
  To: sj; +Cc: xhao, akpm, linux-mm, linux-kernel

The damon_rand() func can not be implemented as a macro.
Example:
	damon_rand(a++, b);
The value of 'a' will be incremented twice, This is obviously
unreasonable, So there fix it.

Fixes: b9a6ac4e4ede ("mm/damon: adaptively adjust regions")
Reported-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
---
 include/linux/damon.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index c6df025d8704..bc9c8932b1e8 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -19,7 +19,10 @@
 #define DAMOS_MAX_SCORE		(99)

 /* Get a random number in [l, r) */
-#define damon_rand(l, r) (l + prandom_u32_max(r - l))
+static inline unsigned long damon_rand(unsigned long l, unsigned long r)
+{
+	return l + (r - l);
+}

 /**
  * struct damon_addr_range - Represents an address region of [@start, @end).
--
2.31.0

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

* Re: [PATCH V1] mm/damon: Modify damon_rand() macro to static inline function
  2021-12-06 12:41 [PATCH V1] mm/damon: Modify damon_rand() macro to static inline function Xin Hao
@ 2021-12-06 12:45 ` SeongJae Park
  2021-12-06 12:48   ` Xin Hao
  0 siblings, 1 reply; 3+ messages in thread
From: SeongJae Park @ 2021-12-06 12:45 UTC (permalink / raw)
  To: Xin Hao; +Cc: sj, akpm, linux-mm, linux-kernel

On Mon, 6 Dec 2021 20:41:29 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:

> The damon_rand() func can not be implemented as a macro.
> Example:
> 	damon_rand(a++, b);
> The value of 'a' will be incremented twice, This is obviously
> unreasonable, So there fix it.
> 
> Fixes: b9a6ac4e4ede ("mm/damon: adaptively adjust regions")
> Reported-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
> ---
>  include/linux/damon.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index c6df025d8704..bc9c8932b1e8 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -19,7 +19,10 @@
>  #define DAMOS_MAX_SCORE		(99)
> 
>  /* Get a random number in [l, r) */
> -#define damon_rand(l, r) (l + prandom_u32_max(r - l))
> +static inline unsigned long damon_rand(unsigned long l, unsigned long r)
> +{
> +	return l + (r - l);

Seems prandom_u32_max() is missed?


Thanks,
SJ

> +}
> 
>  /**
>   * struct damon_addr_range - Represents an address region of [@start, @end).
> --
> 2.31.0

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

* Re: [PATCH V1] mm/damon: Modify damon_rand() macro to static inline function
  2021-12-06 12:45 ` SeongJae Park
@ 2021-12-06 12:48   ` Xin Hao
  0 siblings, 0 replies; 3+ messages in thread
From: Xin Hao @ 2021-12-06 12:48 UTC (permalink / raw)
  To: SeongJae Park; +Cc: akpm, linux-mm, linux-kernel


On 12/6/21 8:45 PM, SeongJae Park wrote:
> On Mon, 6 Dec 2021 20:41:29 +0800 Xin Hao <xhao@linux.alibaba.com> wrote:
>
>> The damon_rand() func can not be implemented as a macro.
>> Example:
>> 	damon_rand(a++, b);
>> The value of 'a' will be incremented twice, This is obviously
>> unreasonable, So there fix it.
>>
>> Fixes: b9a6ac4e4ede ("mm/damon: adaptively adjust regions")
>> Reported-by: Andrew Morton <akpm@linux-foundation.org>
>> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
>> ---
>>   include/linux/damon.h | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/damon.h b/include/linux/damon.h
>> index c6df025d8704..bc9c8932b1e8 100644
>> --- a/include/linux/damon.h
>> +++ b/include/linux/damon.h
>> @@ -19,7 +19,10 @@
>>   #define DAMOS_MAX_SCORE		(99)
>>
>>   /* Get a random number in [l, r) */
>> -#define damon_rand(l, r) (l + prandom_u32_max(r - l))
>> +static inline unsigned long damon_rand(unsigned long l, unsigned long r)
>> +{
>> +	return l + (r - l);
> Seems prandom_u32_max() is missed?

Sorry, my fault, i write a simple test case like this, but i forgot to 
correct in patch, i will send a new one.

#include <stdio.h>

#define damon_rand(l, r) (l + (r - l))
static inline long damon_rand1(int l, int r)
{
         return l + (r - l);
}

int main(void)
{

         int a = 0;
         int b = 0;
         damon_rand(a++, 4);
         damon_rand1(b++, 4);

         printf("a is %d \n", a);
         printf("b is %d \n", b);

         return 0;
}

>
>
> Thanks,
> SJ
>
>> +}
>>
>>   /**
>>    * struct damon_addr_range - Represents an address region of [@start, @end).
>> --
>> 2.31.0

-- 
Best Regards!
Xin Hao


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

end of thread, other threads:[~2021-12-06 12:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-06 12:41 [PATCH V1] mm/damon: Modify damon_rand() macro to static inline function Xin Hao
2021-12-06 12:45 ` SeongJae Park
2021-12-06 12:48   ` Xin Hao

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).