Jump to content

Is it worth it to compile your own Kernel for performance?

Go to solution Solved by igormp,
23 minutes ago, Gat Pelsinger said:

But I still don't know how you can get that number to 2 digits

Disabling services and other useless software.

23 minutes ago, Gat Pelsinger said:

and also not even touching the Kernel.

As I already said before, the Kernel is the least of your worries when it comes to ram usage.

24 minutes ago, Gat Pelsinger said:

Like I am pretty sure I heard somewhere like either today or 10 years ago (I don't remember), The Linux Kernel takes at least 64 MB to boot up.

Nah, you can boot the kernel itself in less than 1MB, and even have SSH and networking with ~1MB of RAM, but that's basically just the kernel and some core components, not useful for a desktop system.

26 minutes ago, Gat Pelsinger said:

Can't believe I forgot this but I did an experiment running Linux in a very tight memory environment. If I can remember, the system (not just the Kernel but also Arch) at least required a bare minimum of 200 MB without SWAP to just boot up and not panic when rebooting.

That's mostly due to other software that the system tries to start on boot, you can get a pretty minimal install if you want. As an example, here's an archbang vm install with some stuff disabled and ctwm + xterm:

image.png.731c83ff5876510235e5c02c3cfb0081.png

 

Less than 200mb, using systemd (which does take it fair share of ram), without swap. Systemd takes around 10mb of ram in total:

image.png.74fdb3b8ad89f8ab6c52342a0f06b5de.png

 

And here's top sorted by memory:

image.png.eab6d3df9bbbeee98ca99288f1b68727.png

 

If you were to forgo systemd and some other quality of life stuff you can easily go below 100MB usage. Xorg alone takes almost 20MB lol

You can also disable some unused kernel modules (without actually rebuilding the kernel) to shave some extra ram.

 

If you want to go extreme, replace glibc with musl. Such an example of extremely minimalist distro is glaucus: https://github.com/glaucuslinux/glaucus

Alpine can also idle with really low ram usage, and it's closer to a real-life, production-ready distro.

As the title says, is it worth it to compile your own custom Kernel and debloat it to gain more performance? This way, how much memory, CPU resources, and Kernel/System activity can be reduced? I heard the native compilation also doesn't use -O3 for GCC. I also heard I can have an uncompressed Kernel image for even faster loading. And when it comes to systemd, I probably would have to make my own distro (oh no) or use some obscure one that uses another init system like Runit (it is much faster). If I keep talking like this, then I would go calling the whole GNU/Linux as bloat. Somebody stop me!

 

Also then I would have to use Debian. I ain't compiling a Kernel every single day. But I like Arch :(.

 

Also I hate replies like "bro just your computer as it is", like bro, I ain't an employee using a computer for work. This is what I really wanted to learn and mess around with when I thought to jump into Linux. Back in the days when I use to experiment on Windows, I used to break it pretty bad. Linux is on a completely new level.  <Just to clarify, I am not mad at anybody, I just sometimes get these replies. This all is purely for experimental purposes.>

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

The reason why you get replies like "just use it as-is" is because you ask questions like "is it worth it?"

 

No, in 99.99% of circumstances, it is not worth it. You will spend more time than you save.

 

Do you want to do it anyway just for fun, on a system that is not important? Go for it!

Link to comment
Share on other sites

Link to post
Share on other sites

14 minutes ago, Gat Pelsinger said:

This is what I really wanted to learn and mess around with when I thought to jump into Linux.

Then do it. Just do it.

 

The is it worth question will get the only real proper answer and that is well it's not worth it. The time, effort and endless frustration isn't worth the 0.2 seconds you save on clicking the file browser basically 😛

 

But if it is to learn and mess around? Fuck it go for it.

 

Just euhh don't do this on your main machine but on something else or a vm because well it's extremely easy to fuck shit up

Link to comment
Share on other sites

Link to post
Share on other sites

@thevictor390 @jaslion

 

Well I know, but I was in search for some actual helpful replies. Like I asked, how will it affect the resource usage?

 

I mean just after boot, I get about 400 MiB of memory usage. How low can I get it with a custom kernel? Only people who have compiled a custom kernel will know this.

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

22 minutes ago, Gat Pelsinger said:

Also I hate replies like "bro just your computer as it is", like bro, I ain't an employee using a computer for work. This is what I really wanted to learn and mess around with when I thought to jump into Linux. Back in the days when I use to experiment on Windows, I used to break it pretty bad. Linux is on a completely new level.  <Just to clarify, I am not mad at anybody, I just sometimes get these replies. This all is purely for experimental purposes.>

Might as well stop beating around the bush then

 

https://www.linuxfromscratch.org/

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Gat Pelsinger said:

@thevictor390 @jaslion

 

Well I know, but I was in search for some actual helpful replies. Like I asked, how will it affect the resource usage?

 

I mean just after boot, I get about 400 MiB of memory usage. How low can I get it with a custom kernel? Only people who have compiled a custom kernel will know this.

It really depends on what you remove. Basically look at arch or other ultra low usage distro's.

 

They are as low as a current day functional kernel can get.

 

You can just use a legit pure linux kernel with nothing but the absolute core components and have some megabytes of ram used if even that. But well it will basically just do a hello world print and thats it.

 

Pretty much depends on what you deem usable. Also keep in mind high memory usage in the form of caching in ram isn't a bad thing at all. Can really speed things up. Sometimes the unused resources are wasted resources way of thinking is not wrong 😛

Link to comment
Share on other sites

Link to post
Share on other sites

Default options won’t net you any performance improvements. You can get some improvement but I personally don’t like to fuck with it. I used XanMod for a while on my shitty laptop it did make a difference in games but it didn’t even support ZFS lol.

mY sYsTeM iS Not pErfoRmInG aS gOOd As I sAW oN yOuTuBe. WhA t IS a GoOd FaN CuRVe??!!? wHat aRe tEh GoOd OvERclok SeTTinGS FoR My CaRd??  HoW CaN I foRcE my GpU to uSe 1o0%? BuT WiLL i HaVE Bo0tllEnEcKs? RyZEN dOeS NoT peRfORm BetTer wItH HiGhER sPEED RaM!!dId i WiN teH SiLiCON LotTerrYyOu ShoUlD dEsHrOuD uR GPUmy SYstEm iS UNDerPerforMiNg iN WarzONEcan mY Pc Run WiNdOwS 11 ?woUld BaKInG MY GRaPHics card fIX it? MultimETeR TeSTiNG!! aMd'S GpU DrIvErS aRe as goOD aS NviDia's YOU SHoUlD oVERCloCk yOUR ramS To 5000C18

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Gat Pelsinger said:

I mean just after boot, I get about 400 MiB of memory usage. How low can I get it with a custom kernel?

I've gotten arch down to two digits memory usage without touching the kernel

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

As always, there's an xkcd for it

Is It Worth the Time?

This is the answer to "is it worth it" (there's even one for hunting cheaper gas).
This chart says it's *extremely* unlikely to be worth it, purely on resource allocation. 
If, however, it will yield intangible rewards (let's be clear, you're gonna have to do troubleshooting, you will burn a lot of time, but you WILL learn from them), then absolutely it's worth it

5950X/3080Ti primary rig  |  1920X/1070Ti Unraid for dockers  |  200TB TrueNAS w/ 1:1 backup

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, Sauron said:

I've gotten arch down to two digits memory usage without touching the kernel

WHAT? 2 digits? But how?

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

@OddOod

 

Damn people really do get up with something which has no meaning. I should probably be more careful writing my posts. By "worth it" I did not mean this deep level analysis. I just asked if I will get some noticeable performance improvement or not.

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, Gat Pelsinger said:

WHAT? 2 digits? But how?

If I had to guess, disable the desktop environment.

 

The amount of resources you save by compiling your own kernel is next to zero.

 

A modern kernel will typically contain drivers as modules, so it only loads stuff into memory you actually use.

 

Other than a bit of disk space, you won't save anything by removing them. (and you lose more disk space to kernel sources, unless you delete them once compiled)

 

Compiling drivers into the kennel will net you a very tiny performance improvement, but you'll only want to include what you need.

 

And chances are you missed something critical and suddenly some hardware no longer works as expected. So it'll be a fair amount of trial and error.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Just go use bazzite you can mess around so much without almost breaking system so have fun.

I'm jank tinkerer if it works then it works.

Regardless of compatibility 🐧🖖

Link to comment
Share on other sites

Link to post
Share on other sites

34 minutes ago, Gat Pelsinger said:

WHAT? 2 digits? But how?

barebones wm, no frills, no applets, no animations. it wasn't really something I'd choose to use every day, but it worked. The kernel on its own barely uses any memory so there isn't much you can shave there anyway.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

@Eigenvektor @Sauron

 

That 400 MiB memory usage is with booted in to TTY. I don't use a DE. 

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, Gat Pelsinger said:

That 400 MiB memory usage is with booted in to TTY.

You're probably counting cached memory then. Or running a load of services.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Gat Pelsinger said:

@OddOod

 

Damn people really do get up with something which has no meaning. I should probably be more careful writing my posts. By "worth it" I did not mean this deep level analysis. I just asked if I will get some noticeable performance improvement or not.

Bud, no need to be salty. 
Will you get performance improvement? 1000% depends on your rig and what you change. We can't answer that for you.

5950X/3080Ti primary rig  |  1920X/1070Ti Unraid for dockers  |  200TB TrueNAS w/ 1:1 backup

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Gat Pelsinger said:

That 400 MiB memory usage is with booted in to TTY. I don't use a DE. 

Really depends on what you're doing. My Debian server running a mail server and associated services (e.g. Postgres) and some Docker containers uses around 850 MiB. The rest of the memory is cache (~2.6 GiB), leaving only around 360 MiB completely unused/wasted. This is with everything running stock, no custom kernel or anything.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Gat Pelsinger said:

As the title says, is it worth it to compile your own custom Kernel and debloat it to gain more performance?

Good old "depends" answer here.

2 hours ago, Gat Pelsinger said:

This way, how much memory, CPU resources, and Kernel/System activity can be reduced?

By debloating? Not much, if at all, just gonna save some storage since you won't have many unused modules installed, but you may get bitten in the future for lacking some module for a device you got later lol

CPU on a modern system won't bring you any noticeable benefit tbh. You could get more perf by tuning some stuff, such as changing the CPU and IO schedulers and whatnot.

2 hours ago, Gat Pelsinger said:

I heard the native compilation also doesn't use -O3 for GCC

Depends on your distro (each distro/maintainer decides how to build their software), but most ones do O2. AFAIK, clear linux does 03, but to be honest the different isn't that relevant:

https://www.phoronix.com/review/linux-kernel-o3

 

You'd be better off by enabling architecture specific stuff, like AVX-512 and whatnot, if you do have those available, otherwise it's a moot point.

3 hours ago, Gat Pelsinger said:

I also heard I can have an uncompressed Kernel image for even faster loading.

Meh, I doubt you'll be able to notice the difference in boot times.

3 hours ago, Gat Pelsinger said:

And when it comes to systemd, I probably would have to make my own distro (oh no) or use some obscure one that uses another init system like Runit (it is much faster).

Systemd would be a tradeoff between practicality (I really like it to manage services) for a little bit faster boot time and less disk usage, but you won't gain much CPU time or that much less RAM usage without it.

3 hours ago, Gat Pelsinger said:

This is what I really wanted to learn and mess around with when I thought to jump into Linux.

Why don't you try going through the linux from scratch project to actually learn this stuff and get a grip on everything from toolchains, build processes, system components and whatnot?

 

2 hours ago, Gat Pelsinger said:

I get about 400 MiB of memory usage.

Have you actually looked at what is using those 400MB?

 

2 hours ago, Gat Pelsinger said:

Only people who have compiled a custom kernel will know this.

No they won't because a system is not just the kernel, and the kernel is just a minor part when it comes to overall resource usage.

The actual kernel and init ram usage is pretty irrelevant overall, just as an example, here's what dmesg gives me during boot time for my memory:

[    0.272625] Memory: 131637872K/134094480K available (16384K kernel code, 2119K rwdata, 12920K rodata, 3432K init, 3828K bss, 2456348K reserved, 0K cma-reserved)
 

So ~16.4MB for the kernel (Arch's default one with nvidia and some other extra modules loaded), ~3.4MB for the init system. For a desktop system, you could save maybe some extra 10MB or so, but is that any relevant?

If you're working on an embedded system that's really constrained (I even have some linux devices that only have 64MB of ram, and it's not uncommon to see ones with 16MB of RAM or so) then I can see the point on learning how to build a slim system (again, LFS is a great resource for this), but for anything with over 500MB of RAM I wouldn't care. This point is also kinda moot when talking about such constrained/embedded devices since you would either be using a provided image that's likely slim enough, or you'd be building your own system from scratch anyway.

 

2 hours ago, Sauron said:

I've gotten arch down to two digits memory usage without touching the kernel

You could also get it on the low two digits by replacing the init with a small program that just prints "hello world" and then goes on a useless busy loop, but that wouldn't be any useful haha

 

2 hours ago, Gat Pelsinger said:

Damn people really do get up with something which has no meaning. I should probably be more careful writing my posts. By "worth it" I did not mean this deep level analysis. I just asked if I will get some noticeable performance improvement or not.

The issue is that you often make a really broad question (which more often than not the answer is "depends"), rarely ever go into any relevant details, and do a mix of "will I have any benefit?" + "it's just for lols". So yeah, maybe you should phrase better what you actually want to achieve and are your measurement of "worth it or not".

1 hour ago, Gat Pelsinger said:

That 400 MiB memory usage is with booted in to TTY. I don't use a DE. 

Look into htop and you should have some stuff already running in the background using memory, along with caches. You can also take a look at the running services with a "systemctl | grep running"

FX6300 @ 4.2GHz | Gigabyte GA-78LMT-USB3 R2 | Hyper 212x | 3x 8GB + 1x 4GB @ 1600MHz | Gigabyte 2060 Super | Corsair CX650M | LG 43UK6520PSA
ASUS X550LN | i5 4210u | 12GB
Lenovo N23 Yoga

Link to comment
Share on other sites

Link to post
Share on other sites

@Sauron

 

free -h reports ~450Mib. Neofetch reports ~250 Mib. And the way Linux works is that they both are correct in their own sense. But I still don't know how you can get that number to 2 digits, and also not even touching the Kernel. Like I am pretty sure I heard somewhere like either today or 10 years ago (I don't remember), The Linux Kernel takes at least 64 MB to boot up.

 

Can't believe I forgot this but I did an experiment running Linux in a very tight memory environment. If I can remember, the system (not just the Kernel but also Arch) at least required a bare minimum of 200 MB without SWAP to just boot up and not panic when rebooting.

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Gat Pelsinger said:

I just asked if I will get some noticeable performance improvement or not.

You can config a custom kernel to boot faster, exclude drivers you explicitly don't need and save memory (some options are boolean and not available as tri-state modules).

Now booting faster means nothing to me, my desktop uptimes are measured in weeks, and my laptop restores from sleep/hibernate so the longest part of booting is "copying to memory from disk".

 

As far as quantifying memory saved, I saw a guy showing the amount he saved using a custom kernel in ubuntu - I don't remember how much it was because "I do that already and I see no reason to change", but he was impressed so YMMV...

 

In 20 years of building static non-modular kernels I've only built one that uses an initrd and is dynamically loading drivers from disk, yes it's slower, but the difference is still an order of magnitude less than the time bios takes to POST.

Link to comment
Share on other sites

Link to post
Share on other sites

Almost the same question as is it worth it to compile your own Adobe premier for performance. 

 

3 hours ago, Ralphred said:

As far as quantifying memory saved, I saw a guy showing the amount he saved using a custom kernel in ubuntu - I don't remember how much it was because "I do that already and I see no reason to change", but he was impressed so YMMV...

Your operating system should be using as much ram as it can because this way applications are cache and will load/perform faster and better. People who keep on talking about small ram usuage sacrifices two things. 1. Less feature rich and uglier/less capable softwares OR 2. counterintutively less performance because using cache data rather than rerunning computation for the same data all over again is actually faster, who knows! It is almost as if some alogrithms are design to trade space for time!(for those not familar, this is a common strategy in alogrthm design and analysis to speed up an alogrithm and improve efficiency). 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, wasab said:

Your operating system should be using as much ram as it can

Yep, and if the kernel isn't using it that makes it free for other programs to use.

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, Gat Pelsinger said:

But I still don't know how you can get that number to 2 digits

Disabling services and other useless software.

23 minutes ago, Gat Pelsinger said:

and also not even touching the Kernel.

As I already said before, the Kernel is the least of your worries when it comes to ram usage.

24 minutes ago, Gat Pelsinger said:

Like I am pretty sure I heard somewhere like either today or 10 years ago (I don't remember), The Linux Kernel takes at least 64 MB to boot up.

Nah, you can boot the kernel itself in less than 1MB, and even have SSH and networking with ~1MB of RAM, but that's basically just the kernel and some core components, not useful for a desktop system.

26 minutes ago, Gat Pelsinger said:

Can't believe I forgot this but I did an experiment running Linux in a very tight memory environment. If I can remember, the system (not just the Kernel but also Arch) at least required a bare minimum of 200 MB without SWAP to just boot up and not panic when rebooting.

That's mostly due to other software that the system tries to start on boot, you can get a pretty minimal install if you want. As an example, here's an archbang vm install with some stuff disabled and ctwm + xterm:

image.png.731c83ff5876510235e5c02c3cfb0081.png

 

Less than 200mb, using systemd (which does take it fair share of ram), without swap. Systemd takes around 10mb of ram in total:

image.png.74fdb3b8ad89f8ab6c52342a0f06b5de.png

 

And here's top sorted by memory:

image.png.eab6d3df9bbbeee98ca99288f1b68727.png

 

If you were to forgo systemd and some other quality of life stuff you can easily go below 100MB usage. Xorg alone takes almost 20MB lol

You can also disable some unused kernel modules (without actually rebuilding the kernel) to shave some extra ram.

 

If you want to go extreme, replace glibc with musl. Such an example of extremely minimalist distro is glaucus: https://github.com/glaucuslinux/glaucus

Alpine can also idle with really low ram usage, and it's closer to a real-life, production-ready distro.

FX6300 @ 4.2GHz | Gigabyte GA-78LMT-USB3 R2 | Hyper 212x | 3x 8GB + 1x 4GB @ 1600MHz | Gigabyte 2060 Super | Corsair CX650M | LG 43UK6520PSA
ASUS X550LN | i5 4210u | 12GB
Lenovo N23 Yoga

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×