Week 7: Grow, MMap, Grow!

If you hear the word: "Dynamic" what do you thing?

APT includes a DynamicMMap to build his package cache. If the user added enough sourcelist entries the user saw the DynamicMMap in full action: It was so dynamic that it even ran out of room. I don't know about you, but this drove me crazy for a long time. Nearly a year ago i implemented a Grow() method which tried to grow the DynamicMMap if needed. That worked in theory - and this even for kfreebsd & co which do not have mremap available for moving - for these systems it uses a char[] array and realloc.

The only problem was: While the binary cache tries hard to be reusable in a subsequent call - otherwise the cache would make much sense after all - while building the cache it couldn't be remapped. All sorts of iterators pointed into the MMap so just enabling MOVEABLE resulted in a huge SEGFAULT probability…

Why I am writing all this and why I try to talk in past tense here? 5 bugs (and counting) are already talking about it - and they are marked as done now. 🙂 The theory is simple: Each pointer into the MMap registers itself and every time the MMap gets a new location some pointer arithmetic is used to fix it.

The theory is easy, in practice it was a bit harder to achieve as the methods causing a grow need to be identified and also all the pointers into the MMap - gdb is a good friend now - and I managed to disprove some bug report participators saying it would be impossible and/or too hard. Yeaha! 🙂

Anyway Mid term evaluation is now, so I suspect I will be a bit more verbose next week and so I am better of saving the reader now from all the boring details. 😉