Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method to avoid the overhead caused by clear_page_emrs() in the kernel?

I followed this method and found that clear_page_erms generated a significant amount of overhead in the flame graph.

After searching the Internet, I learned that the purpose of this function is to zeroize pages allocated by the kernel during page fault. Considering that my workload is not a multi-tenant cloud environment and there will be no malicious software or attack behavior, can I control the kernel to relax these security features and bypass this reset operation to improve performance?

I am using kernel 5.14, AMD processor, and do not enable huge pages or transparent huge pages.

The relevant kernel parameters are all not set:

#
# Memory initialization
#
CONFIG_INIT_STACK_NONE=y
# CONFIG_INIT_ON_ALLOC_DEFAULT_ON is not set
# CONFIG_INIT_ON_FREE_DEFAULT_ON is not set
# end of Memory initialization
# end of Kernel hardening options
# end of Security options
like image 646
Frontier_Setter Avatar asked Sep 13 '25 03:09

Frontier_Setter


1 Answers

No you cannot. While it obviously has security implications, zeroing out pages is not just a security feature, it is a well-defined basic functionality of the kernel. A normal system cannot correctly work without the kernel zeroing out pages before making them available to userspace, as userspace programs will expect them zeroed out.

If you have a custom kernel compiled with CONFIG_MMAP_ALLOW_UNINITIALIZED=y, then userspace programs can explicitly opt-out of automatic page initialization by passing MAP_UNINITIALIZED to mmap, but that's about it.

Regardless though, even having CONFIG_MMAP_ALLOW_UNINITIALIZED=y isn't really going to do much on any normal system as a whole, since normal programs usually never pass that flag and expect zeroed out memory after mmap. In the context of a single application though it may help and make a significant difference.

like image 90
Marco Bonelli Avatar answered Sep 14 '25 22:09

Marco Bonelli