r/linux • u/Fcking_Chuck • 7d ago
Kernel 17k lines of new Rust kernel code heading into Linux 7.4
https://www.phoronix.com/news/Linux-7.4-Rust34
u/editor_of_the_beast 7d ago
Is there FFI to communicate with C and is there a performance hit for that?
63
u/afiefh 7d ago
Calling C functions from Rust is basically just a matter of opening an unsafe block and using C typed arguments.
While the call itself has zero overhead, if the structures in use need to be converted then that's overhead. Luckily Rust can use the same struct layout as C, so in many cases no conversion is necessary at all.
In most cases you end up getting a small adapter library that defines how the ffi should be handled i.e. it encodes the safe Rust interfaces (lifetimes...etc) to allow calling the C functions more easily and without opening an unsafe block every time.
Rustonomicon has the documentation: https://doc.rust-lang.org/nomicon/ffi.html
→ More replies (8)17
u/luciferoussky72 7d ago
Most likely, yes, although Rust can interface with C with no cost if you do it in a certain way with C-compatible types
75
u/Splatoonkindaguy 7d ago
How do I Larp this
62
u/mrheosuper 6d ago
You fork a thousand-stars repo, append "-rs" to its name, then ask your favorite chatbot to rewrite in Rust.
24
u/nicolasdanelon 6d ago
And post on reddit "I built a performant replacement for _____"
12
u/DonkeeeyKong 6d ago
And post on reddit "I built a performant replacement for _____"
You forgot to start with "I was tired of …"
5
1
u/dronmore 6d ago
Fasten your seatbelt, put the helmet on, and announce that you are all for the safety act.
9
29
269
u/Ok_Instruction_3789 7d ago
Awesome rust is really becoming a top notch language even windows is heavily adopting it. Its speed and memory safety is hard to compete with.