[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I think this qualifies as a newbie question



On 16 Apr 1999, Oleg Goldshmidt wrote:

>"Peter L. Peres" <plp@actcom.co.il> writes:
>
>> At the hw level: The addressable memory on an Intel proecssor is divided
>> into pages (currently 4k each ?). This is the minimum size of any
>> allocated memory, file, program etc. 
>
>Are you saying that "malloc(sizeof(int))" allocates 4k on an Intel
>machine? 

No, malloc(sizeof(int)) tries to find a hole of convenient size in any one
of a billion already allocated 4k pages. Same for kmalloc. BUT the process
paging system allocates pages in 4k increments for the process proper.
Also, pages change 'hands' between the swap and buffer space in the same
kind of increments.

Even this you do not see, because the proper length is stored in a kernel
table and all utils know only that (ps etc). This means, that the largest
space wasted on any process at any time, is 4k-1 bytes, exactly. This is a
very good number imho. BTW N processes that share code waste only 1x(4k-1) 
bytes. The shared exec is another magic thing made possible by rx bits in
the permissions. All mmaped dlls fall into this category afaik and some
'memory usage reports' of programs that are dynamically linked on Linux do
not mention this. 

The 4k comes from the granularity in the descriptor tables of the
processor. If you want to cover 4G then you need 4k pages or smth like
that. This calculation dates back to 386 and it may be possible to make it
finer now, but I havn'e had the time to look at the code. 

Swapping f.ex. works like that (4k pages).

It is just barely possible that the block size is not that now, but
everything seems to indicate, that it is. F.ex. the default buffer size of
almost any cli utility and pipe seems to be 4k, and that is normally (i.e. 
outside Redmond,WA imho) allocated to be equal to fstat->buffsz on the
current file system (good q: which one ?) or a whole multiple thereof to
improve efficiency with disk access. This has been standard practice since
floppies were wooden afaik (not even stone, see ?). 

nb: what I am saying here dates back to 1.2.13 kernels. Check your facts
please.

Peter