Skip to contentSkip to conversation

Minor page faults from memory compaction causing in-band transitions

DISCUSSION Brandon Ho 4 participants 9 messages Mar 31 – Apr 14 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Brandon Ho

author
#0 lore raw

Hi Xenomai team,

I'm working on a real-time control application using Xenomai and we've been experiencing unexpected in-band transitions caused by minor page faults during kernel memory compaction. Even though our RT threads use mlockall(MCL_CURRENT | MCL_FUTURE) and we've pre-faulted memory, the kernel's compaction process seems to temporarily invalidate PTEs on our locked pages, causing faults when the RT thread accesses them.

Has this issue come up before? I'm wondering if there's a mechanism to reserve a section of RAM that's excluded from compaction/migration entirely, or if there are kernel/Xenomai configurations we should be using to prevent this.

Any guidance would be appreciated!

Thanks,
Brandon

#1 lore raw
Quoted 9 lines · Brandon Ho

Hi Xenomai team,

I'm working on a real-time control application using Xenomai and we've been experiencing unexpected in-band transitions caused by minor page faults during kernel memory compaction. Even though our RT threads use mlockall(MCL_CURRENT | MCL_FUTURE) and we've pre-faulted memory, the kernel's compaction process seems to temporarily invalidate PTEs on our locked pages, causing faults when the RT thread accesses them.

Quoted 5 lines

Has this issue come up before? I'm wondering if there's a mechanism to reserve a section of RAM that's excluded from compaction/migration entirely, or if there are kernel/Xenomai configurations we should be using to prevent this.

Any guidance would be appreciated!

Memory migration as well as compaction are not compatible with deterministic system behavior. Both Xenomai 3 and 4 should warn about them, and you should disabling these features in your kernel. Unfortunately, current kernels do not allow a more fine-grained control.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#2 lore raw
In reply to Brandon Ho
Quoted 10 lines · Brandon Ho

Hi Xenomai team,

I'm working on a real-time control application using Xenomai and we've been experiencing unexpected in-band transitions caused by minor page faults during kernel memory compaction. Even though our RT threads use mlockall(MCL_CURRENT | MCL_FUTURE) and we've pre-faulted memory, the kernel's compaction process seems to temporarily invalidate PTEs on our locked pages, causing faults when the RT thread accesses them.

Has this issue come up before?

Yes, this is a known issue.

Quoted 3 lines

I'm wondering if there's a mechanism to reserve
a section of RAM that's excluded from compaction/migration entirely, or if

Not to my knowledge.

Quoted 4 lines

there are kernel/Xenomai configurations we should be using to prevent this.

Any guidance would be appreciated!

As Jan mentioned, the only way is to disable all options which select CONFIG_COMPACTION ATM.

Signature · 1 line
Philippe.
author
#3 lore raw

Thank you for the responses! I recently came across the compact_unevictable_allowed sysctl option and it seems like it could be a good fit for our use case. Setting it to 0 would prevent the kernel from compacting/migrating locked pages, which should eliminate the minor faults we're seeing during compaction.

Could we possibly set compact_unevictable_allowed=0 by default when CONFIG_EVL is enabled?

https://www.infradead.org/~mchehab/kernel_docs/admin-guide/sysctl/vm.html#compact-unevictable-allowed

#4 lore raw
Quoted 8 lines · Brandon Ho

Thank you for the responses! I recently came across the compact_unevictable_allowed sysctl option and it seems like it could be a good fit for our use case. Setting it to 0 would prevent the kernel from compacting/migrating locked pages, which should eliminate the minor faults we're seeing during compaction.

Could we possibly set compact_unevictable_allowed=0 by default when CONFIG_EVL is enabled?

Definitely, yes. Thanks for chasing this issue down. This patch is going to be merged upstream asap, you may want to apply it for a preview.

mm/Kconfig +1 -1
index 7bf469354faf3..759af896a5c7b 100644
@@ -648,7 +648,7 @@ config COMPACTION
 config COMPACT_UNEVICTABLE_DEFAULT
 	int
 	depends on COMPACTION
-	default 0 if PREEMPT_RT
+	default 0 if PREEMPT_RT || DOVETAIL
 	default 1
 
 #
Quoted 2 lines

https://www.infradead.org/~mchehab/kernel_docs/admin-guide/sysctl/vm.html#compact-unevictable-allowed

Signature · 1 line
Philippe.
#6 lore raw
In reply to a message not in the archive
Quoted 2 lines · Jay Sridharan

I think it would also be very useful to add these considerations to the "Caveat" page in the EVL documentation.

Agreed.

Quoted 7 lines

Perhaps some discussion on the impacts of CONFIG_COMPACTION, CONFIG_MIGRATION and CONFIG_TRANSPARENT_HUGEPAGE, as well as the impact of COMPACT_UNEVICTABLE_DEFAULT.

I know the Caveat page already has an in-depth discussion of CPU isolation and SMIs, so it feels like a good place to mention it.

Is there a place where we can submit a patch to the docs?

Yes, please send a patch to this list, the markdown files for the website can be cloned from [1].

[1] https://gitlab.com/Xenomai/xenomai4/website

Signature · 1 line
Philippe.
#7 lore raw
In reply to Philippe Gerum
Quoted 8 lines · Philippe Gerum
Quoted 6 lines · Brandon Ho

Thank you for the responses! I recently came across the compact_unevictable_allowed sysctl option and it seems like it could be a good fit for our use case. Setting it to 0 would prevent the kernel from compacting/migrating locked pages, which should eliminate the minor faults we're seeing during compaction.

Quoted 5 lines
Quoted 2 lines

Could we possibly set compact_unevictable_allowed=0 by default when CONFIG_EVL is enabled?

Definitely, yes. Thanks for chasing this issue down. This patch is going to be merged upstream asap, you may want to apply it for a preview.

Targeting linux-evl or linux-dovetail?

This is of interest for Xenomai 3 as well, so merging on Dovetail-level would be nice.

The same applies for the documentation update. Once we have it for x4 we should consider that for x4 as well.

Quoted 20 lines
mm/Kconfig +0 -0
index 7bf469354faf3..759af896a5c7b 100644
@@ -648,7 +648,7 @@ config COMPACTION

 config COMPACT_UNEVICTABLE_DEFAULT
  int
  depends on COMPACTION

mm/Kconfig +1 -1
-	default 0 if PREEMPT_RT
+	default 0 if PREEMPT_RT || DOVETAIL

  default 1

 #

Quoted 2 lines

https://www.infradead.org/~mchehab/kernel_docs/admin-guide/sysctl/vm.html#compact-unevictable-allowed

--
Philippe.

#8 lore raw
Quoted 9 lines · Florian Bezdeka
Quoted 8 lines · Philippe Gerum
Quoted 6 lines · Brandon Ho

Thank you for the responses! I recently came across the compact_unevictable_allowed sysctl option and it seems like it could be a good fit for our use case. Setting it to 0 would prevent the kernel from compacting/migrating locked pages, which should eliminate the minor faults we're seeing during compaction.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Could we possibly set compact_unevictable_allowed=0 by default when CONFIG_EVL is enabled?

Definitely, yes. Thanks for chasing this issue down. This patch is going to be merged upstream asap, you may want to apply it for a preview.

Targeting linux-evl or linux-dovetail?

linux-dovetail, this is a general issue for any latency-sensitive code.

Signature · 1 line
Philippe.
#9 lore raw
Quoted 14 lines · Philippe Gerum
Quoted 12 lines · Florian Bezdeka
Quoted 11 lines · Philippe Gerum
Quoted 8 lines · Brandon Ho

Thank you for the responses! I recently came across the compact_unevictable_allowed sysctl option and it seems like it could be a good fit for our use case. Setting it to 0 would prevent the kernel from compacting/migrating locked pages, which should eliminate the minor faults we're seeing during compaction.

Could we possibly set compact_unevictable_allowed=0 by default when CONFIG_EVL is enabled?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Definitely, yes. Thanks for chasing this issue down. This patch is going to be merged upstream asap, you may want to apply it for a preview.

Targeting linux-evl or linux-dovetail?

linux-dovetail, this is a general issue for any latency-sensitive code.

While reviewing all PREEMPT_RT exclusion cases in Kconfigs, some of which Dovetail may want to share, I found this potential one:

init/Kconfig +1 -1
@@ -947,7 +947,7 @@ config NUMA_BALANCING
 	bool "Memory placement aware NUMA scheduler"
 	depends on ARCH_SUPPORTS_NUMA_BALANCING
 	depends on !ARCH_WANT_NUMA_VARIABLE_LOCALITY
-	depends on SMP && NUMA && MIGRATION && !PREEMPT_RT
+	depends on SMP && NUMA && MIGRATION && !PREEMPT_RT && !DOVETAIL
 

Any objection to disabling NUMA_BALANCING when operating in dual kernel mode? (CONFIG_DOVETAIL=y).

Signature · 1 line
Philippe.