lua-users home
lua-l archive

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



On Sep 5, 2013, at 10:25 PM, Andres Perera <andres.p@zoho.com> wrote:

Sigh.

Whether or not malloc() organizes objects into buckets sized n^2, malloc() can only acquire multiples of pagesize of virtual memory at a time. One page can hold multiple objects.

In function ``f'',

int f()
{
    /*pa*/
    z = malloc(x);
    /*pb*/
}

i
L
L
f at pa the process has allocated n bytes, and malloc(x) is successful, then at pb the process vm will be  (n + x + PAGESIZE-1) & ~(PAGESIZE-1), in other words, rounded to the nearest greater pagesize multiple. Please show a system where this is false.



Um, what? First, you are assuming a simple case where there are no free() calls in pa. Second you are assuming that the heap manager has not over-allocated or pre-allocated pages (most do). Third you are assuming the heap manager makes no attempt at padding or leaving expansion space, or choosing different allocation strategies for differently sized blocks, or does anything beyond a simplistic linear allocation. Almost no real-world system exhibits the linear allocation model your example assumes, and so I would assert that it is false in EVERY system I have ever used; most will have allocated significantly more pages than your model assumes.

And even if it were true, so what? We were discussing the overhead of adding a void* to either Lua_State or Lua globals, a trivial addition to either structure. Nothing in that discussion is even vaguely impacted by the relationship between the C runtime heap manager and the OS VM allocation mechanisms.

--Tim