mariadb/storage
Marko Mäkelä 2323483528 MDEV-31953 madvise(..., MADV_FREE) is causing a performance regression
buf_page_t::set_os_unused(): Remove the system call that had been added in
commit 16c9718758 and revised in
commit c1fd082e9c for Microsoft Windows.

buf_pool_t::garbage_collect(): A new function to collect any garbage
from the InnoDB buffer pool that can be removed without writing any
log or data files. This will also invoke madvise() for all of buf_pool.free.

To trigger this the following MDEV is implemented:
MDEV-24670 avoid OOM by linux kernel co-operative memory management

To avoid frequent triggers that caused the MDEV-31953 regression, while
still preserving the 10.11 functionality of non-greedy kernel memory
usage, memory triggers are used.

On the triggering of memory pressure, if supported in the Linux kernel,
trigger the garbage collection of the innodb buffer pool.

The hard coded triggers occur where there is:
* some memory pressure in 5 of the last 10 seconds
* a full stall on memory pressure for 10ms in the last 2 seconds

The kernel will trigger only one in each of these time windows. To avoid
mariadb being in a constant state of memory garbage collection, this has
been limited to once per minute.

For a small set of kernels in 2023 (6.5, 6.6), there was a limit requiring
CAP_SYS_RESOURCE that was lifted[1] to support the use case of user
memory pressure. It not currently possible to set CAP_SYS_RESOURCES in
a systemd service as its setting a capability inside a usernamespace.

Running under systemd v254+ requires the default MemoryPressureWatch=auto
(or alternately "on").

Functionality was tested in a 6.4 kernel Fedora successfully under a
systemd service.

Running in a container requires that (unmask=)/sys/fs/cgroup be writable
by the mariadbd process.

To aid testing, the buf_pool_resize was a convient trigger point on
which to trigger garbage collection.

ref [1]: https://lore.kernel.org/all/CAMw=ZnQ56cm4Txgy5EhGYvR+Jt4s-KVgoA9_65HKWVMOXp7a9A@mail.gmail.com/T/#m3bd2a73c5ee49965cb73a830b1ccaa37ccf4e427

Co-Author: Daniel Black (on memory pressure trigger)

Reviewed by: Marko Mäkelä, Vladislav Vaintroub, Vladislav Lesin,
   Thirunarayanan Balathandayuthapani

Tested by: Matthias Leich
2023-11-18 20:12:33 +11:00
..
archive Merge branch '10.6' into 10.10 2023-11-08 16:23:30 +01:00
blackhole Merge 10.4 into 10.5 2023-02-10 12:02:11 +02:00
columnstore Merge branch '10.6' into 10.10 2023-11-08 16:23:30 +01:00
connect Merge 10.10 into 10.11 2023-10-17 16:04:21 +03:00
csv MDEV-26635 ROW_NUMBER is not 0 for errors not caused because of rows 2021-10-26 17:29:40 +02:00
example Merge 10.6 into 10.8 2023-02-10 13:43:53 +02:00
federated Merge 10.5 into 10.6 2023-02-10 13:03:01 +02:00
federatedx Merge 10.6 into 10.8 2023-02-10 13:43:53 +02:00
heap Merge 10.5 into 10.6 2023-02-10 13:03:01 +02:00
innobase MDEV-31953 madvise(..., MADV_FREE) is causing a performance regression 2023-11-18 20:12:33 +11:00
maria Merge branch '10.6' into 10.10 2023-11-08 16:23:30 +01:00
mroonga Merge branch '10.6' into 10.10 2023-11-08 16:23:30 +01:00
myisam Merge branch '10.6' into 10.10 2023-11-08 16:23:30 +01:00
myisammrg Merge 10.6 into 10.9 2023-05-25 09:24:32 +03:00
oqgraph Merge 10.6 into 10.10 2023-10-14 13:36:11 +03:00
perfschema Merge 10.10 into 10.11 2023-10-19 14:50:42 +03:00
rocksdb Merge branch '10.10' into 10.11 2023-11-08 16:46:47 +01:00
sequence Merge 10.4 into 10.5 2023-02-10 12:02:11 +02:00
sphinx Merge branch '10.5' into 10.6 2022-11-02 14:33:20 +01:00
spider Merge branch '10.10' into 10.11 2023-11-08 16:46:47 +01:00
test_sql_discovery Merge 10.5 into 10.6 2022-09-20 16:53:20 +03:00