14

I'm wanting to read and understand the Linux kernel's Memory Management (in particular defrag\compaction\migration).

So, I turn off optimization for size in .config (using make menuconfig of course) and compile...This leaves me with still an optimized kernel.

NOTE: When I say optimized kernel, I mean that when I use gdb and tell it next that it'll jump around. I don't want that, I want to be able to follow the code line by line just as I would with a simple hello world.

Next, I edit the Makefile and swap -O2 with -O0 and that causes things to break.

I found this, but I don't know what files I'll want because I don't know how far down the rabbit hole goes.

Is there a more generic option that I can use? I understand the concepts of memory compaction; however, I want to see where everything happens and how it exactly happens.

6
  • How are you gdbing the kernel? Do you have kgdb support turned on? Commented Mar 19, 2015 at 17:46
  • @EugeneSh. I'm going through qemu -s in DEBUG_KERNEL is enabled. I'll enable kgdb and report the results. Commented Mar 19, 2015 at 17:51
  • @EugeneSh. Although I couldn't get a pipe working with qemu (gdb threw fits), there doesn't seem to be a difference. Commented Mar 19, 2015 at 20:36
  • 2
    While going through the question above, I'm suddenly curious, why Linux kernel has to be optimized for working properly? Commented Mar 20, 2015 at 4:09
  • 1
    Greg says it can't be done, thus you can't be done (in practice): lists.kernelnewbies.org/pipermail/kernelnewbies/2016-August/… :-) Related: unix.stackexchange.com/questions/153788/… Commented Feb 18, 2017 at 19:28

1 Answer 1

17

You can't de-optimize the kernel. You might be able to de-optimize certain functions, like this:

void __attribute__((optimize("O0"))) foo(unsigned char data) { // unmodifiable compiler code } 

But the kernel as a whole requires -O2 because the code itself is written with assumptions that certain functions will be optimized in a certain way.

Sorry, but you really will need to know the size of the rabbit hole you want to go down.

Sign up to request clarification or add additional context in comments.

3 Comments

Can we set optimization as -O1 instead -O0?
„But the kernel as a whole requires -O2 because the code itself is written with assumptions that certain functions will be optimized in a certain way.“ – That sounds ugly.
As of gcc v14.2, the documentation claims that -Og is better than -O0 for debugging. Even better: the (semi-random) function I tried to add this __attribute__ to does not compile with O0 but does with Og.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.