debuggers.hg

view tools/xenpaging/policy_default.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents f87b1c194eb8
children
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 DEFAULT_MRU_SIZE (1024 * 16)
32 static unsigned long *mru;
33 static unsigned int i_mru;
34 static unsigned int mru_size;
35 static unsigned long *bitmap;
36 static unsigned long *unconsumed;
37 static unsigned long current_gfn;
38 static unsigned long bitmap_size;
39 static unsigned long max_pages;
42 int policy_init(xenpaging_t *paging)
43 {
44 int i;
45 int rc;
47 /* Allocate bitmap for pages not to page out */
48 rc = alloc_bitmap(&bitmap, paging->bitmap_size);
49 if ( rc != 0 )
50 goto out;
51 /* Allocate bitmap to track unusable pages */
52 rc = alloc_bitmap(&unconsumed, paging->bitmap_size);
53 if ( rc != 0 )
54 goto out;
56 /* record bitmap_size */
57 bitmap_size = paging->bitmap_size;
58 max_pages = paging->domain_info->max_pages;
60 /* Initialise MRU list of paged in pages */
61 if ( paging->policy_mru_size > 0 )
62 mru_size = paging->policy_mru_size;
63 else
64 mru_size = DEFAULT_MRU_SIZE;
66 mru = malloc(sizeof(*mru) * mru_size);
67 if ( mru == NULL )
68 {
69 rc = -ENOMEM;
70 goto out;
71 }
73 for ( i = 0; i < mru_size; i++ )
74 mru[i] = INVALID_MFN;
76 /* Don't page out page 0 */
77 set_bit(0, bitmap);
79 out:
80 return rc;
81 }
83 int policy_choose_victim(xenpaging_t *paging, xenpaging_victim_t *victim)
84 {
85 xc_interface *xch = paging->xc_handle;
86 unsigned long wrap = current_gfn;
87 ASSERT(victim != NULL);
89 do
90 {
91 current_gfn++;
92 if ( current_gfn >= max_pages )
93 current_gfn = 0;
94 if ( wrap == current_gfn )
95 {
96 victim->gfn = INVALID_MFN;
97 return -ENOSPC;
98 }
99 }
100 while ( test_bit(current_gfn, bitmap) || test_bit(current_gfn, unconsumed) );
102 set_bit(current_gfn, unconsumed);
103 victim->gfn = current_gfn;
105 return 0;
106 }
108 void policy_notify_paged_out(unsigned long gfn)
109 {
110 set_bit(gfn, bitmap);
111 clear_bit(gfn, unconsumed);
112 }
114 void policy_notify_paged_in(unsigned long gfn)
115 {
116 unsigned long old_gfn = mru[i_mru & (mru_size - 1)];
118 if ( old_gfn != INVALID_MFN )
119 clear_bit(old_gfn, bitmap);
121 mru[i_mru & (mru_size - 1)] = gfn;
122 i_mru++;
123 }
126 /*
127 * Local variables:
128 * mode: C
129 * c-set-style: "BSD"
130 * c-basic-offset: 4
131 * tab-width: 4
132 * indent-tabs-mode: nil
133 * End:
134 */