Commit Graph

169 Commits

Author SHA1 Message Date
Evan Huus c5319ebc93 One more chunk header alignment fix.
svn path=/trunk/; revision=51218
2013-08-08 12:23:23 +00:00
Evan Huus 0ebe18dcea Make sure our chunk headers are large enough to correctly align the actual data
pointer we return.

svn path=/trunk/; revision=51217
2013-08-08 11:27:39 +00:00
Evan Huus d8684cf32d When splitting a free chunk, if we don't have room for a free header don't even
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-08 11:16:10 +00:00
Evan Huus c4e966b880 Combine two ternary ?: into a single if. Shaves about 1.5% off the fast timing
test.

svn path=/trunk/; revision=51112
2013-08-02 01:58:52 +00:00
Evan Huus a7b30a2a2c Small simplification
svn path=/trunk/; revision=51111
2013-08-02 01:51:06 +00:00
Evan Huus c85ec68e58 Remove unnecessary null check.
svn path=/trunk/; revision=51110
2013-08-02 01:36:52 +00:00
Evan Huus 64ed83d793 Rewrite the merge_free routine to keep the merged chunk on the master free list
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-08-02 00:12:12 +00:00
Evan Huus 8fafa9b758 Add wmem_tree_is_empty(). Also permit lookups on a NULL tree for compatibility
with emem.

svn path=/trunk/; revision=51045
2013-07-31 01:48:47 +00:00
Evan Huus 44d53b4042 More little optimizations.
svn path=/trunk/; revision=51014
2013-07-29 16:55:02 +00:00
Evan Huus 0fb6d96507 Another little optimization.
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-29 16:47:30 +00:00
Graham Bloice 2f6ee944d8 Added more build artefacts to the clean target
svn path=/trunk/; revision=50977
2013-07-28 14:40:56 +00:00
Evan Huus a9bccc8dc8 Don't force the allocator choice in the data-structure tests, we want to be able
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-28 12:55:37 +00:00
Evan Huus b43996c8ab Fix a bug in the gc routine discovered while formally working out parts of the
algorithm.

Also add a test case to excercise it for future.

svn path=/trunk/; revision=50970
2013-07-28 12:46:44 +00:00
Evan Huus b9870c0969 Little optimizations.
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-28 00:00:37 +00:00
Evan Huus e7dfea82f3 Little things make big differences: somehow while I was experimenting this
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-27 23:35:59 +00:00
Evan Huus 9b9467cb79 Small optimization: conjoin two mutually exclusive ifs with an else.
svn path=/trunk/; revision=50959
2013-07-27 23:01:24 +00:00
Evan Huus 720cce4102 Simplify out an addition that happened a lot by performing it once on the
variable it affected, since that variable wasn't used for any other purpose.

svn path=/trunk/; revision=50958
2013-07-27 22:51:27 +00:00
Evan Huus 3663498a8b Redesign of the wmem block allocator.
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-27 22:27:28 +00:00
Evan Huus a076d6332e Use a #define, tweak a comment.
svn path=/trunk/; revision=50954
2013-07-27 21:56:43 +00:00
Evan Huus c693d9c951 whitespace
svn path=/trunk/; revision=50919
2013-07-26 16:42:06 +00:00
Evan Huus 037fc022da Add wmem queue 'implementation' by wrapping wmem_list and wmem_stack.
Also a bit of misc. refactoring of the stack while I was there, and doc tweaks.

svn path=/trunk/; revision=50769
2013-07-21 21:13:30 +00:00
Evan Huus 6635f5ef67 Replace wmem slist (singly-linked) with wmem list (doubly-linked).
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
2013-07-20 20:33:38 +00:00
Chris Maynard 1c19a0d61e Fix warnings: format '%blah' expects argument of type 'foo', but argument 'i' has type 'bar' [-Wformat].
svn path=/trunk/; revision=50639
2013-07-15 21:22:34 +00:00
Evan Huus e1268955c7 Add wmem_array_sort() which just hands off to the standard library's qsort().
svn path=/trunk/; revision=50411
2013-07-06 17:47:32 +00:00
Guy Harris 24142c4ee4 In some versions of some OSes, even <string.h> declares index() under
some circumstances.  Use array_index as a variable name instead, to
avoid warnings.

svn path=/trunk/; revision=50404
2013-07-06 08:33:07 +00:00
Evan Huus 777f060f01 Trivial code style: use wmem_new in a few places, and remove extraneous
whitespace.

svn path=/trunk/; revision=50401
2013-07-06 04:08:07 +00:00
Evan Huus c574f7d1ea Simple growable array implementation for wmem.
svn path=/trunk/; revision=50400
2013-07-06 04:02:08 +00:00
Evan Huus 31bd48bce3 *sigh*
From the comment above wmem_tree_insert32_array():
 * If you use ...32_array() calls you MUST make sure that every single node
 * you add to a specific tree always has a key of exactly the same number of
 * keylen words or things will most likely crash. Or at least that every single
 * item that sits behind the same top level node always have exactly the same
 * number of words.

So clearly generating thousands of keys with random lengths while testing is
going to cause problems. Generate a set of random lengths, then use those
lengths consistently (but still generating random keys of those lengths).

Should hopefully fix the intermittent build-bot failures.

(unfortunately this does not manifest nicely, and I cannot see an easy way to
assert it so that we catch other people trying to use different-length key
subtrees)

svn path=/trunk/; revision=50184
2013-06-27 03:44:48 +00:00
Evan Huus ffe6d9c4d6 Misc little cleanups to wmem tree (comments, whitespace, assertions)
svn path=/trunk/; revision=50182
2013-06-27 03:01:53 +00:00
Evan Huus 32f4010527 Remove debugging lines from wmem_test, I think I've figured out the problem.
svn path=/trunk/; revision=50181
2013-06-27 03:00:33 +00:00
Evan Huus a69be407ab Arrays seems to be where the failure is, so remove excess verbiage around other
tests, and add more details to that section.

Now we wait for the buildbots to fail again...

svn path=/trunk/; revision=50156
2013-06-25 22:32:53 +00:00
Chris Maynard ce088c334d makefile.nmake -> Makefile.nmake and minor whitespace (spaces -> tabs) changes.
svn path=/trunk/; revision=50140
2013-06-25 15:32:49 +00:00
Evan Huus 6ebdc45af1 Fix wmem_tree.h ifdef guards, hopefully fixing the check-abi buildbot.
svn path=/trunk/; revision=50132
2013-06-24 22:37:04 +00:00
Evan Huus 29c75dae91 So it comes to this...
Put in a whole bunch of stderr output in the wmem tree tests in the hopes that
the next time one of the buildbots randomly (and irreproducibly) fails on this
step we'll have at least a bit of a hint as to where it happened.

svn path=/trunk/; revision=50131
2013-06-24 21:59:02 +00:00
Evan Huus bfa8d9af75 Make assertions in tree lookup more useful and fix formatting.
Should help debugging https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8833

svn path=/trunk/; revision=50115
2013-06-22 21:00:36 +00:00
Evan Huus 5d53d63cd7 From Michal Labedzki via
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8824

Convert bluetooth emem trees to wmem trees.
Add modelines and fix indentation.
Correct typo in wmem_tree.h that still referred to emem.

svn path=/trunk/; revision=50076
2013-06-20 16:31:53 +00:00
Evan Huus e13d73e038 Rework wmem scoping limits so that users can still get a handle to a pool when
it is out of scope, they just can't *allocate* in the pool. This is necessary
because file-scope trees (migrating from emem) are set up on program
initialization when there is no file in scope - they need to initialize with the
handle, they just won't use it until a file is actually in scope.

svn path=/trunk/; revision=50046
2013-06-19 18:28:13 +00:00
Evan Huus a17358cf3f Add wmem_strbuf_new_label as just a sized new for label lengths.
svn path=/trunk/; revision=50039
2013-06-19 17:34:24 +00:00
Evan Huus f4e5a62325 Clean up wmem_strsplit to remove a bunch of weird switch statements and
unnecessary continue statements. Should fix the coverity issues Joerg pointed
out as well.

svn path=/trunk/; revision=50033
2013-06-19 06:48:08 +00:00
Evan Huus 8ec8f94db7 Resurrect wmem_memdup in its own misc. utilities group. Emem provides it, so we
need to provide an analogue at least for now.

svn path=/trunk/; revision=50018
2013-06-18 21:42:54 +00:00
Evan Huus d487bba75f Add wmem_alloc_array, wmem_strsplit, wmem_strconcat.
svn path=/trunk/; revision=50017
2013-06-18 21:25:37 +00:00
Evan Huus da6d99e2c9 Refactor insert32 to use lookup_or_insert32 with the right flags.
svn path=/trunk/; revision=50013
2013-06-18 19:55:29 +00:00
Evan Huus 4313d778f0 Refactor lookup_or_insert32 to remove a bunch of continue and break statements
as well as a confusing while(TRUE).

svn path=/trunk/; revision=50012
2013-06-18 19:43:18 +00:00
Evan Huus 8610601f60 Simplify node structure. Use a boolean for whether or not it's a subtree, and an
enum for the color (red/black). Don't use bitfields since they don't save us
much (if anything) in terms of space and don't nest the fields in their own
anonymous struct.

svn path=/trunk/; revision=50011
2013-06-18 19:32:40 +00:00
Evan Huus 02752f3161 Factor function for node creation out and use it in several places.
svn path=/trunk/; revision=50010
2013-06-18 19:19:21 +00:00
Evan Huus 881845a555 Scrap wmem_memdup, it's not actually as useful as I thought it would be.
svn path=/trunk/; revision=50009
2013-06-18 19:01:01 +00:00
Evan Huus 115eb9c727 Factor common code for red-black tree array lookups into a helper function and
use it for both direct lookups and less-than-or-equal-to lookups.

svn path=/trunk/; revision=50008
2013-06-18 18:57:28 +00:00
Evan Huus 7fd970ac45 Remove wmem_tree_create_subtree, it does nothing we can't do with
wmem_tree_new.

svn path=/trunk/; revision=50007
2013-06-18 17:48:04 +00:00
Evan Huus d0c1d89cd6 Factor string-packing code into a common function to use in both insert_string
and lookup_string.

svn path=/trunk/; revision=50006
2013-06-18 17:39:15 +00:00
Evan Huus 701fb00afa Add test block for wmem_tree_lookup32_array_le(), fix other tests where certain
random seeds would cause collisions and false failures.

svn path=/trunk/; revision=50004
2013-06-18 06:22:47 +00:00