Skip to content

u/rastermon

In this archive from Apr 2012 to Aug 2023

0
posts
136
comments
0
media
382
score

Top comments

Just to avoid giving people the wrong idea:

Since Linux keeps running programs in memory

Is wrong. I know it's a simplification here but it leads to all sorts of incorrect ideas about how Linux works. People will think Linux goes and loads every program (and it's needed libraries) into memory entirely then no longer looks at disk. This is false. It always looks at the disk for these binaries and will be loading bits of them and the libraries on demand as needed and will actually throw out unused segments of those binaries after enough memory pressure on disk cache and may have to re-load them back in later. They are mmaped (memory mapped) directly from disk so if that binary were to change then the contents of memory will change with it as a segment memory now is an exact mirror of what is on disk in that file. Making a change to that file while mapped can easily cause binaries to crash or misbehave. If you were to replace a binary with:

cp newbinary /usr/bin/oldbinary

You most certainly will find any existing instances of that binary running will have issues from almost instantly segfaulting or otherwise misbehaving to perhaps running for a while then falling over, depending on what changed between the versions.

The reason upgrades work is they are not done via "cp". They are done by "atomic replacement". This ensures that it's either the old file OR the new file. No half written file. Nothing in between. The old file content is in fact left untouched. The "install" cmdline tool does just this. As opposed to cp it will atomically replace files. Atomic replacement means there is still an invisible copy of the old file around. Anything that did have that file open (like a binary running) will continue to reference this invisible file, thus not be affected (unless it re-opens that file by path ... then it'll find the new one, not the old).

This magic all happens because directories are just lists of names -> inode numbers, and files are just an inode number on disk. That /bin/bash file is actually just file inode 18357022 or something. It's directories that give files names and a sane way to go find them. So the directory is changed to point the same name to a new inode number for that new file. That releases the reference count from the directory to that older file, normally deleting the old file as it goes down to 0 references (note: hard links exist which place multiple directory references to the same file inode, unlike symlinks they can't be broken due to this reference counting), but if binaries hold a reference in memory to that file, that deletion is actually delayed until all those references go away (binaries exit, thus closing the file). For large enough upgrades (enough files still referenced on disk that are large enough) You can actually run out of space before you think you would because of these invisible files still taking up disk space until all references are gone.

Note that the kernel itself is different as it doesn't get loaded from the filesystem the same way everything else does by the kernel, but the above covers 99.9% of things on your system so it's good to know. :)

44 points

When I first got my Raspberry Pi3 I used Raspbian. I switched to Arch Linux after maybe 6-9 months or so on it. I was compiling my own code. It normally took about 2h to build it all on Raspbian. That went down to about 1h20 with Arch. Same code. Same Rpi3 hardware. It was simply faster.

Why? Rapsbian at least WAS supporting the Pi1 and up. The Pi1 was armv6. The pi2 and on are armv7 capable. Pi3 and 4 are armv8 capable (armv8 is 64bit. armv7,v6 are 32bit, but v7 was much improved over v6 a bit like when Pentiums rolled out in a world of 486's). Arch is compiled fully for armv7 (or well the 32bit images are - there is an armv8 64bit aarch64 image too and armv8 gets you more and wider registers etc., but I have stuck to the 32bit ones to keep memory footprint down as my Pi3 only had 1GB RAM. My Pi4 has 4GB so I have more luxury room too use the 64bit images there, but for now I'm not).

Imagine you had a Linux distribution compiled for a 486 vs. another compiled for core i3/5/7 series or newer and then go run it on your latest intel CPU. The 2nd would run much better as it'd make use of newer instructions and optimizations. It makes a real big difference. Raspbian did try use assembly optimized routines for things like memcmp via a dlopen()ed library done by glibc art runtime to load in architecture specific optimized routines, but this just optimizes that function and the few this technique implemented for. It doesn't optimize the entire software stack like compiling for a newer architecture does, and when you have everything from top to bottom with much better optimizations compiled in, then the whole thing works faster -> about 50% faster in this case.

32 points

Subreddits

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.