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