Changeset 142

Show
Ignore:
Timestamp:
07/01/06 07:57:57 (3 years ago)
Author:
jtv
Message:

Fixes #20 and, hopefully, build failure on Debian-PowerPC

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main.c

    r140 r142  
    3030#include <stdlib.h> 
    3131#include <string.h> 
     32#include <unistd.h> 
    3233 
    3334#include <sys/param.h> 
     
    386387int main(int argc, char *argv[]) 
    387388{ 
    388   assert(sizeof(localbuf) >= PAGE_SIZE); 
     389  assert(sizeof(localbuf) >= getpagesize()); 
    389390 
    390391  close(STDIN_FILENO); 
  • trunk/src/main.h

    r140 r142  
    2424#include <sys/param.h> 
    2525 
    26 #include <asm/page.h> 
    27  
    2826/// I thought C99 had this built in... Maybe I'm doing something wrong. 
    2927typedef int bool; 
     
    4240 * 
    4341 * Size is best kept to an even multiple of page size, and is guaranteed to be 
    44  * no less than PAGE_SIZE
     42 * no less than one page in size
    4543 */ 
    4644extern char localbuf[16384]; 
  • trunk/src/memory.h

    r140 r142  
    3737#define MEMSIZE_ERROR LLONG_MIN 
    3838 
    39 /// Round (through truncation) a size (in bytes) to multiple of page size 
    40 #define TRUNC_TO_PAGE(n) (((memsize_t)(n)) & ~((memsize_t)PAGE_SIZE-1)) 
    41  
    42 /// Round upwards to multiple of page size 
    43 #define EXT_TO_PAGE(n) (TRUNC_TO_PAGE((n)+PAGE_SIZE-1)) 
    44  
    4539/// Check if we can access memory status etc.  Clobbers localbuf. 
    4640bool check_memory_status(void); 
  • trunk/src/swaps.c

    r140 r142  
    6767static memsize_t max_swapsize = 2*TERA; 
    6868 
     69/// Truncate n to a multiple of memory page size 
     70static int trunc_to_page(memsize_t n) 
     71{ 
     72  return n & ~((memsize_t)getpagesize()-1); 
     73} 
     74 
     75/// Round n upwards to multiple of page size 
     76static int ext_to_page(memsize_t n) 
     77{ 
     78  return trunc_to_page(n) + getpagesize()-1; 
     79} 
     80 
    6981 
    7082#ifndef NO_CONFIG 
     
    7587char *set_min_swapsize(long long size) 
    7688{ 
    77   min_swapsize = TRUNC_TO_PAGE(size); 
     89  min_swapsize = trunc_to_page(size); 
    7890  return NULL; 
    7991} 
    8092char *set_max_swapsize(long long size) 
    8193{ 
    82   max_swapsize = TRUNC_TO_PAGE(size); 
     94  max_swapsize = trunc_to_page(size); 
    8395  return NULL; 
    8496} 
     
    97109{ 
    98110  CHECK_CONFIG_ERR(min_swapsize > max_swapsize); 
    99   CHECK_CONFIG_ERR(min_swapsize < 10*PAGE_SIZE); 
     111  CHECK_CONFIG_ERR(min_swapsize < 10*getpagesize()); 
    100112 
    101113  if (swappath[0] != '/') 
     
    319331{ 
    320332  // Round upwards to multiple of page size 
    321   bytes = EXT_TO_PAGE(bytes); 
     333  bytes = ext_to_page(bytes); 
    322334 
    323335  /* Zero buffer before using it to write data to swapfile.  This doesn't do 
     
    365377      if (likely(bytes > 0 && max_swapsize > bytes)) 
    366378      { 
    367         max_swapsize = TRUNC_TO_PAGE(bytes); 
     379        max_swapsize = trunc_to_page(bytes); 
    368380#ifndef NO_CONFIG 
    369381        if (verbose) 
     
    397409{ 
    398410  assert(min_swapsize <= max_swapsize); 
    399   assert(max_swapsize == TRUNC_TO_PAGE(max_swapsize)); 
    400   assert(min_swapsize == TRUNC_TO_PAGE(min_swapsize)); 
    401   assert(size == TRUNC_TO_PAGE(size)); 
     411  assert(max_swapsize == trunc_to_page(max_swapsize)); 
     412  assert(min_swapsize == trunc_to_page(min_swapsize)); 
     413  assert(size == trunc_to_page(size)); 
    402414 
    403415  if (unlikely(size < min_swapsize)) return 0; 
     
    602614              expected, 
    603615              found); 
    604         else if (!quiet && unlikely(found+2*PAGE_SIZE < expected)) 
     616        else if (!quiet && unlikely(found+2*getpagesize() < expected)) 
    605617          log_discrep(LOG_INFO, 
    606618              "smaller than expected", 
     
    746758{ 
    747759  /* Round request to page size, then add a bit for swapfile overhead.  Clever 
    748    * readers will notice that this relies on PAGE_SIZE being a power of two. 
     760   * readers will notice that this relies on getpagesize() returning a power of 
     761   * two. 
    749762   */ 
    750   size = TRUNC_TO_PAGE(size) + 2*PAGE_SIZE
     763  size = trunc_to_page(size) + 2*getpagesize()
    751764  const int newswap = find_free(sequence_number); 
    752765  if (unlikely(swapfiles[newswap].size)) return false;  // No free slot, sorry!