ia64/xen-unstable

changeset 17258:c40a5ae3e18b

save/restore: Permute saved memory with 2MB chunk size.

The memory permutation cause a slow down in case of a save/restore
(bug 1143). It works better when the mixing is done with 2MB chunks.

Signed-off-by: Jean Guyader <jean.guyader@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 18 19:36:43 2008 +0000 (2008-03-18)
parents df89656a4b94
children eee1bbb0e9f5
files tools/libxc/xc_domain_save.c
line diff
     1.1 --- a/tools/libxc/xc_domain_save.c	Tue Mar 18 19:28:09 2008 +0000
     1.2 +++ b/tools/libxc/xc_domain_save.c	Tue Mar 18 19:36:43 2008 +0000
     1.3 @@ -125,34 +125,22 @@ static inline int count_bits ( int nr, v
     1.4      return count;
     1.5  }
     1.6  
     1.7 -static inline int permute( int i, int nr, int order_nr  )
     1.8 +static inline int permute(unsigned long i, unsigned long order_nr)
     1.9  {
    1.10      /* Need a simple permutation function so that we scan pages in a
    1.11         pseudo random order, enabling us to get a better estimate of
    1.12         the domain's page dirtying rate as we go (there are often
    1.13         contiguous ranges of pfns that have similar behaviour, and we
    1.14         want to mix them up. */
    1.15 -
    1.16 -    /* e.g. nr->oder 15->4 16->4 17->5 */
    1.17 -    /* 512MB domain, 128k pages, order 17 */
    1.18 -
    1.19 -    /*
    1.20 -      QPONMLKJIHGFEDCBA
    1.21 -             QPONMLKJIH
    1.22 -      GFEDCBA
    1.23 -     */
    1.24 +  
    1.25 +  unsigned char keep = 9; /* chunk of 2 MB */
    1.26 +  unsigned char shift_low = (order_nr - keep) / 2 + ((order_nr - keep) / 2) % 2;
    1.27 +  unsigned char shift_high = order_nr - keep - shift_low;
    1.28  
    1.29 -    /*
    1.30 -      QPONMLKJIHGFEDCBA
    1.31 -                  EDCBA
    1.32 -             QPONM
    1.33 -      LKJIHGF
    1.34 -      */
    1.35 +  unsigned long high = (i >> (keep + shift_low));
    1.36 +  unsigned long low = (i >> keep) & ((1 << shift_low) - 1);
    1.37  
    1.38 -    do { i = ((i>>(order_nr-10)) | ( i<<10 ) ) & ((1<<order_nr)-1); }
    1.39 -    while ( i >= nr ); /* this won't ever loop if nr is a power of 2 */
    1.40 -
    1.41 -    return i;
    1.42 +  return (i & ((1 << keep) - 1)) | (low << (shift_high + keep)) | (high << keep);
    1.43  }
    1.44  
    1.45  static uint64_t tv_to_us(struct timeval *new)
    1.46 @@ -1126,7 +1114,7 @@ int xc_domain_save(int xc_handle, int io
    1.47                     (batch < MAX_BATCH_SIZE) && (N < p2m_size);
    1.48                     N++ )
    1.49              {
    1.50 -                int n = permute(N, p2m_size, order_nr);
    1.51 +                int n = permute(N, order_nr);
    1.52  
    1.53                  if ( debug )
    1.54                  {