Live data from Hacker News

Writing an OS in Rust: Introduction to Paging

os.phil-opp.com

61–70 of 81 posts

Re: Writing an OS in Rust: Introduction to Paging

#61

As a side note: I wish Rust would come to embedded development ASAP running a real time OS written in Rust. You can use massive Boost libraries and Qt frameworks on non-embedded systems with C/C++, but in embedded, there is no such luxury. I am new to it but it is painful and I wish to see a day where we have a complete LLVM based ARM compiler toolchain with Rust sitting on top. I think there were some blog posts abo…

Get used to the idea that embedded is 15 years behind PC. Which is initially frustrating but if you step back is kind of a good thing. I’d also like to see Rust make it’s way into embedded. C support for things like data serialization or RPC for interfacing to web stuff is limited, people just don’t port it to C. And C++ doesn’t thrill me in terms of its non-deterministic garbage handling and difficult to debug natur…

C++ has deterministic garbage collection.

Re: Writing an OS in Rust: Introduction to Paging

#63
Regardless of the platform, this is a truly excellent introduction to memory segmentation, which in my experience tends to be relevant far outside of the realm of operating system (or even single process application) development. Just the other day I was struggling to explain several concepts illustrated eloquently here to a coworker trying to design a scheduling/persistence system for variably-sized datasets that needs to be stored in hundreds of Redis instances across a compute cluster.

Re: Writing an OS in Rust: Introduction to Paging

#65
post #54
post #50

Earlier quoted context omitted.

It's been a while since I've looked into it so I hope I won't be too far off the mark: - Regarding high impedance it might be relevant if you want to explain how the controller and memory card interface works, and why you read full 1s when nothing is connected (high impedance line with a pull-up resistor). More generally the issue will crop up every time you have an interface that might be floating, I think people wh…

It's conceivable that metastability issues could be used as a part of copy protection. Well, protection against emulation more like. Of course it's not the smartest choice for that purpose, because there might be chip-to-chip differences. And environmental factors like temperature could affect it as well. But who knows what people wrote after Bleem PS1 emulator was public? So have metastability issues (or other HW bu…

There are copy protection schemes on magnetic disks that mess with the clock bits on the disk to produce an unstable value:

https://retrocomputing.stackexchange.com/a/7853

Re: Writing an OS in Rust: Introduction to Paging

#66
post #23

Off topic: can we please get support for storing arbitrary data structures inside mmapped files (with nonfixed base address)?

That's not possible to do safely for arbitrary data structures because they can contain pointers or references. If you reload to a different address then the pointers, even within the allocated chunk, would be invalid and require fixup. And if you require fixup then you might as well do (de)serialization for your data structures. Just allocating into such a memory region (essentially custom page swapping) will eventu…

Perhaps this problem can be overcome by modifying the concept of a pointer slightly, to make it a "based pointer" (?)

I found an old discussion on this topic here: https://news.ycombinator.com/item?id=13890011

Note that the Microsoft C++ compiler implements based pointers, using the __based keyword.

Re: Writing an OS in Rust: Introduction to Paging

#67
post #26

I've followed Phil's site on making an operating system. Ever since having worked on PintOS in college, operating systems and their internals have fascinated me. I've tried learning more about writing operating systems via resources like the OSdev wiki, but much of its material almost seems to discourage working on an OS of any kind unless you're already sure of what you're doing. Phil's articles seems so much more a…

I think it's one of these things that's more approachable if you start by working on specific subsystems of an existing OS. This way you don't have to figure everything out at once. At least that's how I did it. I think writing an OS from scratch is discouraging and not very accessible because... writing an OS is discouraging and not very accessible. It's a bit as if a painter was saying "It tried looking up guides o…

I think it's one of these things that's more approachable if you start by working on specific subsystems of an existing OS. This way you don't have to figure everything out at once.

The trouble is, you get yet another UNIX clone that way.

Re: Writing an OS in Rust: Introduction to Paging

#69
post #64

With memory growing arguably beyond what most application workloads really require anyways, and possibly hardware such as Intel Optane, do we still need things like VM, paging, and segmentation?

>do we still need things like VM, paging, and segmentation?

Yes. To begin with, on modern processors, paging is tied with the memory protection system. Memory is protected on a per-page basis. Memory mapped files are implemented through paging. There's also backwards compatibility. Virtual memory allows 32-bit applications to have their physical memory located anywhere. Without that, we'd have to ensure that they reside below 4GB. Programs would start up slower as the executable would have to be relocated every time. Additionally, it's hard to imagine a hypervisor that doesn't use virtual memory. Virtual memory allows hypervisors to present a unified address space to their guests; no matter how fragmented physical memory gets.

Re: Writing an OS in Rust: Introduction to Paging

#70
post #26

Earlier quoted context omitted.

I think it's one of these things that's more approachable if you start by working on specific subsystems of an existing OS. This way you don't have to figure everything out at once. At least that's how I did it. I think writing an OS from scratch is discouraging and not very accessible because... writing an OS is discouraging and not very accessible. It's a bit as if a painter was saying "It tried looking up guides o…

I fully agree, but I think it's good to have options on how to approach the issue. Generally, I've referred to OSDev when I need more real-world information on how things tend to work in practice and resources like Phil's when writing a toy operating system. I wouldn't consider Phil's blog a good resource for, e.g., gaining particular insight into how something like the Linux kernel works, but I also don't think Phil…

> I need more real-world information on how things tend to work in practice.

Have you tried reading any book?

Post reply on HN