]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
proc/kcore: don't walk list on every read
authorOmar Sandoval <osandov@fb.com>
Sat, 9 Nov 2024 01:28:40 +0000 (17:28 -0800)
committerChristian Brauner <brauner@kernel.org>
Mon, 2 Dec 2024 10:21:07 +0000 (11:21 +0100)
commit680e029fd62f7d9d8373788635f52c3de358d18d
tree83582f667f34ab44c67e7f67003a606bc7c73273
parentc9136fad4c08288be26aaff3e63d634545b32a85
proc/kcore: don't walk list on every read

We maintain a list of memory ranges for /proc/kcore, which usually has
10-20 entries. Currently, every single read from /proc/kcore walks the
entire list in order to count the number of entries and compute some
offsets. These values only change when the list of memory ranges
changes, which is very rare (only when memory is hot(un)plugged). We can
cache the values when the list is populated to avoid these redundant
walks.

In my benchmark, this reduces the time per read by another 20
nanoseconds on top of the previous change, from 215 nanoseconds per read
to 195.

Link: https://github.com/osandov/drgn/issues/106
Signed-off-by: Omar Sandoval <osandov@fb.com>
Link: https://lore.kernel.org/r/8d945558b9c9efe74103a34b7780f1cd90d9ce7f.1731115587.git.osandov@fb.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/proc/kcore.c