From: wpp@marie.physik.tu-berlin.de (Kai Petzke) Subject: Re: [Q] Executable size varies with compile options ?? Date: 13 Apr 1993 13:22:04 GMT
In <C53MpG.DJy@news.claremont.edu> michael@jarthur.claremont.edu (Michael Elkins) writes:
>Can someone please explain this to me?
> Compile Options File Type Size
> -s -m486 Linux/i386 demand paged executable 74756
> -s Linux/i386 demand paged executable 13312
> ?? Linux/i386 executable 3392
>To me it looks as if the program is being linked statically with the -m486
>options. But I get all sort of errors when I try to use the -dynamic option.
>And just what is/are the options to make it NON 'demand paged' ? For that
>matter, what does 'demand paged' mean in comparison to something that is not?
I don't know what could make the big difference between 74756 and 13312.
The difference between 13312 and 3392 should be the -N option. Without this
option, code and data segment are padded to a multiple of 4096 bytes. The
remaining bytes are the file header. The size command tells you sizes
more in detail than ls -l.
If you use -N, this padding is not done. But this impacts demand loading
(see below) and the shareing of images, so -N does make sense on the lots
of small programs, where it saves a lot of disk space. For big programs,
the disk usage is increased by a few percent only.
Demand paged means, that the linux kernel does not load the executable into
main memory, when started. Accessing the first byte of the code will
generate a page fault, so the kernel will load the first page needed. When
processing moves or jumps to another page, this page is loaded, and so on.
Performance loss on small executables is very few, as most disks today have
a small disk cache on drive, and Linux is very likely to find all pages
in this disk cache, so it does not matter, whether they are requested all
at once in order, or one by another in any order.
Performance gain on large executables can be very big, especially, when
an interactive program (think of emacs) uses only a small amount of the
big coding space at any time. The program will start up at once, and
will continue to load the pages needed.
Performance loss on big executables, which require the whole coding space
in one run, seems to be moderate: Run "time gcc" (under csh this will truly
work) on any programm after you freshly started linux, run this command
again, but subtract the time you needed to copy about 1 Megabyte to
/dev/null.
Demand Page Loading is part of the Linux swapping machanism, as program
code pages don't have to be swapped out, when space gets narrow. Linux can
simple forget them and reload them the next time, they are needed. So
this saves a lot of resources, when the system is heavily loaded anyways.