Performance improvements to key comparison functions
If you downloaded the code at http://dabbs.net/reiser4 I have uploaded a new zip file. I posted an incorrect version when I uploaded it in the wee hours this morning.
David
Quoted 4 lines · David Dabbs
If you downloaded the code at http://dabbs.net/reiser4 I have uploaded a new zip file. I posted an incorrect version when I uploaded it in the wee hours this morning.
----------------------------------------------------------------------
static inline cmp_t_new
keycmp_new( const reiser4_key * k1 /* first key to compare */ , const reiser4_key * k2 /* second key to compare */ ) {
__u64 v1, v2;
if ((v1=get_key_el(k1,0)) != (v2=get_key_el(k2,0)))
return (v1 > v2);
if ((v1=get_key_el(k1,1)) != (v2=get_key_el(k2,1)))
return (v1 > v2);
if ((v1=get_key_el(k1,2)) != (v2=get_key_el(k2,2)))
return (v1 > v2);
if ((v1=get_key_el(k1,3)) != (v2=get_key_el(k2,3)))
return (v1 > v2); return EQUAL_TO_NEW;
}
----------------------------------------------------------------------
Note that comparisons in C (like (v1 > v2)) are not guaranteed to return 0 or _1_ as a result, but simply zero, or _non-zero_.
Standard trick to "normalize" comparison result is to do
return !!(v1 > v2));
etc. In the same vein, "isunique" argument of znode_contains_key_strict_new() is not guaranteed to be 0 or 1, which renders this function wrong.
That said, I think that proper way to test your functions is to plug them into kernel reiser4 version and run some CPU intensive tests.
Quoted 4 lines
David
Good luck,
Nikita.
Quoted 1 line
Thanks for looking over the code and for your responses.
Quoted 3 lines
Nikita wrote
Note that comparisons in C (like (v1 > v2)) are not guaranteed to return 0 or _1_ as a result, but simply zero, or _non-zero_.
Is the information here (http://www.lysator.liu.se/c/c-faq/c-8.html)
incorrect then? Specifically,
---8< snip
It is true (sic) that any nonzero value is considered true in C, but this applies only "on input", i.e. where a boolean value is expected. When a boolean value is generated by a built-in operator, it is guaranteed to be 1 or 0. Therefore, the test
if((a == b) == TRUE)
will work as expected (as long as TRUE is 1), but it is obviously silly. In general, explicit tests against TRUE and FALSE are undesirable, because some library functions (notably isupper, isalpha, etc.) return, on success, a nonzero value which is not necessarily 1. (Besides, if you believe that "if((a == b) == TRUE)" is an improvement over "if(a == b)", why stop there? Why not use "if(((a == b) == TRUE) == TRUE)"?) A good rule of thumb is to use TRUE and FALSE (or the like) only for assignment to a Boolean variable or function parameter, or as the return value from a Boolean function, but never in a comparison.
The preprocessor macros TRUE and FALSE are used for code readability, not because the underlying values might ever change. (See also questions 1.7 and 1.9.)
References: K&R I Sec. 2.7 p. 41; K&R II Sec. 2.6 p. 42, Sec. A7.4.7 p. 204, Sec. A7.9 p. 206; ANSI Secs. 3.3.3.3, 3.3.8, 3.3.9, 3.3.13, 3.3.14, 3.3.15, 3.6.4.1, 3.6.5; Achilles and the Tortoise.
---8< snip
Quoted 5 lines
In the same vein, "isunique" argument of
znode_contains_key_strict_new()is not guaranteed to be 0 or 1 which renders this function wrong.
That said, I think that proper way to test your functions is to plug them into kernel reiser4 version and run some CPU intensive tests.
I thought I noted in "System Impacts" that when isunique is initialized by ORing the flag that the initialization expression must change to be a Boolean result of the OR test. Something like
isunique = ((h->flags & CBK_UNIQUE) == CBK_UNIQUE);
That may have not made it in.
As to testing in the kernel, I completely agree. Before going there I thought I'd get community feedback to see whether there was something subtle I had missed.
Thanks again,
David
Quoted 11 lines · David Dabbs
Thanks for looking over the code and for your responses.
Quoted 3 lines
Nikita wrote
Note that comparisons in C (like (v1 > v2)) are not guaranteed to return 0 or _1_ as a result, but simply zero, or _non-zero_.Is the information here (http://www.lysator.liu.se/c/c-faq/c-8.html)
incorrect then? Specifically,---8< snip
Arrggh, I shouldn't post that late in night :)
ISO C 6.5.8 Relational operators
[#6] Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.80) The result has type int.
Of course you are right.
Nikita.
Quoted 8 lines
Nikita Danilov wrote
Arrggh, I shouldn't post that late in night :)
ISO C 6.5.8 Relational operators
Quoted 8 lines
[#6] Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.80) The result has type int.
Of course you are right.
Nikita.
I'm curious about testing znode->version before and then after the call to znode_contains_strict (when it returns true). Is there a reason this is not done e.g. extra call to znode_contains is a small price to pay vs. speculative, protected read of each cached node's version member?
David
Quoted 13 lines · David Dabbs
Quoted 13 lines
Nikita Danilov wrote
Arrggh, I shouldn't post that late in night :)
ISO C 6.5.8 Relational operators
[#6] Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.80) The result has type int.
Quoted 8 lines
Quoted 3 lines
Of course you are right.
Nikita.
I'm curious about testing
znode->versionbefore and then after the call toznode_contains_strict(when it returns true). Is there a reason this is not done e.g. extra call toznode_containsis a small price to pay vs. speculative, protected read of each cached node's version member?
I don't quite follow, can you elaborate? What znode_contains_strict()'s call site are you talking about?
Quoted 2 lines
David
Nikita.
Quoted 6 lines
I'm curious about testing
znode->versionbefore and then after the call toQuoted 1 line
znode_contains_strict(when it returns true). Is there a reason this is
Quoted 8 lines
not
Quoted 2 lines
done e.g. extra call to
znode_containsis a small price to pay vs. speculative, protected read of each cached node's version member?I don't quite follow, can you elaborate? What znode_contains_strict()'s call site are you talking about?
Nikita.
[David Dabbs]
The function that scans cached znodes before embarking on a full tree search is the site I had in mind. It locks the cache, then calls znode_contains_key_strict if the h->level == cached_node->level (or something similar). All search key/cached node comparisons are done without locking each cached node. If a cached node is found, the code then locks the node, rechecks znode->level, recalls znode_contains_key_strict and, I think, checks for ZNODE_HEARD_BANSHEE, etc.
Assuming the search key is an invariant, it seems as though one could grab a copy of cached_node->version _before_ calling znode_contains. If z_c_k_s finds a match and the version member is unchanged, then one need not recall z_c_k_s. If it is different, then recheck z_c_k_s as is done now.
David
Quoted 25 lines · David Dabbs
Quoted 6 lines
I'm curious about testing
znode->versionbefore and then after the call toQuoted 1 line
znode_contains_strict(when it returns true). Is there a reason this isQuoted 8 lines
not
Quoted 2 lines
done e.g. extra call to
znode_containsis a small price to pay vs. speculative, protected read of each cached node's version member?I don't quite follow, can you elaborate? What znode_contains_strict()'s call site are you talking about?
Nikita.
[David Dabbs]
The function that scans cached znodes before embarking on a full tree search is the site I had in mind. It locks the cache, then calls
znode_contains_key_strictif theh->level==cached_node->level(or something similar). All search key/cached node comparisons are done without locking each cached node. If a cached node is found, the code then locks the node, rechecksznode->level, recallsznode_contains_key_strictand, I think, checks forZNODE_HEARD_BANSHEE, etc.
Quoted 4 lines
Assuming the search key is an invariant, it seems as though one could grab a copy of
cached_node->version_before_ callingznode_contains. Ifz_c_k_sfinds a match and the version member is unchanged, then one need not recallz_c_k_s. If it is different, then recheckz_c_k_sas is done now.
I see now. Problem is that znode->version is protected by long-term lock itself. That is, invariant
"znode content change implies znode->version bump"
is maintained under long-term lock on znode. In particular, following sequence of actions is valid:
(1) obtain long term lock on znode Z
(2) modify Z's content
(3) bump Z->version
(4) modify Z's content again
(5) release long-term lock (without increasing Z->version for the second time)
If first call to z_c_k_s() happens between (3) and (4), re-checking ->version is not enough.
Quoted 2 lines
David
Nikita.
Quoted 16 lines
Nikita wrote
I see now. Problem is that
znode->versionis protected by long-term lock itself. That is, invariant"znode content change implies znode->version bump"is maintained under long-term lock on znode. In particular, following sequence of actions is valid:
(1) obtain long term lock on znode Z
(2) modify Z's content
(3) bump
Z->version
Quoted 8 lines
(4) modify Z's content again
(5) release long-term lock (without increasing
Z->versionfor the second time)If first call to
z_c_k_s()happens between (3) and (4), re-checking ->version is not enough.
[David Dabbs]
Thanks. I figured there was a concurrency issue.
Another question. Is it an invariant that all key values, whether persisted to disk or in-memory only, are stored in little-endian order? Specifically I'm thinking of key values used when searching the (a) tree. Seems like they must be, as the key comparison functions call d64tocpu() when operating on all key parameters.
If this is the case, one can test for equivalence using each datum (on both big- and little-endian machines) and only call __swab64 (d64tocpu) when one needs to evaluate the difference between two architecture-native values. Something like
if(k1->el[0].datum != k1->el[0].datum) return (d64tocpu(k1, 0) < (d64tocpu(k2, 0);
Bits are bits, right - at least when testing equivalence? This would have no effect on little-endian architectures, but for big-endian shouldn't this 'deferred swabbing' improve things?
David
Quoted 5 lines
Nikita Danilov wrote
That said, I think that proper way to test your functions is to plug them into kernel reiser4 version and run some CPU intensive tests.
Is bonnie++ the recommended stress tool, or is there a reiser4 stress utility?
David
Quoted 9 lines · David Dabbs
Quoted 5 lines
Nikita Danilov wrote
That said, I think that proper way to test your functions is to plug them into kernel reiser4 version and run some CPU intensive tests.Is bonnie++ the recommended stress tool, or is there a reiser4 stress utility?
Standard Namesys benchmarking utility is "mongo"
(http://www.namesys.com/benchmarks/mongo_readme.html).
Quoted 2 lines
David
Nikita.
T�rnqvist
Quoted 3 lines · David Dabbs
Is bonnie++ the recommended stress tool, or is there a reiser4 stress utility?
bonnie++ and slow.c are what one usually sees flying around.
fs stress or somesuch is also sometimes used, but it supposedly fragments Reiser4 quite a bit and afaik there's no way to defrag yet? Or does fsck do it, as I've gathered that some other variants do?
Anyway, if someone has something more cpu-intensive than bonnie++ to offer, I'd also like to know about it, as bonnie++ uses a fair share of cpu on my machine.
Signature · 1 line
mjt
Quoted 10 lines · Markus Törnqvist
Quoted 4 lines · David Dabbs
Is bonnie++ the recommended stress tool, or is there a reiser4 stress utility?
bonnie++ and
slow.care what one usually sees flying around.
Quoted 10 lines
fs stress or somesuch is also sometimes used, but it supposedly fragments Reiser4 quite a bit and afaik there's no way to defrag yet? Or does fsck do it, as I've gathered that some other variants do?
Anyway, if someone has something more cpu-intensive than bonnie++ to offer, I'd also like to know about it, as bonnie++ uses a fair share of cpu on my machine.
If bonnie++ is sync bound, then it it completely inappropriate for reiser4 testing.
Hello david,
I know Namesys uses at least mongo.pl (http://www.namesys.com/benchmarks/mongo.tar.gz)
and slow.c ( http://www.jburgess.uklinux.net/slow.c )
See: http://www.namesys.com/benchmarks.html
Thanks,
Philippe
On Mon, 12 Jul 2004 15:49:25 -0500
"David Dabbs" <[email protected]> wrote:
| | | > Nikita Danilov wrote | > That said, I think that proper way to test your functions is to plug | > them into kernel reiser4 version and run some CPU intensive tests. | | Is bonnie++ the recommended stress tool, or is there a reiser4 stress | utility? | | | David | | |