summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/mmap_v1/record_access_tracker.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/storage/mmap_v1/record_access_tracker.h')
-rw-r--r--src/mongo/db/storage/mmap_v1/record_access_tracker.h199
1 files changed, 99 insertions, 100 deletions
diff --git a/src/mongo/db/storage/mmap_v1/record_access_tracker.h b/src/mongo/db/storage/mmap_v1/record_access_tracker.h
index aa98e22230e..a1cb7ab2187 100644
--- a/src/mongo/db/storage/mmap_v1/record_access_tracker.h
+++ b/src/mongo/db/storage/mmap_v1/record_access_tracker.h
@@ -33,127 +33,126 @@
namespace mongo {
- class MmapV1RecordHeader;
+class MmapV1RecordHeader;
+
+/**
+ * Used to implement likelyInPhysicalMemory() for the MMAP v1 storage engine. Since
+ * MMAP v1 holds exclusive collection-level locks, it should yield the locks during a
+ * page fault. The RecordAccessTracker is used to guess at which records are in memory,
+ * so that a yield can be requested unless we're sure that the record has been
+ * recently accessed.
+ */
+class RecordAccessTracker {
+ MONGO_DISALLOW_COPYING(RecordAccessTracker);
+
+public:
+ RecordAccessTracker();
+
+ enum Constants {
+ SliceSize = 1024,
+ MaxChain = 20, // intentionally very low
+ NumSlices = 10,
+ RotateTimeSecs = 90,
+ BigHashSize = 128
+ };
/**
- * Used to implement likelyInPhysicalMemory() for the MMAP v1 storage engine. Since
- * MMAP v1 holds exclusive collection-level locks, it should yield the locks during a
- * page fault. The RecordAccessTracker is used to guess at which records are in memory,
- * so that a yield can be requested unless we're sure that the record has been
- * recently accessed.
+ * Informs this record access tracker that 'record' has been accessed.
*/
- class RecordAccessTracker {
- MONGO_DISALLOW_COPYING(RecordAccessTracker);
- public:
- RecordAccessTracker();
+ void markAccessed(const void* record);
- enum Constants {
- SliceSize = 1024,
- MaxChain = 20, // intentionally very low
- NumSlices = 10,
- RotateTimeSecs = 90,
- BigHashSize = 128
- };
+ /**
+ * @return whether or not 'record' has been marked as accessed recently. A return value
+ * of true means that 'record' is likely in physical memory.
+ *
+ * Also has the side effect of marking 'record' as accessed.
+ */
+ bool checkAccessedAndMark(const void* record);
- /**
- * Informs this record access tracker that 'record' has been accessed.
- */
- void markAccessed(const void* record);
+ /**
+ * Clears out any history of record accesses.
+ */
+ void reset();
- /**
- * @return whether or not 'record' has been marked as accessed recently. A return value
- * of true means that 'record' is likely in physical memory.
- *
- * Also has the side effect of marking 'record' as accessed.
- */
- bool checkAccessedAndMark(const void* record);
+ //
+ // For testing.
+ //
+
+ /**
+ * The accessedRecently() implementation falls back to making a system call if it
+ * appears that the record is not in physical memory. Use this method to disable
+ * the fallback for testing.
+ */
+ void disableSystemBlockInMemCheck();
+
+private:
+ enum State { In, Out, Unk };
+
+ struct Entry {
+ size_t region;
+ unsigned long long value;
+ };
+
+ /**
+ * simple hash map for region -> status
+ * this constitutes a single region of time
+ * it does chaining, but very short chains
+ */
+ class Slice {
+ public:
+ Slice();
- /**
- * Clears out any history of record accesses.
- */
void reset();
- //
- // For testing.
- //
+ State get(int regionHash, size_t region, short offset);
/**
- * The accessedRecently() implementation falls back to making a system call if it
- * appears that the record is not in physical memory. Use this method to disable
- * the fallback for testing.
+ * @return true if added, false if full
*/
- void disableSystemBlockInMemCheck();
+ bool put(int regionHash, size_t region, short offset);
+
+ time_t lastReset() const;
private:
- enum State {
- In, Out, Unk
- };
+ Entry* _get(int start, size_t region, bool add);
+
+ Entry _data[SliceSize];
+ time_t _lastReset;
+ };
- struct Entry {
- size_t region;
- unsigned long long value;
- };
+ /**
+ * this contains many slices of times
+ * the idea you put mem status in the current time slice
+ * and then after a certain period of time, it rolls off so we check again
+ */
+ class Rolling {
+ public:
+ Rolling();
/**
- * simple hash map for region -> status
- * this constitutes a single region of time
- * it does chaining, but very short chains
+ * After this call, we assume the page is in RAM.
+ *
+ * @param doHalf if this is a known good access, want to put in first half.
+ *
+ * @return whether we know the page is in RAM
*/
- class Slice {
- public:
- Slice();
-
- void reset();
-
- State get(int regionHash, size_t region, short offset);
+ bool access(size_t region, short offset, bool doHalf);
- /**
- * @return true if added, false if full
- */
- bool put(int regionHash, size_t region, short offset);
+ private:
+ void _rotate();
- time_t lastReset() const;
+ int _curSlice;
+ long long _lastRotate;
+ Slice _slices[NumSlices];
- private:
- Entry* _get(int start, size_t region, bool add);
+ SimpleMutex _lock;
+ };
- Entry _data[SliceSize];
- time_t _lastReset;
- };
+ // Should this record tracker fallback to making a system call?
+ bool _blockSupported;
- /**
- * this contains many slices of times
- * the idea you put mem status in the current time slice
- * and then after a certain period of time, it rolls off so we check again
- */
- class Rolling {
- public:
- Rolling();
-
- /**
- * After this call, we assume the page is in RAM.
- *
- * @param doHalf if this is a known good access, want to put in first half.
- *
- * @return whether we know the page is in RAM
- */
- bool access(size_t region, short offset, bool doHalf);
-
- private:
- void _rotate();
-
- int _curSlice;
- long long _lastRotate;
- Slice _slices[NumSlices];
-
- SimpleMutex _lock;
- };
-
- // Should this record tracker fallback to making a system call?
- bool _blockSupported;
-
- // An array of Rolling instances for tracking record accesses.
- std::unique_ptr<Rolling[]> _rollingTable;
- };
+ // An array of Rolling instances for tracking record accesses.
+ std::unique_ptr<Rolling[]> _rollingTable;
+};
-} // namespace
+} // namespace