1 #include "pages_conserving.h" 2 3 PagesConserving::PagesConserving(Memory *memory) 4 : Pages(memory) 5 { 6 } 7 8 PagesConserving::PagesConserving() 9 : Pages() 10 { 11 } 12 13 14 15 /* Refuse to obtain a new flexpage directly. All flexpages must be obtained from 16 the page queue. */ 17 18 Flexpage *PagesConserving::flexpage() 19 { 20 return NULL; 21 } 22 23 /* Pretend to queue an entry associating the given 'owner' and 'flexpage'. 24 Since this collection "conserves" flexpages, they will not be queued unless 25 completely unused. */ 26 27 void PagesConserving::queue(PageOwner *owner, Flexpage *flexpage) 28 { 29 (void) owner; (void) flexpage; 30 } 31 32 /* Pretend to reserve a flexpage already being used by 'owner' and 'flexpage'. 33 Since flexpages are not queued when in use, there is nothing to reserve. */ 34 35 bool PagesConserving::reserve(PageOwner *owner, Flexpage *flexpage) 36 { 37 (void) owner; (void) flexpage; 38 return true; 39 } 40 41 42 43 /* Decrease the provision of flexpages to pipes. */ 44 45 bool PagesConserving::decrease(offset_t size) 46 { 47 // NOTE: Need to remove flexpages from the queue. 48 // NOTE: This might need to happen incrementally in case some pages are not 49 // NOTE: back in the queue for whatever reason. 50 51 return true; 52 } 53 54 /* Increase the provision of flexpages to pipes, returning whether allocation 55 succeeded. */ 56 57 bool PagesConserving::increase(offset_t size) 58 { 59 offset_t allocated_size = 0; 60 std::list<Region *> allocated; 61 std::list<Region *>::iterator it; 62 63 /* Allocate regions for the defined increment value. */ 64 65 while (allocated_size < size) 66 { 67 Region *r = _memory->region(); 68 69 /* Free all allocated regions if not all regions can be allocated. */ 70 71 if (r == NULL) 72 { 73 for (it = allocated.begin(); it != allocated.end(); it++) 74 _memory->release(r); 75 76 return false; 77 } 78 79 allocated.push_back(r); 80 allocated_size += r->size(); 81 } 82 83 /* Queue flexpages for the regions. */ 84 85 for (it = allocated.begin(); it != allocated.end(); it++) 86 _queue.push(NULL, new Flexpage(*it)); 87 88 return true; 89 } 90 91 // vim: tabstop=4 expandtab shiftwidth=4