r/linux • • 7d ago

Kernel 17k lines of new Rust kernel code heading into Linux 7.4

https://www.phoronix.com/news/Linux-7.4-Rust
865 Upvotes

79 comments sorted by

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.

68

u/MBgaming_ 7d ago

How did they even do this, are there any drawbacks in other areas cause of the better performance. Not a programmer so I got no idea

→ More replies (27)
→ More replies (4)

34

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

21

u/CissMN 6d ago edited 3d ago

As someone estimated in the phoronix forum rust now takes up 0.57% of the codebase.

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 …"

9

u/daennie 6d ago

Time for linux-rs, I guess.

1

u/dronmore 6d ago

Fasten your seatbelt, put the helmet on, and announce that you are all for the safety act.

9

u/MagicalVagina 5d ago

17k lines is not that much. Especially in rust. Not sure why it matters.