Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a query about kernel optimization; is that I am quite new in this world and I am learning. And before doing something serious, I want to collect as much information as possible in response to my doubts.
Excuse my ignorance on the subject, but... is there a specific optimization for an exact processor/CPU model? For example, for the Pentium III there are three versions: Katmai, Coppermine and Tualatin. Or is it done generically based on the brand Intel regardless of the exact model of the processor?
Hi
It's a valid/good question (if I understood it correctly )
As far as I know:
- on one hand the Linux kernel is usually not compiled to be optimized for a specific CPU model, respectively, you won't find an option that mentions your CPU model.
- on the other hand ~last year I read about kernels that could be compiled for the specific CPU model (something like "-march=native -O3") => I do not remember anymore the results but as I did not try it out I suppose that they weren't that great.
I guess that better optimizations are more related to the options in the kernel config?
E.g. right now I'm now wondering if I should activate or not "CONFIG_SCHED_CORE"; in my case it's for a host that will run PostgreSQL, so I guess that I'll have to test that on my own with my own specific workload to really understand its performance impact...
optimization is made by the compiler, so it depends on the compiler and obviously the invocation, the command line options.
General kernels are not really specialized to any CPU. In any case see the manual of the compiler to check the possibilities.
If you really wanted, I'm sure the Linux kernel is NOT perfect, so you could either fork the linux kernel wherever the repository is (probably github), or you could just privately work on it, and you should probably give back your changes. Then, from that perspective, optimizing the Linux kernel is like optimizing a Hello World application. You could almost always make it more efficiant, if you try hard enough. Some changes the compiler optimization will optimize out, some changes the compiler will keep in. Heck, you could also modify the generated assembly language, and the prewritten assembly language. Or if you're really daring, the machine code. This probably isn't the quote on quote "normal" way to make the optimization you are looking for, or the easiest. But it IS possible, and I wanted you to be aware of it. You could also translate it into more efficient langauges. Since it's open source and FOSS, the possibilities are limitless. I just wanted to make you aware of endless possibility, and also make sure you didn't need to be more specific, or are you finding the answers? Even if you are finding what you're looking for, I did NOT want you to overlook this possibility.
If you are interested in optimising the kernel, the Gentoo documentation may be useful. https://wiki.gentoo.org/wiki/Kernel/...guration_Guide
Whether it's worth doing is another question. Even many (most?) Gentoo users opt for the generic kernel and you'll note that they suggest that one motive for making a custom kernel might be "severe boredom"!
my 2 cents, what is your end goal? run the Kernel for a specific application? or run the Kernel without other modules that won't be needed in your device?
So, basically you can optimize it by excluding some modules. For example, if you want Linux to run on your browser, and you only need it to process for data that uses, sed, awk, or other tools.
In this way, you can optimize it by excluding drivers that you won't need so it will be lightweight.
As, what other suggested it would depend on how you compile it. Good luck, keep exploring ... and enjoy the journey.
FYI, if you do choose to explore the Gentoo distribution, this system does allow you to make a specific CPU-type selection and it will compile the kenel (and, "gcc") with these settings considered. Gentoo is a source-code based distribution where you actually compile everything when you install it.
I once used this on an old "slow" laptop that had been sold to me with Windows-95 installed. Using Gentoo, over time, I was able to make the machine positively fast.
The only optimizing of the kernel I ever "needed" on my oldest machines (originally windows 3.0 and up) was targeted drivers vs generic( with mostly a netinst and sid ). My IBM Thinkpad T20 (thrift store) still flies, even if I fire up a DE and compared to what it originally did with microcoughed.
Optimizing for a specific CPU mostly affects vectorized and floating point calculations, neither of which are used in the kernel. It's not clear you would gain much.
My advice from my limited understanding, is unless you're trying linux for scratch, or trying to write you're own distribution or OS, unless you REALLY know what you're trying to do, I would avoid optimizing - that is, unless required, or unless you are going to contribute code to an existing distribution. However, it's possible, at least as stated. I just personally would try everything else first. However, once you get to a certain point in your programming journey, it would be an advantage to try to read and understand at least the linux kernel, unless you are going to need to make a proprietory competing OS, that uses in NO way, the Linux kernel, but does the same thing. Reading, will help you understand the language you want to program in. I've told you how I know to go about optimizing, if you want to though. Gentoo would be great, like the DavidMcCann said. Then, you might get benefits out of compiling AND optimizing.
I forgot to say, if you want it optimized some, there is almost always an existing distribution, that has already done it. But if you insist on staying with current distribution, then it might make some more sense. This should help a little more. But yes, please tell, if I didn't miss it, what you're end goal of optimizing is. That will target the discussion.
Last edited by des_a; 05-09-2023 at 09:52 PM.
Reason: Forgot about distros...
Haven't had to heavily optimise for years and last time I did, it was for running squid proxy.
File system, the kernel, etc were modified with the target of running squid only.
This query had me googling to see if optimising today is just as easy.
First hit took me to this page and step 6 under 'Compiling your kernel' is interesting with the use of cflags, never done that before. https://github.com/sn99/Optimizing-linux
If you are interested in optimising the kernel, the Gentoo documentation may be useful. https://wiki.gentoo.org/wiki/Kernel/...guration_Guide
Whether it's worth doing is another question. Even many (most?) Gentoo users opt for the generic kernel and you'll note that they suggest that one motive for making a custom kernel might be "severe boredom"!
I personally think that this is debateable and that being able to configure an ad-hoc kernel shouldn't be downplayed . Saying this because I admit that while I hate to do that (review dozens or more of new/changed settings for each major kernel upgrade), I still ~like to do it to personally keep up-to-date with introduced changes (reading docs often make me aware of new/changed functionality) and maybe other weird/interesting changes that happened since the last kernel.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.