Ask HN: Recommended resources to learn the Linux kernel and OS theory?
408 points| non-entity | 6 years ago
Unfortunately I'm still completely lost. It seems that there's so much to learn and every kernel update breaks whatever you just finished writing. I see terms in unfamiliar with and often find myself googling basic OS concepts.
Are there any recommendations reading materials to get a better grasp on OS theory and / or the Linux / UNIX kernels and programming for them?
[+] [-] waddlesplash|6 years ago|reply
Depending on your style of programming, I'd recommend maybe not working on Linux if you are trying to learn kernel development and OS internals.
Have you looked at Haiku (https://www.haiku-os.org/)? We have a very well organized and commented modular-monolitic kernel, and a pretty active development team with a wide range of experience levels. I'm more than happy to help you (or anyone else) learn OS development!
Some example Haiku kernel code:
* "load_image_internal()", which is responsible for creating processes: https://github.com/haiku/haiku/blob/master/src/system/kernel...
* a recent change by me to replace a global lock with two local ones: https://github.com/haiku/haiku/commit/37eda488be1c9fee242e8e...
[+] [-] xz0r|6 years ago|reply
Could you also tell why ?
[+] [-] non-entity|6 years ago|reply
[+] [-] no-dr-onboard|6 years ago|reply
This sounds like a bit of an oxymoron. What is a modular-monolithic kernel?
[+] [-] okl|6 years ago|reply
[+] [-] hatsubai|6 years ago|reply
It provides extremely detailed information about everything going on in Linux, as well as example programs and exercises to help you further your knowledge. While it doesn't get deep into kernel theory like Tanenbaum's books tend to do, it will provide you with a greater understanding of how things work, IMO.
[+] [-] whowhatwhy|6 years ago|reply
[+] [-] sruffell|6 years ago|reply
"Linux Programming Interface" is one of the best technical books I've ever read.
[+] [-] aidos|6 years ago|reply
[+] [-] tbrock|6 years ago|reply
[+] [-] koolba|6 years ago|reply
[+] [-] filereaper|6 years ago|reply
I'd recommend starting with an academic operating system to nail the fundamentals down, once you have a solid foundation you can then use all the excellent links provided by everyone else and ramp up on production grade kernels.
I have linked to multiple course syllabus'es below from excellent institutes, pick whichever feels most comfortable.
Harvard with MIPS based OS/161 (I learned this personally): http://www.eecs.harvard.edu/~cs161/syllabus.html
Berkeley EECS 162 (John Kubiatowicz is amazing and is behind RISC V) https://inst.eecs.berkeley.edu/~cs162/sp19/
MIT OCW: https://ocw.mit.edu/courses/electrical-engineering-and-compu...
[+] [-] pm215|6 years ago|reply
[+] [-] jiveturkey|6 years ago|reply
Highly recommended.
[+] [-] alfiedotwtf|6 years ago|reply
There's a Xinu book which is similar, but without the accompanying source code.
[+] [-] geofft|6 years ago|reply
The basic trick of dealing with the kernel is becoming comfortable working in a large codebase most of which you don't understand, and figuring out how to find what you need. Honestly, git grep is one of the best tools here. Get some practice finding some specific thing and where it's implemented, e.g., find a syscall (git grep SYSCALL.*foo) and trace what it calls. Find the definition of a structure inside include/ and see who uses it. Get comfortable with the kernel's OO-ish system of operations structs, and get some practice tracing both "this function makes a generic call, here's a sample driver that implements it" and "this is an implementation of a generic function, here's the syscall that calls it."
Beyond that, reading https://lwn.net 's articles is invaluable, partly for the clear prose coverage and partly for the breadth of what they talk about. (You don't need to pay unless you care strongly about this week's updates - you'll learn plenty from reading articles a week behind - but support them if you can, they're an important resource.) Again, you're not going to follow exactly why e.g. Google wants a new syscall for "restartable sequences" on your first read, but you'll get a sense of what is involved in adding a syscall, how various concurrency models work, what other kernel features are relevant, etc.
What sort of OS concepts are you finding yourself Googling? I will say that actually doing a college OS class is what made things like virtual memory management click in my head. It's an intensive approach but writing code in a much smaller kernel than Linux is a valuable way to understand concepts without being drowned in real-world optimizations and edge cases and portability.
[+] [-] livueta|6 years ago|reply
That's a very good point. If we're recommending tools, cscope (especially if you're a vim/emacs user) or opengrok (if you're not or prefer a web frontend for other reasons) are super helpful for navigating and comprehending large, mysterious codebases.
DTrace/eBPF are also valuable tools for grokking kernel functionality.
[+] [-] non-entity|6 years ago|reply
[+] [-] whydoyoucare|6 years ago|reply
http://pages.cs.wisc.edu/~remzi/OSTEP/
(Online version above, you can also order a print copy).
[+] [-] 0x262d|6 years ago|reply
[+] [-] snoocat|6 years ago|reply
[+] [-] thinkmassive|6 years ago|reply
[+] [-] lorenzfx|6 years ago|reply
[+] [-] mjb|6 years ago|reply
[+] [-] non-entity|6 years ago|reply
[+] [-] qntty|6 years ago|reply
[+] [-] weinzierl|6 years ago|reply
[+] [-] Noe2097|6 years ago|reply
[+] [-] jascii|6 years ago|reply
[+] [-] slipwalker|6 years ago|reply
[+] [-] molteanu|6 years ago|reply
XinuOS [2]
MIT's xv6 OS [3]
[1] http://pages.cs.wisc.edu/~remzi/OSTEP/
[2] https://xinu.cs.purdue.edu/
[3] https://github.com/mit-pdos/xv6-public
[+] [-] apengwin|6 years ago|reply
https://pdos.csail.mit.edu/6.828/2014/xv6/book-rev8.pdf
[+] [-] bytematic|6 years ago|reply
[+] [-] apacheCamel|6 years ago|reply
[+] [-] yodsanklai|6 years ago|reply
https://pdos.csail.mit.edu/6.828/2014/overview.html
I completed this one, but they may have more recent versions. They give you some initial code that you need to complete, as well as tests to check your work before going to the next step. It covers a lot of material. It takes some patience and it's not for complete beginners but it's a great fun project. Not sure, but I'd say it took me 1 or 2 weeks full time.
[+] [-] peterkelly|6 years ago|reply
Here's something I put together some years ago - it's about 5,000 lines of code and supports a number of key Unix features. There's a PDF of lecture notes accompanying it.
http://adelaideos.sourceforge.net/
Once you've gone through this you'll be in a better position to tackle the Linux kernel and books on OS architecture. My personal favorite is "The Design of the UNIX Operating System" by Maurice J. Bach. It's an old book but explains things well, and I believe it was one of the references Linux Torvalds relied on when creating Linux.
[+] [-] gamescodedogs|6 years ago|reply
[+] [-] lignux|6 years ago|reply
[+] [-] yourbandsucks|6 years ago|reply
[+] [-] DanAtC|6 years ago|reply
[+] [-] kernyan|6 years ago|reply
Matyukevich page on GitHub has lessons with accompanying code to develop a Linux OS for raspberry Pi. The author goes into kernel, processor initialization, interrupt handling, scheduler, implementing syscall, and virtual memory.
I like his approach for these reasons 1. Minimal workable code, 2. Points you to entry function in linux repo 3. Line commentary of those entry function
Note that it's also a somewhat short read as he focuses on the practical implementations instead of the theory.
I myself was hoping that the author continue developing the chapters on file system, drivers, and networking but seemed to have been on hiatus.
[+] [-] throwawaypls|6 years ago|reply
[+] [-] rubyn00bie|6 years ago|reply
Also, Redox OS is an OS written in Rust and has a ton of wonderful documentation on it that's been helping me get into systems development: https://www.redox-os.org/docs/
[+] [-] alfiedotwtf|6 years ago|reply
As for OS theory, "Operating Systems Vade Macum" and "Operating Systems Design and Implementation" are my favorites.