top | item 17592560

Xv6, a simple Unix-like teaching operating system

354 points| rspivak | 7 years ago |pdos.csail.mit.edu

79 comments

order
[+] ArtWomb|7 years ago|reply
A great (and free) companion textbook to any introductory OS class is Three Easy Pieces:

http://pages.cs.wisc.edu/~remzi/OSTEP/

[+] goodells|7 years ago|reply
This book rocks! I took the OS class with Remzi’s wife my junior year and it was the one that made everything “click”, bridging the gap between the computer engineering/circuits and higher-level C code we otherwise did. OSTEP and Xv6 were really integral for understanding things inside and out because we had to implement what we learned about in class.
[+] tdjones879|7 years ago|reply
This is a really great book for anyone interested. My professor used this in place of the more traditional book by Tanenbaum. It's easy to read and provides good citations if you want to read more in-depth about a specific chapter.
[+] sitzkrieg|7 years ago|reply
While its available completely free online, I highly recommend anyone who plans on using the book in detail to purchase a printed copy on lulu, its pretty cheap and looks really nice
[+] enitihas|7 years ago|reply
+1 for 3 easy pieces. To me it felt the most natural book on operating systems.
[+] exist|7 years ago|reply
Such a great book! As someone who came from a non-traditional background, this book was very key in helping me understand operating systems.
[+] rdh|7 years ago|reply
It's incredibly helpful to learn by example, in my opinion. My university course taught using Xv6 as well, and the exams often included a problem where you were asked to modify a portion of the code to change behavior in a particular way (we were also asked to have the entire code printed out for reference during the exam). Probably one of my favorite courses.
[+] ape4|7 years ago|reply
Yikes, what a waste of paper. Hopefully you could borrow it from the library or buy a used copy at the bookstore.
[+] dwheeler|7 years ago|reply
MINIX was also created for teaching. Is there a comparison of Xv6 vs. MINIX pros and cons for teaching?
[+] burfog|7 years ago|reply
Aside from being small, Xv6 is a normal OS. MINIX was designed to chase the gravely ill-advised microkernel fad that took over academia. You can lump Xv6 in with Linux and BSD, while lumping MINIX in with GNU HURD. The trouble is that glue isn't free: breaking an OS down into simple parts doesn't make the OS simple; the resulting interactions between simple parts become complex.

Xv6 is also written in a more modern coding style, using stuff like C99 initializers. It runs on modern hardware, even supporting SMP.

[+] sobraton|7 years ago|reply
MINIX is much, much closer to being a fully working OS. Hell, you can run X11 on it, it can recompile itself, it has a package manager.

xv6, on the other hand, is just bare kernel with no functional purpose.

[+] MisterTea|7 years ago|reply
Minix is microkernel based while Xv6 appears to be monolithic.
[+] pieterr|7 years ago|reply
One of the people, Frans Kaashoek, has been involved in Minix as well, an OS from the 80s, also created for educational purposes at the time.

[1] https://en.wikipedia.org/wiki/MINIX

[+] Cursuviam|7 years ago|reply
And another of the people, Robert Morris, helped found ycombinator
[+] TheAnig|7 years ago|reply
Can't wait for Intel to put this onto every one of their processors!
[+] pinewurst|7 years ago|reply
Intel’s already put Minix on every one of their modern processors as the embedded ME OS.
[+] joebergeron|7 years ago|reply
Ah, I have fond memories of staring at pages of Xv6 code. I took the OS class, 6.828, which uses Xv6 as a reference, while an undergrad at MIT. While relatively simple compared to most anything else you could think up, it gave great insight and intuition into code style and idiomatic OS patterns for working on JOS, the more substantial OS you end up writing in that class.
[+] userbinator|7 years ago|reply
IMHO the source code is an example of good C style, and certainly quite pleasant to read --- no excessive verbosity, gratuitous indirections, PretentiouslyCapitalisedObscenelyLongIdentifiers, unnecessarily huge indents, or any of the other annoyances I tend to find with more "modern" source code. With the exception of a few minor stylistic choices I would've done differently, it's extremely close to my preferred source style.

Unfortunate that it isn't quite completely C89 (in particular regarding placement of variable declarations), since C89 compilers are much simpler than C99 ones and otherwise a compiler course could've been created around writing a compiler (and assembler) that can compile itself, Xv6, and then itself run inside Xv6 --- to become a self-contained, self-bootstrapping OS.

[+] wolfgke|7 years ago|reply
What a pity that lots of people seem to want to create (often small) enhancements to xv6

> https://github.com/mit-pdos/xv6-public/pulls

but the authors (probably because of lack of time and/or academic obligations) seem to ignore them.

[+] beefhash|7 years ago|reply
I mean, it's basically licensed under MIT. If somebody really wants to do something with the OS, they can just go and fork it, then get everybody else to hack on that instead. Given upstream is dead, it shouldn't be too hard to gain traction.

Some "basic" (actually very involved, but the modern-day PC is hell) requirement to get it to run on physical hardware past 2020[1] is UEFI support. USB keyboard support is probably also a hard requirement nowadays and would basically require a full USB stack.

[1] https://arstechnica.com/gadgets/2017/11/intel-to-kill-off-th...

[+] justin66|7 years ago|reply
Rather than incorporate them into the software, small enhancements are the sort of thing the authors of the project would prefer to leave as exercises for students, I'm sure.
[+] sigjuice|7 years ago|reply
If you read through the comments of the closed pull requests you will get some idea of the type of enhancements that the maintainers expect.
[+] qntty|7 years ago|reply
Any tips for understanding the lowest level code like the bootloader? It seems to be pretty opaque to me.
[+] teraflop|7 years ago|reply
At a glance, the code seems reasonably well commented, but it definitely assumes some prior familiarity with x86 hardware. Do you have any specific questions?

If not, the OSDev.org wiki is a pretty good starting point: https://wiki.osdev.org/Expanded_Main_Page

[+] dev510213|7 years ago|reply
Can someone briefly explain how does one go about using this (for self learning)?
[+] rijoja|7 years ago|reply
Any place where you could get a disk images to try to spin this up in a VM?
[+] monocasa|7 years ago|reply
You can just run make. It doesn't need a cross compiler or anything weird on x86.
[+] bitcoinmoney|7 years ago|reply
is there are resource like this but for computer networking?
[+] shawn|7 years ago|reply
Does anyone know how to extend xv6 with copy-on-write? I was implementing a multiprocessing lib based on xv6 but noticed a fork copied the entire parent page table.

I think it’s a matter of extending the page fault routine to check whether the missing page is flagged copy on write, but I wasn’t sure how to correctly track which source page it should be copied from. Every process has its own clone of the page table hierarchy, so how do you know which one to grab during the fault?

[+] mav3rick|7 years ago|reply
When you fork, your forked process get a copy of the parent's page table i.e. at this point it points to the same physical page for xyz address as the parent. There can be a metadata bit in the final PTE that says this page is COW (Copy on Write). For context, in a 32-bit system 2 Level page table with 4KB pages means only 20 bits are used in the final page table to get the page frame. There are 12 bits free for some metadata.

Your forked process already has the physical page frame number and the COW bit. If it's a write/modify on that page and the COW is set, your code should allocate a new physical page, copy the raw contents of the currently mapped physical page and then finally update the page table entry with this new physical page frame number. If you want an example with some numbers, I can reply further. Let me know :)

[+] deusofnull|7 years ago|reply
Cool, is this Unix like teaching operating system going to be clandestinely installed on all future Intel CPUs like Minix was?
[+] tonysdg|7 years ago|reply
Made me laugh (thanks for that!), but in fairness, MINIX 3 was designed for actual usage and not just education. From Wikipedia [1]:

> Although it still serves as an example for the new edition of Tanenbaum and Woodhull's textbook, it is comprehensively redesigned to be "usable as a serious system on resource-limited and embedded computers and for applications requiring high reliability."

[1]: https://en.wikipedia.org/wiki/MINIX_3#History

[+] fernly|7 years ago|reply
Looking at the github repo [1] I am immediately underwhelmed by the commit messages. "nothing much," "nits," "nit". Really?

[1] https://github.com/mit-pdos/xv6-public

[+] sigjuice|7 years ago|reply
Have you seen the diffs for those commits? What else do you suggest should go in the messages for such commits?