summaryrefslogtreecommitdiff
path: root/epan/wmem
AgeCommit message (Collapse)AuthorFilesLines
2014-03-04Remove assertions from block allocator.Evan Huus1-30/+0
It has been extremely well-tested at this point, and is a very hot code path so the performance gain is measurable (~1-2% on most captures I tried). Change-Id: I2f5e03d2f348f56e740bf0dfbc83a4fd9cc8c5a9 Reviewed-on: https://code.wireshark.org/review/499 Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-01-05From Jim Young via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9613Evan Huus1-3/+3
Don't use "rand" as a variable name, it shadows a global in recent MacOSX stdlib.h svn path=/trunk/; revision=54598
2013-12-24Add wmem_destroy_list, wmem_destroy_queue, wmem_destroy_stack so that thoseEvan Huus5-0/+35
data-structures can be used with manually managed memory. svn path=/trunk/; revision=54432
2013-12-20Try to please the buildbot.Anders Broman1-1/+1
svn path=/trunk/; revision=54281
2013-12-20Fix [-Wmissing-prototypes]Anders Broman5-3/+6
svn path=/trunk/; revision=54280
2013-12-15Fix some const/ not const warnings.Jakub Zawadzki1-2/+2
svn path=/trunk/; revision=54114
2013-11-05Expose wmem_list_remove_frame to make it efficient to do pop operations asEvan Huus2-0/+10
wmem_list_remove_frame(wmem_list_tail()) svn path=/trunk/; revision=53088
2013-10-19Don't link explicitly with libwmem, it's already in libwireshark and the symbolEvan Huus1-2/+2
doubling leads to all sorts of very subtle badness (including test failures due to funny internal assertions because the two wmems have mismatching state). Make wmem_init and wmem_cleanup PUBLIC instead of LOCAL so that they don't get stripped and don't cause a link failure when trying to build oids_test (now that it's not linking with libwmem explicitly). There is possibly a better way to fix this, but I'm not sure what it is. svn path=/trunk/; revision=52694
2013-10-15As suggested separately by both Jakub and Anders: only read theEvan Huus2-55/+39
WIRESHARK_DEBUG_WMEM_OVERRIDE environment variable once in wmem_init, not every time wmem_allocator_new is called. We currently create a new pinfo pool for every packet we dissect, so this is a small performance win, especially when getenv is slow (which may happen if a large number of environment variables are set, such as when fuzz-testing). svn path=/trunk/; revision=52634
2013-10-15Don't do canaries in blocks of guint32, it appears to cause alignment issuesEvan Huus1-9/+9
when running tests on Solaris. Revert back to byte-at-a-time, but do fewer bytes to avoid a performance hit. svn path=/trunk/; revision=52617
2013-10-13Subsume README.binarytrees into wmem doxygen. The README was out of dateEvan Huus1-14/+59
anyways, since Michael made key operations non-destructive in r44380. svn path=/trunk/; revision=52583
2013-09-28Don't assert that the key to a wmem tree operation is short. If XMPP wants toEvan Huus1-4/+0
use a 1500-byte string as a key, so be it. It will be slow, but at least it will work. Fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9078 svn path=/trunk/; revision=52261
2013-09-08Cycle the recycler in realloc() and free() as well, reducing memory usage of theEvan Huus1-3/+17
stress-test by another ~10%. svn path=/trunk/; revision=51840
2013-09-01Send all alloc and free calls within wmem through wmem_alloc and wmem_free withEvan Huus8-40/+45
a NULL allocator. This gives us a single, central place to handle out-of-memory errors (by, for example, throwing an exception) for basically all of epan. The only remaining glib memory that is directly allocated is for the hash tables used by the simple and strict allocators. svn path=/trunk/; revision=51627
2013-09-01Do our list manipulation entirely after the realloc, so that if the reallocEvan Huus1-3/+10
doesn't return (do to, for example, throwing an exception) the allocator is left in a consistent state. svn path=/trunk/; revision=51626
2013-08-31In the strict allocator, do canaries in units of guint32 instead of guint8. ThisEvan Huus1-19/+22
makes canary checking about 20% faster, which should speed up fuzz-testing now that more and more dissectors use wmem. svn path=/trunk/; revision=51620
2013-08-14Include config.h first; it defines _FILE_OFFSET_BITS, and if some systemGuy Harris7-12/+15
header later causes it to be redefined - as happens on my Solaris 11 virtual machine - we get a redefinition warning, which gets treated as an error. svn path=/trunk/; revision=51344
2013-08-13As suggested in https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9033Evan Huus1-11/+1
Make epan_free a no-op if the pointer is NULL. This fixes 99% of the cases causing problems for wmem_leave_file_scope() - remove that XXX comment and add back the assertion. Remove the cleanup_dissection call from epan_cleanup, it doesn't make sense there. init_dissection is only called from epan_new, so cleanup_dissection should only be called from epan_free. Add one missing epan_free call to tshark revealed by the above changes. svn path=/trunk/; revision=51342
2013-08-12Be sure to initialize the jumbo flag when creating a new chunk header byEvan Huus1-8/+15
splitting an existing chunk. Thanks to Jeff for catching this one. svn path=/trunk/; revision=51325
2013-08-11Reorder and group chunk header flags. Reduces the bit-twiddling needed by theEvan Huus1-3/+5
compiler and provides a surprising (if fairly small) performance win. svn path=/trunk/; revision=51305
2013-08-11Split jumbo_free and jumbo_realloc into their own functions for readability andEvan Huus1-13/+45
consistency (they are called just once and will be inlined by any reasonable compiler). Also add some comments, fix some spacing etc. No functional changes. svn path=/trunk/; revision=51304
2013-08-11Move the null check outside the function call. Simpler, and more efficient forEvan Huus1-5/+3
compilers that decide not to inline. svn path=/trunk/; revision=51303
2013-08-11Little optimization: move two statements inside an if block.Evan Huus1-3/+3
svn path=/trunk/; revision=51302
2013-08-11Add support for allocating more than will fit in a single block, through the useEvan Huus2-16/+110
of a jumbo flag in the chunk header. svn path=/trunk/; revision=51299
2013-08-11Instead of using a glib slist to track the list of blocks, embed a shortEvan Huus1-51/+84
doubly-linked list at the head of each block. This was intended as a step towards supporting allocations bigger than the usual block size, but also shows up as a 2% performance improvement in the speed test, so win-win. svn path=/trunk/; revision=51298
2013-08-11Small optimization: the master-list and recycler cases are different enough thatEvan Huus1-14/+22
doing all the safety checks was unnecessarily slow. Do only the appropriate checks for each case. svn path=/trunk/; revision=51296
2013-08-10Fix (-W)documentation error found by ClangAlexis La Goutte1-7/+3
../../epan/wmem/wmem_user_cb.h:52:11: error: parameter 'allocator' not found in the function declaration [-Werror,-Wdocumentation] * @param allocator The allocator that triggered this callback. ^~~~~~~~~ ../../epan/wmem/wmem_user_cb.h:53:11: error: parameter 'event' not found in the function declaration [-Werror,-Wdocumentation] * @param event The event type that triggered this callback. ^~~~~ ../../epan/wmem/wmem_user_cb.h:54:11: error: parameter 'user_data' not found in the function declaration [-Werror,-Wdocumentation] * @param user_data Whatever user_data was originally passed to the call to ^~~~~~~~~ ../../epan/wmem/wmem_user_cb.h:63:11: error: parameter 'recurring' not found in the function declaration [-Werror,-Wdocumentation] * @param recurring If this is FALSE then the callback is called exactly once. ^~~~~~~~~ 4 errors generated. svn path=/trunk/; revision=51259
2013-08-09Enhance verification to assert that the recycler and master list contain allEvan Huus1-12/+34
free chunks of sufficient size. svn path=/trunk/; revision=51234
2013-08-08One more chunk header alignment fix.Evan Huus1-2/+2
svn path=/trunk/; revision=51218
2013-08-08Make sure our chunk headers are large enough to correctly align the actual dataEvan Huus1-7/+9
pointer we return. svn path=/trunk/; revision=51217
2013-08-08When splitting a free chunk, if we don't have room for a free header don't evenEvan Huus1-42/+29
bother splitting. This greatly simplifies the logic, trims another 4% off the fast path, and doesn't actually affect the results at all because of the way we pad for alignment anyways. svn path=/trunk/; revision=51216
2013-08-02Combine two ternary ?: into a single if. Shaves about 1.5% off the fast timingEvan Huus1-2/+8
test. svn path=/trunk/; revision=51112
2013-08-02Small simplificationEvan Huus1-3/+2
svn path=/trunk/; revision=51111
2013-08-02Remove unnecessary null check.Evan Huus1-4/+0
svn path=/trunk/; revision=51110
2013-08-02Rewrite the merge_free routine to keep the merged chunk on the master free listEvan Huus1-75/+80
if the right-hand merge target was there originally. This brings memory usage down another ~40% when running the heavy test suite. This also lets us extract the master-list check out of unfree() since it is now only relevant at a single caller, and turns unfree into the more understandable remove_from_recycler(). svn path=/trunk/; revision=51104
2013-07-31Add wmem_tree_is_empty(). Also permit lookups on a NULL tree for compatibilityEvan Huus3-1/+16
with emem. svn path=/trunk/; revision=51045
2013-07-29More little optimizations.Evan Huus1-5/+3
svn path=/trunk/; revision=51014
2013-07-29Another little optimization.Evan Huus1-18/+11
Removes one branch from the hot path, deduplicates one function call in the cold path by effectively falling through, and makes it more obvious what the code is actually trying to do. svn path=/trunk/; revision=51013
2013-07-28Added more build artefacts to the clean targetGraham Bloice1-1/+1
svn path=/trunk/; revision=50977
2013-07-28Don't force the allocator choice in the data-structure tests, we want to be ableEvan Huus1-10/+10
to override that to simple for valgrinding (we still force the allocator in the allocator and timing tests, of course). svn path=/trunk/; revision=50971
2013-07-28Fix a bug in the gc routine discovered while formally working out parts of theEvan Huus2-11/+29
algorithm. Also add a test case to excercise it for future. svn path=/trunk/; revision=50970
2013-07-28Little optimizations.Evan Huus1-6/+5
Move a few assignments around to avoid one extra subtraction. I suspect having the two if statements next to each other is friendly to the compiler's optimizer as well. Shaves ~1.3% off my timing tests, bringing the new design *very* close to the old one in raw allocation speed. svn path=/trunk/; revision=50961
2013-07-27Little things make big differences: somehow while I was experimenting thisEvan Huus1-1/+3
unobtrusive if statement got dropped. Without it the allocator exhibits the old bad behaviour of 3x memory usage and heavy fragmentation. We want it back, thank you very much. svn path=/trunk/; revision=50960
2013-07-27Small optimization: conjoin two mutually exclusive ifs with an else.Evan Huus1-3/+4
svn path=/trunk/; revision=50959
2013-07-27Simplify out an addition that happened a lot by performing it once on theEvan Huus1-10/+8
variable it affected, since that variable wasn't used for any other purpose. svn path=/trunk/; revision=50958
2013-07-27Redesign of the wmem block allocator.Evan Huus1-298/+371
What was becoming apparent as more dissectors started using wmem was that the old block allocator design had issues with memory fragmentation. This keeps the same underlying memory layout, but completely changes how free blocks are kept. It runs about 3% slower in my tests (still an order of magnitude faster than g_malloc) but uses about 1/3 the memory. I suspect some simple optimizations could reclaim that 3% as well - the design is fast, but I did not code particularly for speed. Thoroughly tested with the existing test suite (which caught half a dozen bugs in my first draft) so it should actually work! svn path=/trunk/; revision=50955
2013-07-27Use a #define, tweak a comment.Evan Huus1-2/+2
svn path=/trunk/; revision=50954
2013-07-26whitespaceEvan Huus1-2/+2
svn path=/trunk/; revision=50919
2013-07-21Add wmem queue 'implementation' by wrapping wmem_list and wmem_stack.Evan Huus6-9/+116
Also a bit of misc. refactoring of the stack while I was there, and doc tweaks. svn path=/trunk/; revision=50769
2013-07-20Replace wmem slist (singly-linked) with wmem list (doubly-linked).Evan Huus8-232/+271
The overhead is not large, and it makes append much faster (O(1) vs O(n)). It also will make a queue easy to add, which I need for a dissector I'm writing... svn path=/trunk/; revision=50744