Search code examples
linuxperformancelinux-kernelperf

The consequences of changing perf_event_mlock_kb


I'm trying to understand the exact consequences of changing /proc/sys/kernel/perf_event_mlock_kb.

  • The man page for perf says

    Maximum number of pages an unprivileged user can mlock(2). The default is 516 (kB).

  • The kernel documentation says

    Control size of per-cpu ring buffer not counted agains mlock limit. The default value is 512 + 1 page

What confuses me is that both sources use two different units - the number of pages and Kb of memory. At the same time, the postfix _kb of the name implies that the file defines the number of Kb.

Is my understanding correct that the wording implies that the number should be devisable by the page size and if I set the file to 8046 on a machine with two vCPUs then perf will be able to take up to 16Mb of memory for the event buffers?


Solution

  • I think the kernel docs are missing a unit.

    It should be 512 kiB + 1 page = 516 kiB, matching the filename and the perf man page. The actual filename wouldn't still be named _kb if it had different units.

    cat /proc/sys/kernel/perf_event_mlock_kb on my system shows 516, so that pretty much confirms that it's in kiB.

    number should be devisable by the page size

    Yes, the number should be divisible by 4 to make the size divisible by the 4k page size, on x86.

    If not, the kernel presumably rounds up or down, IDK which.