lua-users home
lua-l archive

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


Dears,

  I didn't understand this behavior of Lua GC. My Linux box:

[michel@magnesio michel]$ uname -a
Linux magnesio.k8.com.br 2.6.3-7mdk-p3-smp-64GB #1 SMP Wed Mar 17
15:34:39 CET 2004 i686 unknown unknown GNU/Linux


### Case 1: The expected behavior.

[michel@magnesio michel]$ lua
Lua 5.0.2  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> print(gcinfo())
14      24
> -- Obtain the memory used for this process in other terminal.

  With the top command:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
10780 michel    16   0  1848  620 1664 S  0.0  0.0   0:00.00 lua

> t = {}
> for i=1,10000000 do
>> t[i] = i  -- Important line.
>> end
> print(gcinfo())
196622  393244
> -- Obtain the memory used for this process in other terminal.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
10780 michel    16   0  193m 192m 1664 S  0.0  5.0   0:01.30 lua

> t = nil
> print(gcinfo())
196623  393244
> collectgarbage()
> print(gcinfo())
14      28
> -- Obtain the memory used for this process in other terminal.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
10780 michel    16   0  1848  736 1664 S  0.0  0.0   0:01.34 lua

  All right.


### Case 2: Lua GC: OK; Process Memory: NO.

  Important line here: t[{}] = i

  Final results:

> t = {}
> for i=1,10000000 do
>> t[{}] = i
>> end
> print(gcinfo())
771266  839679

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11122 michel    16   0  831m 830m 1664 S  0.0 21.5   0:10.21 lua

> t = nil
> print(gcinfo())
771267  839679
> collectgarbage()
> print(gcinfo())
14      28

  GC Lua is OK.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11122 michel    16   0  383m 382m 1664 S  0.0  9.9   0:10.92 lua

  The process memory is NOT ok: ~380MB.


### Case 3: Lua GC: NO; Process Memory: NO.

  Important line here: t[i..""] = i

  Before from collectgarbage():

> print(gcinfo())
757591  1439648

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11213 michel    16   0  818m 817m 1664 S  0.0 21.2   0:39.07 lua

  After:

> print(gcinfo())
32781   65562

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11213 michel    16   0  306m 305m 1664 S  0.0  7.9   0:44.63 lua


### Final notes.

  This problem is occurring in a real application too:

...
IN      416     831 -- print("IN", gcinfo())
OUT     421     831
IN      416     831
OUT     421     831
IN      416     831
OUT     518     854
IN      416     831
OUT     421     831
IN      416     831
OUT     421     831

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
1144 isee1     16   0 1593m 1.6g 3744 S  0.0 41.2  20:11.49 lua

[ ]'s
Michel Machado