1
/******************************************************************************
2
* tools/xenpaging/policy.c
4
* Xen domain paging default policy.
6
* Copyright (c) 2009 Citrix Systems, Inc. (Patrick Colp)
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
static unsigned long mru[MRU_SIZE];
33
static unsigned int i_mru = 0;
34
static unsigned long *bitmap;
37
int policy_init(xenpaging_t *paging)
42
/* Allocate bitmap for pages not to page out */
43
rc = alloc_bitmap(&bitmap, paging->bitmap_size);
47
/* Initialise MRU list of paged in pages */
48
for ( i = 0; i < MRU_SIZE; i++ )
51
/* Don't page out page 0 */
60
int policy_choose_victim(xenpaging_t *paging, domid_t domain_id,
61
xenpaging_victim_t *victim)
63
ASSERT(victim != NULL);
65
/* Domain to pick on */
66
victim->domain_id = domain_id;
70
/* Randomly choose a gfn to evict */
71
victim->gfn = rand() % paging->domain_info->max_pages;
73
while ( test_bit(victim->gfn, bitmap) );
78
void policy_notify_paged_out(domid_t domain_id, unsigned long gfn)
83
void policy_notify_paged_in(domid_t domain_id, unsigned long gfn)
85
unsigned long old_gfn = mru[i_mru & (MRU_SIZE - 1)];
87
if ( old_gfn != INVALID_MFN )
88
clear_bit(old_gfn, bitmap);
90
mru[i_mru & (MRU_SIZE - 1)] = gfn;
101
* indent-tabs-mode: nil