debuggers.hg

view tools/xenpaging/policy_default.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 47ec2d131c22
children 779c0ef9682c
line source
1 /******************************************************************************
2 * tools/xenpaging/policy.c
3 *
4 * Xen domain paging default policy.
5 *
6 * Copyright (c) 2009 Citrix Systems, Inc. (Patrick Colp)
7 *
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.
12 *
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.
17 *
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
21 */
24 #include "bitops.h"
25 #include "xc.h"
26 #include "policy.h"
29 #define MRU_SIZE 1024
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)
38 {
39 int i;
40 int rc;
42 /* Allocate bitmap for pages not to page out */
43 rc = alloc_bitmap(&bitmap, paging->bitmap_size);
44 if ( rc != 0 )
45 goto out;
47 /* Initialise MRU list of paged in pages */
48 for ( i = 0; i < MRU_SIZE; i++ )
49 mru[i] = INVALID_MFN;
51 /* Don't page out page 0 */
52 set_bit(0, bitmap);
54 rc = 0;
56 out:
57 return rc;
58 }
60 int policy_choose_victim(xenpaging_t *paging, domid_t domain_id,
61 xenpaging_victim_t *victim)
62 {
63 ASSERT(victim != NULL);
65 /* Domain to pick on */
66 victim->domain_id = domain_id;
68 do
69 {
70 /* Randomly choose a gfn to evict */
71 victim->gfn = rand() % paging->domain_info->max_pages;
72 }
73 while ( test_bit(victim->gfn, bitmap) );
75 return 0;
76 }
78 void policy_notify_paged_out(domid_t domain_id, unsigned long gfn)
79 {
80 set_bit(gfn, bitmap);
81 }
83 void policy_notify_paged_in(domid_t domain_id, unsigned long gfn)
84 {
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;
91 i_mru++;
92 }
95 /*
96 * Local variables:
97 * mode: C
98 * c-set-style: "BSD"
99 * c-basic-offset: 4
100 * tab-width: 4
101 * indent-tabs-mode: nil
102 * End:
103 */