linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmscan: simplify the nr assignment logic for pages to scan
@ 2022-11-09  7:04 Chao Xu
  2022-11-10  1:19 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Xu @ 2022-11-09  7:04 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Chao Xu

By default the assignment logic of anonymouns or file inactive
pages and active pages to scan using the same duplicated code
snippet. To simplify the logic, merge the same part.

Signed-off-by: Chao Xu <Chao.Xu9@zeekrlife.com>
---
 mm/vmscan.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 04d8b88e5216..df3c0cbe381f 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5932,14 +5932,11 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
 		 * scan target and the percentage scanning already complete
 		 */
 		lru = (lru == LRU_FILE) ? LRU_BASE : LRU_FILE;
-		nr_scanned = targets[lru] - nr[lru];
-		nr[lru] = targets[lru] * (100 - percentage) / 100;
-		nr[lru] -= min(nr[lru], nr_scanned);
-
-		lru += LRU_ACTIVE;
-		nr_scanned = targets[lru] - nr[lru];
-		nr[lru] = targets[lru] * (100 - percentage) / 100;
-		nr[lru] -= min(nr[lru], nr_scanned);
+		for ( ; lru <= lru + LRU_ACTIVE; lru++) {
+			nr_scanned = targets[lru] - nr[lru];
+			nr[lru] = targets[lru] * (100 - percentage) / 100;
+			nr[lru] -= min(nr[lru], nr_scanned);
+		}
 
 		scan_adjusted = true;
 	}
-- 
2.34.1


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

* Re: [PATCH] mm/vmscan: simplify the nr assignment logic for pages to scan
  2022-11-09  7:04 [PATCH] mm/vmscan: simplify the nr assignment logic for pages to scan Chao Xu
@ 2022-11-10  1:19 ` Andrew Morton
  2022-11-10  2:48   ` Chao Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2022-11-10  1:19 UTC (permalink / raw)
  To: Chao Xu; +Cc: linux-mm, linux-kernel, Chao Xu

On Wed,  9 Nov 2022 15:04:16 +0800 Chao Xu <amos.xuchao@gmail.com> wrote:

> By default the assignment logic of anonymouns or file inactive
> pages and active pages to scan using the same duplicated code
> snippet. To simplify the logic, merge the same part.
> 
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -5932,14 +5932,11 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
>  		 * scan target and the percentage scanning already complete
>  		 */
>  		lru = (lru == LRU_FILE) ? LRU_BASE : LRU_FILE;
> -		nr_scanned = targets[lru] - nr[lru];
> -		nr[lru] = targets[lru] * (100 - percentage) / 100;
> -		nr[lru] -= min(nr[lru], nr_scanned);
> -
> -		lru += LRU_ACTIVE;
> -		nr_scanned = targets[lru] - nr[lru];
> -		nr[lru] = targets[lru] * (100 - percentage) / 100;
> -		nr[lru] -= min(nr[lru], nr_scanned);
> +		for ( ; lru <= lru + LRU_ACTIVE; lru++) {

The "lru++" implicitly assumes that LRU_ACTIVE=1.  That happens to be
the case, but a more accurate translation of the existing code would
use "lru += LRU_ACTIVE" here, yes?

> +			nr_scanned = targets[lru] - nr[lru];
> +			nr[lru] = targets[lru] * (100 - percentage) / 100;
> +			nr[lru] -= min(nr[lru], nr_scanned);
> +		}
>  
>  		scan_adjusted = true;
>  	}


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

* Re: [PATCH] mm/vmscan: simplify the nr assignment logic for pages to scan
  2022-11-10  1:19 ` Andrew Morton
@ 2022-11-10  2:48   ` Chao Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Chao Xu @ 2022-11-10  2:48 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Chao Xu


在 2022/11/10 9:19, Andrew Morton 写道:
> On Wed,  9 Nov 2022 15:04:16 +0800 Chao Xu <amos.xuchao@gmail.com> wrote:
>
>> By default the assignment logic of anonymouns or file inactive
>> pages and active pages to scan using the same duplicated code
>> snippet. To simplify the logic, merge the same part.
>>
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -5932,14 +5932,11 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
>>   		 * scan target and the percentage scanning already complete
>>   		 */
>>   		lru = (lru == LRU_FILE) ? LRU_BASE : LRU_FILE;
>> -		nr_scanned = targets[lru] - nr[lru];
>> -		nr[lru] = targets[lru] * (100 - percentage) / 100;
>> -		nr[lru] -= min(nr[lru], nr_scanned);
>> -
>> -		lru += LRU_ACTIVE;
>> -		nr_scanned = targets[lru] - nr[lru];
>> -		nr[lru] = targets[lru] * (100 - percentage) / 100;
>> -		nr[lru] -= min(nr[lru], nr_scanned);
>> +		for ( ; lru <= lru + LRU_ACTIVE; lru++) {
> The "lru++" implicitly assumes that LRU_ACTIVE=1.  That happens to be
> the case, but a more accurate translation of the existing code would
> use "lru += LRU_ACTIVE" here, yes?
By default the value of LRU_ACTIVE is 1,but if someone change it one day, I
use "lru++" maybe facing some exceptions, which is not robust. So I 
agree with
that "lru += LRU_ACTIVE" is appropriate instead of "lru++". I will send 
a new patch.
>> +			nr_scanned = targets[lru] - nr[lru];
>> +			nr[lru] = targets[lru] * (100 - percentage) / 100;
>> +			nr[lru] -= min(nr[lru], nr_scanned);
>> +		}
>>   
>>   		scan_adjusted = true;
>>   	}

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

end of thread, other threads:[~2022-11-10  2:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09  7:04 [PATCH] mm/vmscan: simplify the nr assignment logic for pages to scan Chao Xu
2022-11-10  1:19 ` Andrew Morton
2022-11-10  2:48   ` Chao Xu

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