lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 25 Jan 2024 20:28:30 +0800
From: Lance Yang <ioworker0@...il.com>
To: linux-kernel@...r.kernel.org
Cc: Michal Hocko <mhocko@...e.com>, linux-mm@...ck.org
Subject: [Issue] mprotect+madvise may be better than mmap for permission
 changes and page zeroing

Hello Everyone,

I've noticed that using mprotect(PROT_NONE) with
madvise(MADV_DONTNEED) is much faster than
mmap(PROT_NONE, MAP_FIXED) alone for changing
permissions and zeroing pages.

I have maintained a chunk-allocator internally at the
company. It allocates a chunk using
mmap(PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0),
releases a chunk using mmap(PROT_NONE, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0),
and reuses a chunk using mprotect(PROT_READ|PROT_WRITE).
Recently, I replaced mmap(PROT_NONE, MAP_FIXED) with
mprotect(PROT_NONE) + madvise(MADV_DONTNEED) to
reduce the latency of releasing chunks.

Test code:
https://github.com/ioworker0/mmapvsmprotect/blob/main/test2.c

Here are the test results on my machine:
CPU: AMD EPYC 7R13 Processor
Kernel: 6.2.0
Elapsed Time for mprotect+madvise: 3670 nanoseconds
Elapsed Time for mmap: 5520 nanoseconds

Thanks for your time!
Lance Yang

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ