Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use much faster getcpu() via vDSO #424

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

jserv
Copy link
Contributor

@jserv jserv commented Jun 26, 2021

vDSO (virtual dynamic shared object) is exported by Linux kernel into every userspace program, designed to speed up this process for certain system calls. For Linux/x86_64, getcpu() can be called via vDSO, which
makes getcpu() much faster. The faster getcpu() invocation is beneficial when retrieving NUMA node information.

Benchmarking on AMD Ryzen Threadripper 2990WX 32-Core Processor:

  getcpu: syscall: 103 nsec/call
  getcpu:    vdso: 18 nsec/call

@jserv jserv force-pushed the getcpu-vdso branch 5 times, most recently from d95825a to cfca58a Compare June 26, 2021 16:03
vDSO (virtual dynamic shared object) is exported by Linux kernel into
every userspace program, designed to speed up this process for certain
system calls. For Linux/x86_64, getcpu() can be called via vDSO, which
makes getcpu() much faster. The faster getcpu() invocation is beneficial
when retrieving NUMA node information.

Benchmarking[1] on AMD Ryzen Threadripper 2990WX 32-Core Processor:
  getcpu: syscall: 103 nsec/call
  getcpu:    vdso: 18 nsec/call

We can not use dlsym to resolve the vDSO symbol "__vdso_getcpu" directly
becase it would cause recursive malloc calls when MI_DEBUG_FULL is enabled.

[1] https://github.com/nathanlynch/vdsotest

Co-authored-by: Chin-Hao Lo <[email protected]>
Signed-off-by: Jim Huang <[email protected]>
@LifeIsStrange
Copy link

@jserv noob question: why doesn't the default GLIBC getcpu() doesn't leverage vdso?

@jserv
Copy link
Contributor Author

jserv commented Jan 5, 2022

@jserv noob question: why doesn't the default GLIBC getcpu() doesn't leverage vdso?

In glibc development, getcpu was absent until the commit on Dec 7, 2018. That is the reason why mimalloc uses syscall to invoke getcpu. Then, glibc version 2.29 included getcpu system call wrapper. vDSO path can be enabled since glibc-2.29, but not every major Linux distribution ships with glibc-2.29+. For example, Red Hat Enterprise Linux 8 uses glibc-2.28.

@LifeIsStrange
Copy link

Thanks for your technical excellence :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants