Changeset 78

Show
Ignore:
Timestamp:
06/08/05 00:09:39 (4 years ago)
Author:
jtv
Message:

Bugfix: PAGE_MASK may be too small for memsize_t!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/memory.c

    r77 r78  
    8585  return true; 
    8686} 
     87 
    8788 
    8889struct meminfo_item 
  • src/memory.h

    r77 r78  
    2727#define MEMSIZE_ERROR LLONG_MIN 
    2828 
     29/// Round (through truncation) a size (in bytes) to multiple of page size 
     30#define TRUNC_TO_PAGE(n) (((memsize_t)n) & ~((memsize_t)PAGE_SIZE-1)) 
     31 
     32 
    2933/// Check if we can access memory status etc.  Clobbers localbuf. 
    3034bool check_memory_status(void); 
  • src/swaps.c

    r77 r78  
    6161 
    6262/// Smallest allowed swapfile size 
    63 static memsize_t min_swapsize = (12*PAGE_SIZE) & PAGE_MASK
     63static memsize_t min_swapsize = TRUNC_TO_PAGE(12*PAGE_SIZE)
    6464/// Largest allowed swapfile size 
    6565/** Don't set this too low.  The program will learn if it runs into file size 
    6666 * limits. 
    6767 */ 
    68 static memsize_t max_swapsize = TERA & PAGE_MASK
     68static memsize_t max_swapsize = TRUNC_TO_PAGE(TERA)
    6969 
    7070 
     
    100100char *set_min_swapsize(long long size) 
    101101{ 
    102   min_swapsize = ((memsize_t)size & PAGE_MASK); 
     102  min_swapsize = TRUNC_TO_PAGE(size); 
    103103  return NULL; 
    104104} 
     
    106106char *set_max_swapsize(long long size) 
    107107{ 
    108   max_swapsize = ((memsize_t)size) & PAGE_MASK
     108  max_swapsize = TRUNC_TO_PAGE(size)
    109109  return NULL; 
    110110} 
     
    272272      // File is too large.  Remember how much we were allowed to write. 
    273273      if (likely(bytes > 0 && max_swapsize > bytes)) 
    274         max_swapsize = (bytes & PAGE_MASK); 
     274        max_swapsize = TRUNC_TO_PAGE(bytes); 
    275275      break; 
    276276    case ENOSPC: 
     
    303303{ 
    304304  assert(min_swapsize <= max_swapsize); 
    305   assert(!(max_swapsize & ~PAGE_MASK)); 
    306   assert(!(min_swapsize & ~PAGE_MASK)); 
    307   assert(!(size & ~PAGE_MASK)); 
     305  assert(max_swapsize == TRUNC_TO_PAGE(max_swapsize)); 
     306  assert(min_swapsize == TRUNC_TO_PAGE(min_swapsize)); 
     307  assert(size == TRUNC_TO_PAGE(size)); 
    308308 
    309309  memsize_t realsize; 
     
    616616   * readers will notice that this relies on PAGE_SIZE being a power of two. 
    617617   */ 
    618   size = (size & PAGE_MASK) + 2*PAGE_SIZE; 
     618  size = TRUNC_TO_PAGE(size) + 2*PAGE_SIZE; 
    619619  const int newswap = find_free(sequence_number); 
    620620  if (swapfiles[newswap].size) return;  // No free slot, sorry!