[SERVER-16096] ResourceId constructors use operator% where they should use operator& for bit masking Created: 11/Nov/14  Updated: 24/Nov/14  Resolved: 14/Nov/14

Status: Closed
Project: Core Server
Component/s: Concurrency
Affects Version/s: 2.8.0-rc0
Fix Version/s: 2.8.0-rc1

Type: Bug Priority: Major - P3
Reporter: Andy Schwerin Assignee: Geert Bosch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

The ResourceId constructors hash a resource name and then compute that value modulo 0x1fffffffffffffffULL. The author almost certainly meant to mask off the high order 3 bits, which is achieved by taking the bitwise and (operator&) rather than the unsigned integer modulus (operator%). Since operator% with this constant requires integer division, it is computationally far more expensive than necessary, but it may not be affecting the correctness of operation.

ResourceId should probably be rewritten entirely in terms of bit masking, instead of a mix of bit masking and narrow bit field structures.



 Comments   
Comment by Githook User [ 14/Nov/14 ]

Author:

{u'username': u'GeertBosch', u'name': u'Geert Bosch', u'email': u'geert@mongodb.com'}

Message: SERVER-16096: Fix UINT64_MAX build issue
Branch: master
https://github.com/mongodb/mongo/commit/9a0cb0d0ba72bc499c1761487422b72904e951a7

Comment by Githook User [ 14/Nov/14 ]

Author:

{u'username': u'GeertBosch', u'name': u'Geert Bosch', u'email': u'geert@mongodb.com'}

Message: SERVER-16096: Use explicit masking in ResourceId instead of union/bitfields

Also pass ResourceId by value instead of by reference and use static const for
_numLockBuckets to avoid division.
Branch: master
https://github.com/mongodb/mongo/commit/78923a5dd969e9b9f46d3fe9bdd969ab0d0a3ca2

Comment by Githook User [ 14/Nov/14 ]

Author:

{u'username': u'GeertBosch', u'name': u'Geert Bosch', u'email': u'geert@mongodb.com'}

Message: SERVER-16096: Add test case for locker perf
Branch: master
https://github.com/mongodb/mongo/commit/3d754a25fb3a14c4ddd47b5257b86e775fb17091

Comment by Geert Bosch [ 12/Nov/14 ]

I just noticed this while making some unrelated changes to the lock manager.
Will fix.

Generated at Thu Feb 08 03:39:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.