Replies: 2 comments
-
bustub/src/buffer/buffer_pool_manager_instance.cpp Lines 59 to 66 in 783f191 In the image below, If there aren't any empty pages available, you use your replacement policy to decide which No disk I/O happens at this point, this is all purely in-memory
A page becomes When you "sync" (flush) changes from the pages to disk, the When a new page is allocated in memory, it can't be dirty, or referenced yet 👍 |
Beta Was this translation helpful? Give feedback.
-
Something that also helped me a lot (depending on your familiarity with programming) was the tip to just think of the If you're familiar with Java, Guava's class BufferPoolManager {
private static final int POOL_SIZE = 100;
private final DiskManager diskManager;
// LRU cache that holds POOL_SIZE pages
//
// When a new page is requested, if it exists in the cache, it is returned
// Otherwise it is loaded from the DiskManager and added to the cache
// If the cache is full, the least-recently-used page is evicted
private final LoadingCache<PageId, Page> bufferPoolCache = CacheBuilder.newBuilder()
.maximumSize(POOL_SIZE) // LRU eviction happens after reaching this size
.build(new CacheLoader<>() {
@Override
public Page load(PageId pageId) throws Exception {
byte[] pageBuffer = new byte[4096];
diskManager.readPage(pageId.value(), pageBuffer);
return Page.fromBytes(pageBuffer);
}
});
public BufferPoolCache(DiskManager diskManager) {
this.diskManager = diskManager;
}
public Page getPage(PageId pageId) {
return bufferPoolCache.get(pageId);
}
} |
Beta Was this translation helpful? Give feedback.
-
I am confused about the newpgImp function, when i called this function, it means that the buffermanager create a new page in disk or memory? If it is created in memory, do you need to set this isdirty variable to true or just write the page back to the disk?
Beta Was this translation helpful? Give feedback.
All reactions