* [PATCH] mm/compaction: Reduce unnecessary loops
@ 2024-01-12 7:35 Bang Li
2024-01-12 19:25 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Bang Li @ 2024-01-12 7:35 UTC (permalink / raw)
To: akpm
Cc: linux-mm, linux-kernel, 朱辉(茶水),
Yan Yan(cailing),
Bang Li
Compaction will be triggered when we write 1 to '/proc/sys/vm/
compact_memory'. During the execution of the process, when we send
SIGKILL to terminate the compaction, the process does not exit
immediately. Instead, it will continue to loop through the remaining
zones and nodes before exiting.
in my environment:
[root]# cat /proc/buddyinfo
Node 0, zone DMA 1 1 1 0 2 1 1 0 1 1 3
Node 0, zone DMA32 1666 1123 804 625 488 356 321 278 209 178 250
Node 0, zone Normal 58852 83160 49983 9812 2287 1229 19604 24471 10346 5219 12205
[root]# echo 1 > /sys/kernel/debug/tracing/events/compaction/mm_compaction_end/enable
before the patch:
[root]# timeout --signal=SIGKILL 0.002 bash -c 'echo 1 > /proc/sys/vm/compact_memory'
[root]# cat /sys/kernel/debug/tracing/trace_pipe
<...>-26494 [014] ..... 226.468993: mm_compaction_end: zone_start=0x1 migrate_pfn=0xe00 free_pfn=0xe00 zone_end=0x1000, mode=sync status=complete
<...>-26494 [014] ..... 226.469718: mm_compaction_end: zone_start=0x1000 migrate_pfn=0x20a80 free_pfn=0xffe00 zone_end=0x100000, mode=sync status=contended
<...>-26494 [014] ..... 226.469720: mm_compaction_end: zone_start=0x100000 migrate_pfn=0x100000 free_pfn=0x307fe00 zone_end=0x3080000, mode=sync status=contended
after the patch:
[root]# timeout --signal=SIGKILL 0.002 bash -c 'echo 1 > /proc/sys/vm/compact_memory'
[root]# cat /sys/kernel/debug/tracing/trace_pipe
<...>-17491 [053] ..... 109.005387: mm_compaction_end: zone_start=0x1 migrate_pfn=0xe00 free_pfn=0xe00 zone_end=0x1000, mode=sync status=complete
<...>-17491 [053] ..... 109.006139: mm_compaction_end: zone_start=0x1000 migrate_pfn=0x22220 free_pfn=0xffe00 zone_end=0x100000, mode=sync status=contended
Although it exits quickly after receiving the SIGKILL signal, a better
solution is to terminate the loop early after receiving the SIGKILL
signal.
Signed-off-by: Bang Li <libang.li@antgroup.com>
---
mm/compaction.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/mm/compaction.c b/mm/compaction.c
index 27ada42924d5..16f2bde5205d 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -2807,7 +2807,7 @@ static void proactive_compact_node(pg_data_t *pgdat)
}
/* Compact all zones within a node */
-static void compact_node(int nid)
+static int compact_node(int nid)
{
pg_data_t *pgdat = NODE_DATA(nid);
int zoneid;
@@ -2830,7 +2830,12 @@ static void compact_node(int nid)
cc.zone = zone;
compact_zone(&cc, NULL);
+
+ if (fatal_signal_pending(current))
+ return -EINTR;
}
+
+ return 0;
}
/* Compact all nodes in the system */
@@ -2841,8 +2846,10 @@ static void compact_nodes(void)
/* Flush pending updates to the LRU lists */
lru_add_drain_all();
- for_each_online_node(nid)
- compact_node(nid);
+ for_each_online_node(nid) {
+ if (compact_node(nid))
+ break;
+ }
}
static int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
--
2.19.1.6.gb485710b
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/compaction: Reduce unnecessary loops
2024-01-12 7:35 [PATCH] mm/compaction: Reduce unnecessary loops Bang Li
@ 2024-01-12 19:25 ` Andrew Morton
2024-01-13 5:52 ` Bang Li
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2024-01-12 19:25 UTC (permalink / raw)
To: Bang Li
Cc: linux-mm, linux-kernel, 朱辉(茶水) ,
Yan Yan(cailing)
On Fri, 12 Jan 2024 15:35:24 +0800 "Bang Li" <libang.li@antgroup.com> wrote:
> Compaction will be triggered when we write 1 to '/proc/sys/vm/
> compact_memory'. During the execution of the process, when we send
> SIGKILL to terminate the compaction, the process does not exit
> immediately. Instead, it will continue to loop through the remaining
> zones and nodes before exiting.
>
> in my environment:
>
> [root]# cat /proc/buddyinfo
> Node 0, zone DMA 1 1 1 0 2 1 1 0 1 1 3
> Node 0, zone DMA32 1666 1123 804 625 488 356 321 278 209 178 250
> Node 0, zone Normal 58852 83160 49983 9812 2287 1229 19604 24471 10346 5219 12205
> [root]# echo 1 > /sys/kernel/debug/tracing/events/compaction/mm_compaction_end/enable
>
> before the patch:
>
> [root]# timeout --signal=SIGKILL 0.002 bash -c 'echo 1 > /proc/sys/vm/compact_memory'
> [root]# cat /sys/kernel/debug/tracing/trace_pipe
> <...>-26494 [014] ..... 226.468993: mm_compaction_end: zone_start=0x1 migrate_pfn=0xe00 free_pfn=0xe00 zone_end=0x1000, mode=sync status=complete
> <...>-26494 [014] ..... 226.469718: mm_compaction_end: zone_start=0x1000 migrate_pfn=0x20a80 free_pfn=0xffe00 zone_end=0x100000, mode=sync status=contended
> <...>-26494 [014] ..... 226.469720: mm_compaction_end: zone_start=0x100000 migrate_pfn=0x100000 free_pfn=0x307fe00 zone_end=0x3080000, mode=sync status=contended
>
> after the patch:
>
> [root]# timeout --signal=SIGKILL 0.002 bash -c 'echo 1 > /proc/sys/vm/compact_memory'
> [root]# cat /sys/kernel/debug/tracing/trace_pipe
> <...>-17491 [053] ..... 109.005387: mm_compaction_end: zone_start=0x1 migrate_pfn=0xe00 free_pfn=0xe00 zone_end=0x1000, mode=sync status=complete
> <...>-17491 [053] ..... 109.006139: mm_compaction_end: zone_start=0x1000 migrate_pfn=0x22220 free_pfn=0xffe00 zone_end=0x100000, mode=sync status=contended
>
> Although it exits quickly after receiving the SIGKILL signal, a better
> solution is to terminate the loop early after receiving the SIGKILL
> signal.
>
What is the use case here? The requirement? Why is this change
valuable to anyone?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/compaction: Reduce unnecessary loops
2024-01-12 19:25 ` Andrew Morton
@ 2024-01-13 5:52 ` Bang Li
0 siblings, 0 replies; 3+ messages in thread
From: Bang Li @ 2024-01-13 5:52 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, 朱辉(茶水),
Yan Yan(cailing)
On 2024/1/13 3:25, Andrew Morton wrote:
> On Fri, 12 Jan 2024 15:35:24 +0800 "Bang Li" <libang.li@antgroup.com> wrote:
>
>> Compaction will be triggered when we write 1 to '/proc/sys/vm/
>> compact_memory'. During the execution of the process, when we send
>> SIGKILL to terminate the compaction, the process does not exit
>> immediately. Instead, it will continue to loop through the remaining
>> zones and nodes before exiting.
>>
>> in my environment:
>>
>> [root]# cat /proc/buddyinfo
>> Node 0, zone DMA 1 1 1 0 2 1 1 0 1 1 3
>> Node 0, zone DMA32 1666 1123 804 625 488 356 321 278 209 178 250
>> Node 0, zone Normal 58852 83160 49983 9812 2287 1229 19604 24471 10346 5219 12205
>> [root]# echo 1 > /sys/kernel/debug/tracing/events/compaction/mm_compaction_end/enable
>>
>> before the patch:
>>
>> [root]# timeout --signal=SIGKILL 0.002 bash -c 'echo 1 > /proc/sys/vm/compact_memory'
>> [root]# cat /sys/kernel/debug/tracing/trace_pipe
>> <...>-26494 [014] ..... 226.468993: mm_compaction_end: zone_start=0x1 migrate_pfn=0xe00 free_pfn=0xe00 zone_end=0x1000, mode=sync status=complete
>> <...>-26494 [014] ..... 226.469718: mm_compaction_end: zone_start=0x1000 migrate_pfn=0x20a80 free_pfn=0xffe00 zone_end=0x100000, mode=sync status=contended
>> <...>-26494 [014] ..... 226.469720: mm_compaction_end: zone_start=0x100000 migrate_pfn=0x100000 free_pfn=0x307fe00 zone_end=0x3080000, mode=sync status=contended
>>
>> after the patch:
>>
>> [root]# timeout --signal=SIGKILL 0.002 bash -c 'echo 1 > /proc/sys/vm/compact_memory'
>> [root]# cat /sys/kernel/debug/tracing/trace_pipe
>> <...>-17491 [053] ..... 109.005387: mm_compaction_end: zone_start=0x1 migrate_pfn=0xe00 free_pfn=0xe00 zone_end=0x1000, mode=sync status=complete
>> <...>-17491 [053] ..... 109.006139: mm_compaction_end: zone_start=0x1000 migrate_pfn=0x22220 free_pfn=0xffe00 zone_end=0x100000, mode=sync status=contended
>>
>> Although it exits quickly after receiving the SIGKILL signal, a better
>> solution is to terminate the loop early after receiving the SIGKILL
>> signal.
>>
>
> What is the use case here? The requirement? Why is this change
> valuable to anyone?
Thanks for the quick reply! I'm very sorry that my inappropriate use
case confused you. What I want to explain is that when receiving the
SIGKILL signal, we can break in advance to reduce unnecessary loops.
This is a clean up patch, the purpose is to reduce the execution of
unnecessary code. If possible, I will remove the confusing use case
in V2.
Thanks,
Bang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-13 5:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-12 7:35 [PATCH] mm/compaction: Reduce unnecessary loops Bang Li
2024-01-12 19:25 ` Andrew Morton
2024-01-13 5:52 ` Bang Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox