Changeset 142
- Timestamp:
- 07/01/06 07:57:57 (3 years ago)
- Files:
-
- trunk/src/main.c (modified) (2 diffs)
- trunk/src/main.h (modified) (2 diffs)
- trunk/src/memory.h (modified) (1 diff)
- trunk/src/swaps.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main.c
r140 r142 30 30 #include <stdlib.h> 31 31 #include <string.h> 32 #include <unistd.h> 32 33 33 34 #include <sys/param.h> … … 386 387 int main(int argc, char *argv[]) 387 388 { 388 assert(sizeof(localbuf) >= PAGE_SIZE);389 assert(sizeof(localbuf) >= getpagesize()); 389 390 390 391 close(STDIN_FILENO); trunk/src/main.h
r140 r142 24 24 #include <sys/param.h> 25 25 26 #include <asm/page.h>27 28 26 /// I thought C99 had this built in... Maybe I'm doing something wrong. 29 27 typedef int bool; … … 42 40 * 43 41 * 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. 45 43 */ 46 44 extern char localbuf[16384]; trunk/src/memory.h
r140 r142 37 37 #define MEMSIZE_ERROR LLONG_MIN 38 38 39 /// Round (through truncation) a size (in bytes) to multiple of page size40 #define TRUNC_TO_PAGE(n) (((memsize_t)(n)) & ~((memsize_t)PAGE_SIZE-1))41 42 /// Round upwards to multiple of page size43 #define EXT_TO_PAGE(n) (TRUNC_TO_PAGE((n)+PAGE_SIZE-1))44 45 39 /// Check if we can access memory status etc. Clobbers localbuf. 46 40 bool check_memory_status(void); trunk/src/swaps.c
r140 r142 67 67 static memsize_t max_swapsize = 2*TERA; 68 68 69 /// Truncate n to a multiple of memory page size 70 static 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 76 static int ext_to_page(memsize_t n) 77 { 78 return trunc_to_page(n) + getpagesize()-1; 79 } 80 69 81 70 82 #ifndef NO_CONFIG … … 75 87 char *set_min_swapsize(long long size) 76 88 { 77 min_swapsize = TRUNC_TO_PAGE(size);89 min_swapsize = trunc_to_page(size); 78 90 return NULL; 79 91 } 80 92 char *set_max_swapsize(long long size) 81 93 { 82 max_swapsize = TRUNC_TO_PAGE(size);94 max_swapsize = trunc_to_page(size); 83 95 return NULL; 84 96 } … … 97 109 { 98 110 CHECK_CONFIG_ERR(min_swapsize > max_swapsize); 99 CHECK_CONFIG_ERR(min_swapsize < 10* PAGE_SIZE);111 CHECK_CONFIG_ERR(min_swapsize < 10*getpagesize()); 100 112 101 113 if (swappath[0] != '/') … … 319 331 { 320 332 // Round upwards to multiple of page size 321 bytes = EXT_TO_PAGE(bytes);333 bytes = ext_to_page(bytes); 322 334 323 335 /* Zero buffer before using it to write data to swapfile. This doesn't do … … 365 377 if (likely(bytes > 0 && max_swapsize > bytes)) 366 378 { 367 max_swapsize = TRUNC_TO_PAGE(bytes);379 max_swapsize = trunc_to_page(bytes); 368 380 #ifndef NO_CONFIG 369 381 if (verbose) … … 397 409 { 398 410 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)); 402 414 403 415 if (unlikely(size < min_swapsize)) return 0; … … 602 614 expected, 603 615 found); 604 else if (!quiet && unlikely(found+2* PAGE_SIZE< expected))616 else if (!quiet && unlikely(found+2*getpagesize() < expected)) 605 617 log_discrep(LOG_INFO, 606 618 "smaller than expected", … … 746 758 { 747 759 /* 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. 749 762 */ 750 size = TRUNC_TO_PAGE(size) + 2*PAGE_SIZE;763 size = trunc_to_page(size) + 2*getpagesize(); 751 764 const int newswap = find_free(sequence_number); 752 765 if (unlikely(swapfiles[newswap].size)) return false; // No free slot, sorry!
