Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by nitrox on 23.01.19..
- //
- #include "PageDeduplication.h"
- //#include <.h>
- #include <offsets.h>
- #include <mm/PageManager.h>
- #include <kernel/Loader.h>
- //#include <mm/pd.h>
- PageDeduplication* PageDeduplication::instance_ = 0;
- PageDeduplication::PageDeduplication() : Thread(0, "PageDeduplication", Thread::KERNEL_THREAD)
- {
- }
- PageDeduplication* PageDeduplication::instance()
- {
- if (unlikely(!instance_))
- instance_ = new PageDeduplication();
- return instance_;
- }
- void PageDeduplication::Run()
- {
- setState(Running);
- debug(MIRZA, "got here");
- while(true)
- {
- for(size_t ppn = 0; ppn < PageManager::instance()->getTotalNumPages(); ppn++)
- {
- for(size_t it = ppn; it < PageManager::instance()->getTotalNumPages(); it++)
- {
- size_t ppn_new = PageManager::instance()->allocPPN();
- uint64 page = ArchMemory::getIdentAddressOfPPN(ppn_new);
- size_t ppn_new_1 = PageManager::instance()->allocPPN();
- uint64 page_1 = ArchMemory::getIdentAddressOfPPN(ppn_new_1);
- auto check1 = checksum((uint32*)page, PAGE_SIZE);
- auto check2 = checksum((uint32*)page_1, PAGE_SIZE);
- if(check1 == check2)
- {
- if(memcmp((void *)SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second, (void *)SwapThread::getInstance()->ipt_struct_ptr[it].arch_mem_vpage.begin()->second, PAGE_SIZE))
- {
- debug(MIRZA, "FIRST PAGE: [%zd] SECOND PAGE: [%zd]", SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second, SwapThread::getInstance()->ipt_struct_ptr[it].arch_mem_vpage.begin()->second);
- auto amm = SwapThread::getInstance()->ipt_struct_ptr[it].arch_mem_vpage.begin()->first->resolveMapping(SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second);
- for(auto it = SwapThread::getInstance()->ipt_struct_ptr[amm.pt[amm.pti].page_ppn].arch_mem_vpage.begin(); it !=SwapThread::getInstance()->ipt_struct_ptr[amm.pt[amm.pti].page_ppn].arch_mem_vpage.end(); it++)
- {
- if(it->first == &(currentThread->loader_->arch_memory_) && it->second == SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second)
- {
- SwapThread::getInstance()->ipt_struct_ptr[amm.pt[amm.pti].page_ppn].arch_mem_vpage.erase(it);
- return;
- }
- }
- debug(MIRZA, "REMOVE PAGE: %zd", SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second);
- //SwapThread::getInstance()->removeCowMapping(amm.pt[amm.pti].page_ppn, &(currentThread->loader_->arch_memory_), SwapManager::instance()->inverted_page_table_[ppn].proc_v_pages_.begin()->second);
- }
- }
- }
- }
- }
- }
- bool PageDeduplication::deduplicate(size_t ppn_2, size_t v_page)
- {
- for(size_t ppn = 0; ppn < PageManager::instance()->getTotalNumPages(); ppn++)
- {
- size_t page = ArchMemory::getIdentAddressOfPPN(ppn_2);
- if(SwapThread::getInstance()->ipt_struct_ptr[ppn].checksuma == checksum((uint32 *)page, PAGE_SIZE))
- {
- if(memcmp((void *)SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second, (void *) v_page, PAGE_SIZE))
- {
- return false;
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement