SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Created by nitrox on 23.01.19..
  3. //
  4.  
  5. #include "PageDeduplication.h"
  6. //#include <.h>
  7. #include <offsets.h>
  8. #include <mm/PageManager.h>
  9. #include <kernel/Loader.h>
  10. //#include <mm/pd.h>
  11.  
  12. PageDeduplication* PageDeduplication::instance_ = 0;
  13.  
  14. PageDeduplication::PageDeduplication() : Thread(0, "PageDeduplication", Thread::KERNEL_THREAD)
  15. {
  16.  
  17. }
  18.  
  19. PageDeduplication* PageDeduplication::instance()
  20. {
  21.   if (unlikely(!instance_))
  22.     instance_ = new PageDeduplication();
  23.   return instance_;
  24. }
  25.  
  26. void PageDeduplication::Run()
  27. {
  28.   setState(Running);
  29.   debug(MIRZA, "got here");
  30.   while(true)
  31.   {
  32.     for(size_t ppn = 0;  ppn < PageManager::instance()->getTotalNumPages(); ppn++)
  33.     {
  34.       for(size_t it = ppn; it <  PageManager::instance()->getTotalNumPages(); it++)
  35.       {
  36.         size_t ppn_new = PageManager::instance()->allocPPN();
  37.         uint64 page = ArchMemory::getIdentAddressOfPPN(ppn_new);
  38.  
  39.         size_t ppn_new_1 = PageManager::instance()->allocPPN();
  40.         uint64 page_1 = ArchMemory::getIdentAddressOfPPN(ppn_new_1);
  41.  
  42.         auto check1 = checksum((uint32*)page, PAGE_SIZE);
  43.         auto check2 = checksum((uint32*)page_1, PAGE_SIZE);
  44.  
  45.         if(check1 == check2)
  46.         {
  47.           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))
  48.           {
  49.             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);
  50.             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);
  51.  
  52.             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++)
  53.             {
  54.               if(it->first == &(currentThread->loader_->arch_memory_) && it->second == SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second)
  55.               {
  56.                 SwapThread::getInstance()->ipt_struct_ptr[amm.pt[amm.pti].page_ppn].arch_mem_vpage.erase(it);
  57.                 return;
  58.               }
  59.             }
  60.             debug(MIRZA, "REMOVE PAGE: %zd", SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second);
  61.             //SwapThread::getInstance()->removeCowMapping(amm.pt[amm.pti].page_ppn, &(currentThread->loader_->arch_memory_), SwapManager::instance()->inverted_page_table_[ppn].proc_v_pages_.begin()->second);
  62.  
  63.           }
  64.         }
  65.       }
  66.     }
  67.   }
  68. }
  69.  
  70.  
  71. bool PageDeduplication::deduplicate(size_t ppn_2, size_t v_page)
  72. {
  73.   for(size_t ppn = 0;  ppn < PageManager::instance()->getTotalNumPages(); ppn++)
  74.   {
  75.     size_t page = ArchMemory::getIdentAddressOfPPN(ppn_2);
  76.     if(SwapThread::getInstance()->ipt_struct_ptr[ppn].checksuma == checksum((uint32 *)page, PAGE_SIZE))
  77.     {
  78.       if(memcmp((void *)SwapThread::getInstance()->ipt_struct_ptr[ppn].arch_mem_vpage.begin()->second, (void *) v_page, PAGE_SIZE))
  79.       {
  80.         return false;
  81.       }
  82.     }
  83.  
  84.   }
  85.   return  true;
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top