Basic Linux IPC
D-Bus
D-Bus is a message bus system for inter-process communication (IPC
)
D-Bus is enabled automatically when using systemd because dbus is a dependency of systemd.
What’s D-Bus
a powerful IPC system
the closest thing to a standard in this area as can be found on Linux
provides a nice method-call transaction mechanism
- has fundamental inefficiencies of the user-space implementation
- well suited to control tasks
works well to tell a sound server to change the volume
- less so for anything that has to carry significant amounts of data
one would not want to try to send the actual audio data over the bus
In D-Bus a call-return message requires
10 message copies
,4 message validations
,4 context switches
D-Bus has
no timestamps on messages
not available at early boot
We need a better implementation ->
kdbus
D-Bus - Architecture
libdbus
dbus-daemon
wrapper libraries based on particular application frameworks
Interesting :
In 2013 the systemd project rewrote libdbus in an effort to simplify the code, but it turned out to significantly increase the performance of D-Bus as well.
In preliminary benchmarks, BMW found that the systemd D-Bus library increased performance by 360%.
kdbus
ALS: Linux interprocess communication and kdbus (May 30, 2013)
- The unveiling of kdbus (Jan 13, 2014)
Linux Kernel only have primitives IPC : sockets, FIFOs, and shared memory
- kdbus is a in-kernel implementation of D-Bus
- can carry large amounts of data
even used for gigabyte-sized message streams
have zero-copy message passing
worst case :
2 copy operations
,2 validations
,2 context switches
all messages carry timestamps
full credential information (user ID, process ID, SELinux label, control group information, capabilities, and much more) is passed with each message
always available to the system (no need to wait for the D-Bus daemon to be started)
Linux security modules can hook into it directly
various race conditions have been fixed
API has simplified
Kdbus is implemented as a
character device
in the kernelsignal broadcasting mechanism has been rewritten to use Bloom filters to select recipients
There is a user-space proxy server that can be used by older code that has not been rewritten to use the new API, so everything should just work on a kdbus-enabled system with no code changes required.
- the new
memfd
syscall was merged into Linux kernel 3.17 memfd
is a mechanism similar to Android’sashmem
that allowszero-copy
message passing in KDBUS.
- the new
Android “ashmem” subsystem
Android Binder
- Kdbus Details - Greg Kroah-Hartman
Binder vs. kdbus
Binder is bound to the CPU, D-Bus (and hence kdbus), is bound to RAM