SwatDB
Loading...
Searching...
No Matches
bm_policies.h
Go to the documentation of this file.
1/*
2 * SwatDB
3 *
4 * @authors: See Contributors.doc for code contributors
5 *
6 * Copyright (c) 2020, 2024 Swarthmore College Computer Science Department
7 * Swarthmore PA, Professors Tia Newhall, Ameet Soni
8 */
9
10// @@@@ SWATDB_ASSIGNMENT: ADDTODODATE
11
12#ifndef _SWATDB_BM_POLICIES_H_
13#define _SWATDB_BM_POLICIES_H_
14
20#include <utility>
21#include <list>
22#include <queue>
23
24#include "swatdb_types.h"
25#include "bm_replacement.h" // base class def
26
27
37class Clock: public ReplacementPolicy {
38
39
40 public:
41
42
58
63
86
87
100 void pin(FrameId frame_id);
101
112 void unpin(FrameId frame_id);
113
114
125
126
139 void freeFrame(FrameId frame_id);
140
141
146 void printFrame(FrameId frame_id);
147
148
154
155
156 private:
157
158
163 std::uint32_t clock_hand;
164
165
171
172
181
182
191
192
193};
194
195
204
205
206 public:
207
208
224
229
230
253
254
267 void pin(FrameId frame_id);
268
280 void unpin(FrameId frame_id);
281
282
288
289
290 private:
291
292
300
301
307
308
309};
310
311
320class MRU: public ReplacementPolicy {
321
322
323 public:
324
325
340
345
366
367
378 void pin(FrameId frame_id);
379
380
391 void unpin(FrameId frame_id);
392
393
405 void freeFrame(FrameId frame_id);
406
412
413
414 private:
415
416
420 std::list<FrameId> stack;
421
422
431
432
438
439};
440
441
442
451class LRU: public ReplacementPolicy {
452
453
454 public:
455
456
472
477
498
499
510 void pin(FrameId frame_id);
511
512
523 void unpin(FrameId frame_id);
524
525
537 void freeFrame(FrameId frame_id);
538
539
545
546
547 private:
548
549
553 std::list<FrameId> queue;
554
555
563
564
570
571};
572
573
574// @@@@ SWATDB_ASSIGNMENT: CUT_START
575#ifndef BUFMGR_LAB_SOL_OMIT
576
586
587
588 public:
589
590
605
610
632
633
646 void pin(FrameId frame_id);
647
659 void unpin(FrameId frame_id);
660
661
667
668
669 private:
670
671
679
680
686
687
688};
689// endif for ifndef BUFMGR_LAB_SOL_OMIT
690#endif
691// @@@@ SWATDB_ASSIGNMENT: CUT_END
692
693
694// endif gaurd for .h file
695#endif
Definition bm_policies.h:585
void pin(FrameId frame_id)
Frame is being pinned with pin count going from 0 to 1. Clock Random policy has nothing to do here,...
RepType _getType()
Derived class from pure virtual function that returns replacement policy type specific to this derive...
int times_chosen[BUF_SIZE]
Definition bm_policies.h:685
void printStats()
Prints average frames checked, replacement calls, summary stats on randomness.
FrameId replace()
Method that implements the Clock Random replacement policy functionality.
void unpin(FrameId frame_id)
Frame is being unpinned with pin count going from 1 to 0. Clock Random policy has nothing to do here,...
ClockRandom(Frame *frame_table)
Clock Random constructor. Initializes pointer to buffer manager's frame_table, creates the free list,...
Definition bm_policies.h:37
void getRepStats(struct BufferState::ReplacementStats *rep_stats)
Updates the struct of replacement policy statistics within the buffer state struct....
bool ref_table[BUF_SIZE]
Definition bm_policies.h:170
void freeFrame(FrameId frame_id)
The frame is invalidated in the buffer manager, and is added to the free list of frames in the replac...
void unpin(FrameId frame_id)
Frame is being unpinned with pin count going from 1 to 0. Set the ref_bit associated with this frame_...
FrameId replace()
Method that implements core replacement policy functionality of the clock replacement policy.
RepType _getType()
Derived class from pure virtual function that returns replacement policy type specific to this derive...
void _advanceClock()
Increments the clock hand according to the clock replacement policy.
void pin(FrameId frame_id)
Frame is being pinned with pin count going from 0 to 1. Clock policy has nothing to do here,...
Clock(Frame *frame_table)
Clock constructor. Initializes pointer to buffer manager's frame_table, creates the free list,...
void printStats()
Prints clock_hand, average frames checked, replacement calls, how many frames have ref_bit set.
void printFrame(FrameId frame_id)
THIS METHOD IS FOR DEBUGGING ONLY. Prints Frame state, including pin count and ref_bit.
std::uint32_t clock_hand
Definition bm_policies.h:163
Definition bm_frame.h:28
Definition bm_policies.h:451
void printStats()
Prints replacement calls, average frames checked when pinning, and max and average size of queue.
LRU(Frame *frame_table)
LRU constructor. Initializes pointer to buffer manager's frame_table, creates the free list,...
void pin(FrameId frame_id)
Frame is being pinned with pin count going from 0 to 1. Frame id is removed from queue.
void unpin(FrameId frame_id)
Frame is being unpinned with pin count going from 1 to 0. Frame id is added to the bottom of the queu...
FrameId replace()
Method that implements the Least Recently Used (LRU) replacement policy functionality.
std::list< FrameId > queue
Definition bm_policies.h:553
int remove_calls
Definition bm_policies.h:569
void freeFrame(FrameId frame_id)
The frame is invalidated in the buffer manager, and is added to the free list of frames in the replac...
~LRU()
RepType _getType()
Derived class from pure virtual function that returns replacement policy type specific to this derive...
Definition bm_policies.h:320
RepType _getType()
Derived class from pure virtual function that returns replacement policy type specific to this derive...
void printStats()
Prints replacement calls, average frames checked when pinning, and max and average size of stack.
MRU(Frame *frame_table)
MRU constructor. Initializes pointer to buffer manager's frame_table, creates the free list,...
std::list< FrameId > stack
Definition bm_policies.h:420
void freeFrame(FrameId frame_id)
The frame is invalidated in the buffer manager, and is added to the free list of frames in the replac...
void pin(FrameId frame_id)
Frame is being pinned with pin count going from 0 to 1. Frame id is removed from stack.
void unpin(FrameId frame_id)
Frame is being unpinned with pin count going from 1 to 0. Frame id is added to the top of the stack.
int remove_calls
Definition bm_policies.h:437
~MRU()
FrameId replace()
Method that implements the Most Recently Used (MRU) replacement policy functionality.
Definition bm_policies.h:203
void unpin(FrameId frame_id)
Frame is being unpinned with pin count going from 1 to 0. Random policy has nothing to do here,...
int times_chosen[BUF_SIZE]
Definition bm_policies.h:306
void pin(FrameId frame_id)
Frame is being pinned with pin count going from 0 to 1. Random policy has nothing to do here,...
Random(Frame *frame_table)
Random constructor. Initializes pointer to buffer manager's frame_table, creates the free list,...
FrameId replace()
Method that implements the Random replacement policy functionality.
void printStats()
Prints average frames checked, replacement calls, summary stats on randomness.
RepType _getType()
Derived class from pure virtual function that returns replacement policy type specific to this derive...
Definition bm_replacement.h:29
Frame * frame_table
Definition bm_replacement.h:156
Definition bufmgr.h:78
std::uint32_t FrameId
Index of each frame in the bufferpool of BufferManager.
Definition swatdb_types.h:44
const std::uint32_t BUF_SIZE
Definition swatdb_types.h:292
RepType
Definition swatdb_types.h:167