Live data from Hacker News

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

retrocomputing.stackexchange.com

41–50 of 170 posts

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

#41
post #33
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.

Back then, fitting in RAM was a big problem: The PDP-11 (the first kind of computer to run Unix, as opposed to UNICS) had a 16-bit address space, which gives you 64 K of RAM if you ignore the fact peripherals were memory-mapped and so took addresses away from actual memory. Later models had split I+D, or separate address spaces for Instructions and Data, but that's still only 128 K. https://gunkies.org/wiki/PDP-11_Me…

Later models could address 18 (256k) or 22 bits (4Mbytes) of memory.

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

#42
From one answer:

> Linux, before all these features and bloat were added, as originally released as a crude kernel for 386 machines

Developers surely like to say anything they don't care about is "bloat", don't they? This "bloat" is what makes Linux usable everywhere.

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

#43

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…

> Before I start working on a feature, I simulate how it's going to work in my head and try to identify all the hurdles and alternatives; sometimes several levels down in the hypothetical component/module hierarchy. I do brainstorms, draw diagrams and make lists of pros-and-cons. I use as many visual aids as I can get. Remarkably, this is how 37Signal's Shape Up ( https://basecamp.com/shapeup ) encourages defining fe…

[flagged]

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

#44
post #9
post #2

Answer: smaller target to cover! Modern Linux has most code in device drivers to support so many different devices. Then, it supports many targets for other subsystems, like file systems. The original Unix provided one implementation for each subsystem. They relentlessly simplified the problem they were solving to make it doable.

Latest Linux kernel source: 39,000 certs 0.0% 40,000 usr 0.0% 164,000 init 0.0% 240,000 virt 0.0% 250,000 ipc 0.0% 459,000 io_uring 0.0% 664,000 rust 0.1% 980,000 samples 0.1% 1,885,000 block 0.1% 2,850,000 scripts 0.2% 2,953,000 security 0.2% 3,609,000 crypto 0.3% 5,165,000 mm 0.4% 7,156,000 lib 0.5% 12,420,000 kernel 1.0% 33,047,000 net 2.5% 39,916,000 include 3.1% 43,224,000 fs 3.3% 45,001,000 sound 3.4% 54,988,00…

arch seems pretty essential and it's still at 107m. hardware is complex, no way around it.

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

#45
post #13

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.

Most of the time the OS is just overhead now. Look at unikernels for one possible future.

I'm not sure I think the exokernel/unikernel approach by itself is the path forward. While the library operating system approach makes a lot of sense for applications where raw throughput/performance are crucial, they don't offer as much in the way of development luxuries, stability, or security as most modern operating systems. Furthermore, outside of very specific applications the bare metal kind of performance that the exokernel approach promises isn't really that useful. That said, I suspect a hybrid approach may be viable where two extremes are offered, an extremely well isolated and secure microkernel which offers all of the luxuries of a modern operating system built on top of an exokernel which can also be accessed directly through the library operating system approach for specific performance critical applications (say, network and disk operations for a server.)

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

#46
It's unsurprising when you consider that there are often several magnitudes of difference in code between what code grows to when you have the capacity and time and compounding user requests, and what a meaningful starting point that provides useful functionality above and beyond what you had without it looks like.

As an extreme example here[1] is an article by Brian Kernighan about a basic regexp matcher by Rob Pike. The code, with comments, is 35 lines of C.

Meanwhile, the regexp engine in Ruby 3.2.2, not even including the Regexp class visible to the language, is ~20597 lines excluding the headers.

They are not reasonably comparable, of course. Pike's code provides a very basic syntax which doesn't even support character classes, and does nothing to speed up the matching. The latter supports a very much more complex syntax, and is far faster for repeated or long matches.

But while Ruby's regexp engine is 588 times large than Pike's code, you of course get a vastly higher boost in overall system capability from those first 35 lines of code (from no regexp matching to some regexp matching) than the last 35 lines of code, or indeed the second 35 lines.

So if you have a small system and a small team, you work with that and start small and it won't be that surprising when you get a lot done in few lines of code, even though you have a long list of things you'll add when you can justify the extra resources (like those missing language classes, and a billion other features)

(Then you get a larger system, and you'll very soon find yourself wondering how you could manage with so little)

I think it's mostly surprising because most developers today aren't used to thinking about capacity constraints of small systems, and so starts designing for lots of features from the start (can't have regexps without character classes, and capture groups, and back-references, and ...).

[1] https://www.cs.princeton.edu/courses/archive/spr09/cos333/be...

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

#47
post #27

Earlier quoted context omitted.

Ls -l tells you whether it's a directory. (-l flag available in the first edition) If you want colours you can pipe it through a sed script. If you want to sort it in some way you could pipe it to sort or something. No system is ever going to do everything everyone wants. The Unix solution is to allow you to easily add the things you do want.

> The Unix solution is to allow you to easily add the things you do want. And yet here we are, with ls having builtin support for color, sorting and more.

Yes, very annoying.

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

#48
There was no complex stuff like SMP, no netfilter or similar. Software in and before the 90s was written with extreme naivety; buffers would be blindly allocated / assumed based on user (even network) supplied input. This makes code much simpler, even with bloated designs like UNIX. If you think about it, UNIX actually can't even be defined, you just have a way to execute programs, some process management (in this case which is overly defined for no reason, with superfluous concepts like process groups), the UNIX file system with a permission model that only needs a hundred lines of code, and output (and input) just goes to a terminal that interprets it however it wants. It has no say on anything so that's why you have 13 different programming languages that all do the same thing, dumping files all over the place trying not to stomp on each other, a shell language which itself is so poorly defined that people aren't even sure if comparing something to empty string is portable, no standard way to pass around data (just strings, whose encoding changes every 5 years), even the encoding of file names.

On the other hand, UNIX is bloated with garbage like `wall`, the ability to output text into another user's terminal, metadata all over the place with no discipline, like ps being able to see other users' command line including if they typed a password in it (security is a bonus but beside the point: you shouldn't expose data through an API that isn't explicitly needed for the purpose the API purports to serve). Stuff like hostnames, DNS, email, are built into the kernel in various ways. This could answer why it needs a whopping 13KLOC.

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

#49
post #2

Answer: smaller target to cover! Modern Linux has most code in device drivers to support so many different devices. Then, it supports many targets for other subsystems, like file systems. The original Unix provided one implementation for each subsystem. They relentlessly simplified the problem they were solving to make it doable.

They also did't care that much about * unit testing * framework boiler plate * testing pragmas * mockups

Unit testing doesn't account for many lines in the Linux kernel. I see 33 test suites.

    $ find include/kunit/ -type f | xargs wc -l --total=only
    2418
    $ git grep -lE '^kunit_test_suites\(' | xargs wc -l --total=only
    17838

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

#50
post #16

Earlier quoted context omitted.

With virtual memory and demand paging, memory management (done efficiently) becomes a much harder problem, too.

Unix V7 had virtual memory, at least, I can remember the PDP-11 disk unit throwing itself around violently when somebody started nroff.

Although the 11/70 had primitive mmu support, V7 ran on the /45 and /55 and did not use anything besides I/D separation.
Post reply on HN