~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/xenpaging/policy_default.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
22
 
 
23
 
 
24
#include "bitops.h"
 
25
#include "xc.h"
 
26
#include "policy.h"
 
27
 
 
28
 
 
29
#define MRU_SIZE 1024
 
30
 
 
31
 
 
32
static unsigned long mru[MRU_SIZE];
 
33
static unsigned int i_mru = 0;
 
34
static unsigned long *bitmap;
 
35
 
 
36
 
 
37
int policy_init(xenpaging_t *paging)
 
38
{
 
39
    int i;
 
40
    int rc;
 
41
 
 
42
    /* Allocate bitmap for pages not to page out */
 
43
    rc = alloc_bitmap(&bitmap, paging->bitmap_size);
 
44
    if ( rc != 0 )
 
45
        goto out;
 
46
 
 
47
    /* Initialise MRU list of paged in pages */
 
48
    for ( i = 0; i < MRU_SIZE; i++ )
 
49
        mru[i] = INVALID_MFN;
 
50
 
 
51
    /* Don't page out page 0 */
 
52
    set_bit(0, bitmap);
 
53
 
 
54
    rc = 0;
 
55
 
 
56
 out:
 
57
    return rc;
 
58
}
 
59
 
 
60
int policy_choose_victim(xenpaging_t *paging, domid_t domain_id,
 
61
                         xenpaging_victim_t *victim)
 
62
{
 
63
    ASSERT(victim != NULL);
 
64
 
 
65
    /* Domain to pick on */
 
66
    victim->domain_id = domain_id;
 
67
    
 
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) );
 
74
 
 
75
    return 0;
 
76
}
 
77
 
 
78
void policy_notify_paged_out(domid_t domain_id, unsigned long gfn)
 
79
{
 
80
    set_bit(gfn, bitmap);
 
81
}
 
82
 
 
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)];
 
86
 
 
87
    if ( old_gfn != INVALID_MFN )
 
88
        clear_bit(old_gfn, bitmap);
 
89
    
 
90
    mru[i_mru & (MRU_SIZE - 1)] = gfn;
 
91
    i_mru++;
 
92
}
 
93
 
 
94
 
 
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
 */