Reducing coldplug memory usage

Richard Hughes hughsient at gmail.com
Mon Jan 1 15:12:34 PST 2007


Attached is a patch that removes the static 1000 device chunk of memory
allocated for coldplug, and instead uses the new g_slice allocator.

This reduces the memory allocations at startup from 4Mb to 1.2Mb on my
machine as we only allocate the chunks as we add the devices. On devices
such as n770 or OLPC the difference should be even greater as there are
far fewer devices than on this 150+ device laptop.

A bit of background: g_slice is a much better allocator than g_new as we
are always creating the same size chunks of memory. The g_slice
allocator can be used in versions of glib >= 2.10.0, so we would
obviously require am updated dependency on this, as we currently only
require glib 2.6.0.

There is no measurable speed difference on my machine, although I expect
for low power ARM machines there should be a saving for startup speed
also. I can profile this further if required.

old g_new (with large pool) code:

[root at hughsie-laptop hald]# ./profile-hald.sh 
0..1..2..3..4..5..6..7..8..9..10..
total process time:
0m0.001s 0m0.004s
0m2.125s 0m0.502s

This is using 4Mb of memory at startup for queue_events()

proposed change using g_slice_new without pool:

0..1..2..3..4..5..6..7..8..9..10..
total process time:
0m0.006s 0m0.003s
0m2.133s 0m0.563s

This uses 1.2Mb of memory in the slice allocator.

The profile graphs can be seen here:
http://people.freedesktop.org/~hughsient/temp/massif-old.pdf
http://people.freedesktop.org/~hughsient/temp/massif-gslice.pdf

Another thing, should I commit my massif and speed profile scripts
(attached) to play with?

So, any objections or comments? Happy new year by the way! :-)

Thanks,

Richard.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hal-use-gslice.patch
Type: text/x-patch
Size: 2725 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/hal/attachments/20070101/e15b9762/hal-use-gslice.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: massif-hald.sh
Type: application/x-shellscript
Size: 1035 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/hal/attachments/20070101/e15b9762/massif-hald.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: profile-hald.sh
Type: application/x-shellscript
Size: 726 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/hal/attachments/20070101/e15b9762/profile-hald.bin


More information about the hal mailing list