From 3355e84f7cd4485564b92145efff82ac73c61873 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 12 Jan 2007 12:20:55 +0100 Subject: [PATCH] CPU_PAGE_SIZE ported from mainline. --- lib/autoconf.cfg | 19 ++++++++++++++++--- lib/fb-mmap.c | 17 ++++++++--------- lib/lizard-safe.c | 15 +++++++-------- lib/lizard-test.c | 5 ++--- lib/partmap.c | 5 ++--- lib/qache.c | 7 +++---- 6 files changed, 38 insertions(+), 30 deletions(-) diff --git a/lib/autoconf.cfg b/lib/autoconf.cfg index 2cbb1efa..66c4056c 100644 --- a/lib/autoconf.cfg +++ b/lib/autoconf.cfg @@ -1,5 +1,5 @@ # Automatic configuration of the UCW Library -# (c) 2005 Martin Mares +# (c) 2005--2007 Martin Mares # (c) 2006 Robert Spalek ### OS ### @@ -221,10 +221,23 @@ if (IsSet("CONFIG_DARWIN")) { Append("LIBS" => "-L/sw/lib"); Append("COPT" => "-I/sw/include"); # Fill in some constants not found in the system header files - Set("PAGE_SIZE" => `sysctl -n hw.pagesize`); - Set("SOL_TCP" => 6); #missing in /usr/include/netinet/tcp.h + Set("SOL_TCP" => 6); # missing in /usr/include/netinet/tcp.h } +# Determine page size +Test("CPU_PAGE_SIZE", "Determining page size", sub { + my $p; + if (IsSet("CONFIG_DARWIN")) { + $p = `sysctl -n hw.pagesize`; + defined $p or Fail "sysctl hw.pagesize failed"; + } elsif (IsSet("CONFIG_LINUX")) { + $p = `getconf PAGE_SIZE`; + defined $p or Fail "getconf PAGE_SIZE failed"; + } + chomp $p; + return $p; +}); + if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) { # Use 64-bit versions of file functions Set("CONFIG_LFS"); diff --git a/lib/fb-mmap.c b/lib/fb-mmap.c index 67b7f910..85dc27ee 100644 --- a/lib/fb-mmap.c +++ b/lib/fb-mmap.c @@ -16,10 +16,9 @@ #include #include #include -#include -static uns mmap_window_size = 16*PAGE_SIZE; -static uns mmap_extend_size = 4*PAGE_SIZE; +static uns mmap_window_size = 16*CPU_PAGE_SIZE; +static uns mmap_extend_size = 4*CPU_PAGE_SIZE; static struct cf_section fbmm_config = { CF_ITEMS { @@ -49,10 +48,10 @@ static void bfmm_map_window(struct fastbuf *f) { struct fb_mmap *F = FB_MMAP(f); - sh_off_t pos0 = f->pos & ~(sh_off_t)(PAGE_SIZE-1); + sh_off_t pos0 = f->pos & ~(sh_off_t)(CPU_PAGE_SIZE-1); int l = MIN((sh_off_t)mmap_window_size, F->file_extend - pos0); - uns ll = ALIGN_TO(l, PAGE_SIZE); - uns oll = ALIGN_TO(f->bufend - f->buffer, PAGE_SIZE); + uns ll = ALIGN_TO(l, CPU_PAGE_SIZE); + uns oll = ALIGN_TO(f->bufend - f->buffer, CPU_PAGE_SIZE); int prot = ((F->mode & O_ACCMODE) == O_RDONLY) ? PROT_READ : (PROT_READ | PROT_WRITE); DBG(" ... Mapping %x(%x)+%x(%x) len=%x extend=%x", (int)pos0, (int)f->pos, ll, l, (int)F->file_size, (int)F->file_extend); @@ -68,7 +67,7 @@ bfmm_map_window(struct fastbuf *f) if (f->buffer == (byte *) MAP_FAILED) die("mmap(%s): %m", f->name); #ifdef MADV_SEQUENTIAL - if (ll > PAGE_SIZE) + if (ll > CPU_PAGE_SIZE) madvise(f->buffer, ll, MADV_SEQUENTIAL); #endif f->bufend = f->buffer + l; @@ -109,7 +108,7 @@ bfmm_spout(struct fastbuf *f) f->pos = end; if (f->pos >= F->file_extend) { - F->file_extend = ALIGN_TO(F->file_extend + mmap_extend_size, (sh_off_t)PAGE_SIZE); + F->file_extend = ALIGN_TO(F->file_extend + mmap_extend_size, (sh_off_t)CPU_PAGE_SIZE); if (sh_ftruncate(F->fd, F->file_extend)) die("ftruncate(%s): %m", f->name); } @@ -137,7 +136,7 @@ bfmm_close(struct fastbuf *f) struct fb_mmap *F = FB_MMAP(f); if (f->buffer) - munmap(f->buffer, ALIGN_TO(f->bufend-f->buffer, PAGE_SIZE)); + munmap(f->buffer, ALIGN_TO(f->bufend-f->buffer, CPU_PAGE_SIZE)); if (F->file_extend > F->file_size && sh_ftruncate(F->fd, F->file_size)) die("ftruncate(%s): %m", f->name); diff --git a/lib/lizard-safe.c b/lib/lizard-safe.c index 7553b459..0473e34a 100644 --- a/lib/lizard-safe.c +++ b/lib/lizard-safe.c @@ -12,7 +12,6 @@ #include "lib/lizard.h" #include -#include #include #include #include @@ -38,13 +37,13 @@ lizard_free(struct lizard_buffer *buf) { unhandle_signal(SIGSEGV); if (buf->ptr) - munmap(buf->ptr, buf->len + PAGE_SIZE); + munmap(buf->ptr, buf->len + CPU_PAGE_SIZE); xfree(buf); } static void lizard_realloc(struct lizard_buffer *buf, uns max_len) - /* max_len needs to be aligned to PAGE_SIZE */ + /* max_len needs to be aligned to CPU_PAGE_SIZE */ { if (max_len <= buf->len) return; @@ -52,12 +51,12 @@ lizard_realloc(struct lizard_buffer *buf, uns max_len) max_len = 2*buf->len; if (buf->ptr) - munmap(buf->ptr, buf->len + PAGE_SIZE); + munmap(buf->ptr, buf->len + CPU_PAGE_SIZE); buf->len = max_len; - buf->ptr = mmap(NULL, buf->len + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); + buf->ptr = mmap(NULL, buf->len + CPU_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); if (buf->ptr == MAP_FAILED) - die("mmap(anonymous, %d bytes): %m", (uns)(buf->len + PAGE_SIZE)); - if (mprotect(buf->ptr + buf->len, PAGE_SIZE, PROT_NONE) < 0) + die("mmap(anonymous, %d bytes): %m", (uns)(buf->len + CPU_PAGE_SIZE)); + if (mprotect(buf->ptr + buf->len, CPU_PAGE_SIZE, PROT_NONE) < 0) die("mprotect: %m"); } @@ -77,7 +76,7 @@ lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length) * case of buffer-overflow. The function is not re-entrant because of a * static longjmp handler. */ { - uns lock_offset = ALIGN_TO(expected_length + 3, PAGE_SIZE); // +3 due to the unaligned access + uns lock_offset = ALIGN_TO(expected_length + 3, CPU_PAGE_SIZE); // +3 due to the unaligned access if (lock_offset > buf->len) lizard_realloc(buf, lock_offset); volatile sh_sighandler_t old_handler = set_signal_handler(SIGSEGV, sigsegv_handler); diff --git a/lib/lizard-test.c b/lib/lizard-test.c index 3973cfcd..dd9c62c4 100644 --- a/lib/lizard-test.c +++ b/lib/lizard-test.c @@ -6,7 +6,6 @@ #include #include #include -#include static char *options = CF_SHORT_OPTS "cdtx"; static char *help = "\ @@ -105,8 +104,8 @@ main(int argc, char **argv) else { int smaller_li; - if (li >= (int) PAGE_SIZE) - smaller_li = li - PAGE_SIZE; + if (li >= (int) CPU_PAGE_SIZE) + smaller_li = li - CPU_PAGE_SIZE; else smaller_li = 0; struct lizard_buffer *buf = lizard_alloc(); diff --git a/lib/partmap.c b/lib/partmap.c index 8dba8f8f..3b32bc90 100644 --- a/lib/partmap.c +++ b/lib/partmap.c @@ -18,7 +18,6 @@ #include #include #include -#include #ifdef CONFIG_PARTMAP_IS_MMAP #define PARTMAP_WINDOW ~(size_t)0 @@ -68,10 +67,10 @@ partmap_load(struct partmap *p, sh_off_t start, uns size) if (p->start_map) munmap(p->start_map, p->end_off - p->start_off); sh_off_t end = start + size; - sh_off_t win_start = start/PAGE_SIZE * PAGE_SIZE; + sh_off_t win_start = start/CPU_PAGE_SIZE * CPU_PAGE_SIZE; size_t win_len = PARTMAP_WINDOW; if ((sh_off_t) (win_start+win_len) > p->file_size) - win_len = ALIGN_TO(p->file_size - win_start, PAGE_SIZE); + win_len = ALIGN_TO(p->file_size - win_start, CPU_PAGE_SIZE); if ((sh_off_t) (win_start+win_len) < end) die("partmap_map: Window is too small for mapping %d bytes", size); p->start_map = sh_mmap(NULL, win_len, p->writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, p->fd, win_start); diff --git a/lib/qache.c b/lib/qache.c index 3c4be273..5a832bb7 100644 --- a/lib/qache.c +++ b/lib/qache.c @@ -15,7 +15,6 @@ #include #include #include -#include /* * The cache lives in a mmapped file of the following format: @@ -81,9 +80,9 @@ qache_msync(struct qache *q UNUSED, uns start UNUSED, uns len UNUSED) { #ifndef CONFIG_LINUX /* We don't need msyncing on Linux, since the mappings are guaranteed to be coherent */ - len += (start % PAGE_SIZE); - start -= start % PAGE_SIZE; - len = ALIGN_TO(len, PAGE_SIZE); + len += (start % CPU_PAGE_SIZE); + start -= start % CPU_PAGE_SIZE; + len = ALIGN_TO(len, CPU_PAGE_SIZE); if (msync(q->mmap_data + start, len, MS_ASYNC | MS_INVALIDATE) < 0) log(L_ERROR, "Cache %s: msync failed: %m", q->file_name); #endif -- 2.39.2