1 #include "pages_conserving.h" 2 3 PagesConserving::PagesConserving(Memory *memory) 4 : PageCollection(memory) 5 { 6 _queue = &_page_queue; 7 } 8 9 PagesConserving::PagesConserving() 10 : PageCollection() 11 { 12 _queue = &_page_queue; 13 } 14 15 16 17 /* Refuse to obtain a new flexpage directly. All flexpages must be obtained from 18 the page queue. */ 19 20 Flexpage *PagesConserving::flexpage() 21 { 22 return NULL; 23 } 24 25 26 27 /* Decrease the provision of flexpages to pipes. */ 28 29 bool PagesConserving::decrease(offset_t size) 30 { 31 // NOTE: Need to remove flexpages from the queue. 32 // NOTE: This might need to happen incrementally in case some pages are not 33 // NOTE: back in the queue for whatever reason. 34 35 return true; 36 } 37 38 /* Increase the provision of flexpages to pipes, returning whether allocation 39 succeeded. */ 40 41 bool PagesConserving::increase(offset_t size) 42 { 43 offset_t allocated_size = 0; 44 std::list<Region *> allocated; 45 std::list<Region *>::iterator it; 46 47 /* Allocate regions for the defined increment value. */ 48 49 while (allocated_size < size) 50 { 51 Region *r = _memory->region(); 52 53 /* Free all allocated regions if not all regions can be allocated. */ 54 55 if (r == NULL) 56 { 57 for (it = allocated.begin(); it != allocated.end(); it++) 58 _memory->release(r); 59 60 return false; 61 } 62 63 allocated.push_back(r); 64 allocated_size += r->size(); 65 } 66 67 /* Queue flexpages for the regions. */ 68 69 for (it = allocated.begin(); it != allocated.end(); it++) 70 _queue->push(NULL, new Flexpage(*it)); 71 72 return true; 73 } 74 75 // vim: tabstop=4 expandtab shiftwidth=4