larsth
Posts: 50
Joined: Sat Aug 27, 2011 9:51 pm
Contact: Website

So when is Raspbian going to get a 64-bit kernel?

Wed Jun 26, 2019 12:40 am

Introduction

First 2 posts from the Raspberry Pi 4 on sale now from $35 blog post

Rob Stoddard says: 24th Jun 2019 at 7:18 am
Is that software 64 bit? All that you wrote about the software I honestly don’t care about, all I want to know is, is that software 64 bit?
Link: https://www.raspberrypi.org/blog/raspbe ... nt-1509934

Answer,
David Ferguson says: 24th Jun 2019 at 7:28 am
No for mainly the same reason as before: the OS standard Raspbian image needs to be backwards compatible with the older Pi versions, and therefore isn’t 64 bit.
Kexec_file_load(2), or kexec_load(2) and reboot(2)
So no 64-bit kernel, because of backwards compability with older Pi models, but ...

... there are the kexec_load and reboot system calls.

reboot(2) does what your think it does, but you probably don't know what the kexec_file_load(2), and the kexec_load(2) system calls does:

Here is their man page
kexec_load, kexec_file_load - load a new kernel for later execution

Security
kexec_file_load, and kexec_load are potential security risks, so I would propose to use an initial 32-bit kernel, which is stripped down to have only what it needs to have - meaning that it don't support network, and the only supported filesystems could be initramfs, and FAT32 for the boot partition.

Boot process with the kexec_file_load, and reboot syscalls
  1. The Pi boots like it usually do, but the kernel is an initial 32-bit kernel
  2. The root filesystem for the initial kernel is a initramfs filesystem image that are loaded from a file on the boot (FAT32) partition
  3. The initial kernel starts the init (PID 1) process from the initramfs filesystem.
  4. A program (process) needs to detect whether or not the microprocessor is a 64-bit CPU.
  5. Another tool figures out which kernel images are available on the boot partition. It can also read configuration files too, fx one which file name (not its content) means that the initial 32-bit kernel will always boot into a 32-bit kernel, Fx the name could be BOOT-32-BIT_KERNEL - you probably has a better name. The content of such a file could be the kernel image one would like to use.
  6. A process calls kexec(8), which is a CLI tool that can directly boot into a new kernel
  7. If kexec successfully booted into the loaded kernel : That 32-bit or 64-bit kernel will then start as if was started like the way it is done today.
so why 64-bit?

Virtual memory!

Introduction to virtual memory

Important!
Programs run in virtual memory - not directly on physical memory.


Virtual memory is made up of
  • Physical RAM
  • Named swap (mmap'ed files), which has a higher priority than anonymous swap.
    The Python interpreter mmap's *.py source code files
  • zram - compressed swap in physical RAM
    Don't use zram if you use zswap
  • zswap, which is like zram, but backed by a swap partition
    If you use, let us say 1 GB of physical RAM for (z)swap, you will get approx about 2,2 times more swap, i.e., ~2,2 GB super fast swap instead of just 1 GB of swap.
    Extra bonus: If your Pi don't use the amount of physical RAM reserved for zswap , then the physical RAM is used for something else, fx a disk buffer.
    Don't use zswap if you use zram
  • Anonymouns swap, which is:
    • swap files, and ...
    • swap partittions
Virtual memory is useful for running software that are using more memory than the amount of physical memory.

Example of using a lot of virtual memory
The Chrome browser is know for notoriously using a lot of virtual memory.

If we let a Raspberry Pi 4B make use of a 64-bit kernel, that kernel can have, let's say 4 GB physical memory, and a 12 GB swap partition on a SSD disk.

The amount of available useful virtual memory is then 16 GB!

The Chrome browser can then use 8 GB of virtual memory. Most of it is paged out to zram, zswap, swap file(s), or swap partition(s).

If you want to watch a tab that has been completely paged out (isn't in physucal RAM). Let's say that tab (webpage) uses 25 GB of virtual memeory, then teh folllowing will happen:
25 MB pages are maybe, hint vm.swappiness, paged out, then the 25 MB of pages are swapped in into physical memory.

With a SSD reading at 500 MB/s - and connected to a Raspberry Pi via USB 3.0 - the 25 MB paged out, followed by a 25 MB paged in - it takes 0.1 second, which is acceptable.

Userland
If userland programs are both in 32-bit and 64-bit the downloaded image would be about twice the zsize of the current one, so a capability to run 32-bit software would be a good idea.

/Lars

User avatar
HawaiianPi
Posts: 4463
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: So when is Raspbian going to get a 64-bit kernel?

Wed Jun 26, 2019 1:18 am

larsth wrote:
Wed Jun 26, 2019 12:40 am
...
With a SSD reading at 500 MB/s - and connected to a Raspberry Pi via USB 3.0 - the 25 MB paged out, followed by a 25 MB paged in - it takes 0.1 second, which is acceptable.
That might be acceptable, if it were true...

https://www.raspberrypi.org/blog/raspberry-pi-4-on-sale-now-from-35/ wrote: USB is provided via an external VLI controller, connected over a single PCI Express Gen 2 lane, and providing a total of 4Gbps of bandwidth, shared between the four ports.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
thagrol
Posts: 1711
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: So when is Raspbian going to get a 64-bit kernel?

Wed Jun 26, 2019 12:54 pm

larsth wrote:
Wed Jun 26, 2019 12:40 am
so why 64-bit?

Virtual memory!
Nope. 64bit is not needed for virtual memory. It might let you have a bigger address space but that's all.

And trust me, swap will always be an order of magnitude slower than RAM.

Your proposal in this area reminds me of this joke from the 90s when virtual memory was hitting servers and early windows:

Great! Virtual memory. Now I can have a really big RAM disc.
This space unintentionally left blank.

User avatar
rpdom
Posts: 14765
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: So when is Raspbian going to get a 64-bit kernel?

Wed Jun 26, 2019 1:05 pm

thagrol wrote:
Wed Jun 26, 2019 12:54 pm
And trust me, swap will always be an order of magnitude slower than RAM.

Your proposal in this area reminds me of this joke from the 90s when virtual memory was hitting servers and early windows:

Great! Virtual memory. Now I can have a really big RAM disc.
I do remember quite a lot of people asking if their PC would run faster if they put the swap on a RAM disk.

I did put the swap from our office PC on a network share once. It made the system a lot faster, even over 10Base2 coax.

fanoush
Posts: 460
Joined: Mon Feb 27, 2012 2:37 pm

Re: So when is Raspbian going to get a 64-bit kernel?

Wed Jun 26, 2019 1:14 pm

When you can have 64bit kernel with raspbian? You already missed it.

https://www.raspberrypi.org/forums/view ... 9&t=232684
https://www.raspberrypi.org/forums/view ... 3&t=232417
https://github.com/sakaki-/raspbian-nspawn-64

It is 64bit kernel (as you wanted) and 32bit raspbian as main os and 64bit debian in container for stuff that really needs 64 bits.

larsth
Posts: 50
Joined: Sat Aug 27, 2011 9:51 pm
Contact: Website

Re: So when is Raspbian going to get a 64-bit kernel?

Wed Jun 26, 2019 3:11 pm

fanoush wrote:
Wed Jun 26, 2019 1:14 pm
When you can have 64bit kernel with raspbian? You already missed it.

https://www.raspberrypi.org/forums/view ... 9&t=232684
https://www.raspberrypi.org/forums/view ... 3&t=232417
https://github.com/sakaki-/raspbian-nspawn-64

It is 64bit kernel (as you wanted) and 32bit raspbian as main os and 64bit debian in container for stuff that really needs 64 bits.
Thanks!

/Lars

Return to “Raspbian”