Live data from Hacker News

How could the early Unix OS comprise so few lines of code?

retrocomputing.stackexchange.com

151–160 of 170 posts

Re: How could the early Unix OS comprise so few lines of code?

#151
post #102
post #97

Earlier quoted context omitted.

Toy solutions deal with small data inputs. How many lines of that 20k is just optimizing for large inputs (you can’t have long repeating sections in small inputs).

I've written a linear-time regex matcher in 65 lines of code: https://jasonhpriestley.com/regex

I think this is a good base case for exploring how achieving feature parity affects the code.

Re: How could the early Unix OS comprise so few lines of code?

#152
post #64

I feel that most 100K line programs could be rewritten with just 10K lines and end up being more reliable. Feature creep is responsible for some of the code bloat but I can guarantee from experience that, in the vast majority of projects, you could keep all the features and still cut the code to at least 1/10th of its size. I think the reason for this is because developers who focus on development speed do so at the…

First, I think we should use expression count instead of pure LOC because many styles add white space but keep the expression the same. I don’t consider one style “more terse” than another. e.g. a.map(…).reduce(…).join(…) a.map(…) .reduce(…) .join(…) If you can accept that expressions are a better metric for “terseness” then I will categorically say your statement is pretty easy to disprove. Essentially you’re saying…

Code generation is also pretty prevalent, some languages/ecosystems more than others

Re: How could the early Unix OS comprise so few lines of code?

#153
Early Unix switched contexts by writing the current process out to disk, loading the next runnable process, then jumping to it. Besides that overhead being far too slow in modern terms it also did not admit threads nor multiple concurrent cores. There was no need to consider atomic operations or even locks to a large degree.

Most people wouldn't appreciate minimalism if they had to use such software on a daily basis.

Re: How could the early Unix OS comprise so few lines of code?

#155

It was essentially a "time-sharing" system that multiplexes interactive sessions of multiple users on teletype terminals. The "shell" handles such a session by waiting for user input on the terminal, interpreting it and starting external programs as a sub-hierarchy of user processes. On a teletype terminal, you couldn't even have a cursor-oriented editor like vi, but had to rely on line-oriented editors like ed and s…

In a way it became the complete opposite of how it started. At first one OS for many users, ea with many processes. Now, with containers, micro services etc. we have an OS per service/process. Still the original abstractions work surprisingly well though makes it me wonder how a complete redesign of would look like aimed at modern usage.

Calling an independent set of libraries in an isolated space an entire OS is a bit of a stretch. Containers generally don't contain an init system and a bunch of services (sure, they technically can and some do), but there's generally much less running than an entire OS.

Re: How could the early Unix OS comprise so few lines of code?

#156

Earlier quoted context omitted.

In a way it became the complete opposite of how it started. At first one OS for many users, ea with many processes. Now, with containers, micro services etc. we have an OS per service/process. Still the original abstractions work surprisingly well though makes it me wonder how a complete redesign of would look like aimed at modern usage.

But the question is why did we arrive at containers and one OS per "microservice"? Has memory-to-IO bandwidth, scalability requirements, or whatever really changed (like in orders of magnitude) to warrant always-async programming models, even though these measurably destroy process isolation and worsen developer efficiency? After almost 50 years of progress? Or is it the case that containers are more convenient for c…

>But the question is why did we arrive at containers and one OS per "microservice"?

I think it makes more sense if you consider the interim transition to other isolation mechanisms like commodity servers instead of mainframes, VMs, then containers as a way to get more isolation/security than traditional multi user model with less overhead than an entire machine.

Obviously cloud providers want to push for solutions that offer higher densities but those same cost/efficiency incentives exist outside cloud providers.

I'd say we've more accurately been trying to reinvent proprietary mainframes on commodity hardware.

Re: How could the early Unix OS comprise so few lines of code?

#157
post #61

Any way to reasonably estimate how long it would take to compile back then? The PDP-11 was 1.25 MHz, Would it be roughly 4000x slower than compiling a 13K-line C program on a modern CPU? Or are computer architectures so much different that CPU speed isn't the primary factor?

People did not compile the kernel back then. The kernel was supplied in a precompiled form as a collection of object (.o) files, and there was a kernel «generation» shell script that would ask questions about which parts of the kernel were required (e.g. which device drivers to link in), what to set certain kernel parameters to (e.g. the number and the size of I/O buffers for the page cache had not been invented yet and neither had been «sysctl»), and – after jumping through the hooves of the very detailed and thorough interview with the kernel generation script – it would link the /unix kernel a.out image. It took several hours to get the final product.

The source code was distributed on a tape but it was not customary to compile the kernel from scratch every time.

Re: How could the early Unix OS comprise so few lines of code?

#158
post #59
post #7

Earlier quoted context omitted.

They also didn't care nearly as much about performance. Or to be more precise, they had very different trade-offs to make. Back then, you could have a system call and context switch for every read and live with the overhead. Today we have something like io_uring.

I'd guess that back then system call overhead was lower than with modern CPUs with deep pipelines, speculation and their vulnerability workarounds.

It wasn't lower. But people put up with it.

Because they had to; there just wasn't a viable alternative

Re: How could the early Unix OS comprise so few lines of code?

#159
post #90
post #25

Earlier quoted context omitted.

> the PDP-11 disk unit throwing itself around violently when somebody started nroff. That was the overlays… the early days substitute for the virtual memory proper. If I remember correctly, the first PDP-11 to have the true virtual memory and a MMU was PDP-11/70 which had 18-bit wide hardware addresses.

The 11/70 had a 22-bit wide memory bus and an 18-bit wide unibus which was mapped to the high 256kb of the 4M physical address space.

You are correct. I have long forgotten about the mapped memory and was thinking about Unibus device registers having long 18-bit addresses. The 11/70 also had separate instruction and data spaces which did not exist in earlier models.

Re: How could the early Unix OS comprise so few lines of code?

#160
post #51

Unlike previous OSes, UNIX provided the pipe facility to allow you to combine the functionality of many small programs. Ex. ls | grep ... | sort ... | more Before that every command-line program had to support the full suite of additional functionality like search, filtering, paging, etc. This UNIX/Pipe approach allowed for greater reuse and much less code. This is explained and simulated in this video: https://www.y…

Thank you for sharing that video! Your foam project looks fascinating too: https://github.com/kgrgreer/foam3
Post reply on HN