From: Martin Mares Date: Mon, 16 Jan 2006 19:41:56 +0000 (+0000) Subject: On 64-bit architectures, partmap is just an mmap. X-Git-Tag: holmes-import~693 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=95d18fdbc7274c501eed2ecce3861452aaa4a50c;p=libucw.git On 64-bit architectures, partmap is just an mmap. On all architectures, it calls madvise() to optimize for sequential access. --- diff --git a/lib/autoconf.cfg b/lib/autoconf.cfg index 4485db74..3c81f034 100644 --- a/lib/autoconf.cfg +++ b/lib/autoconf.cfg @@ -170,6 +170,9 @@ if (IsSet("CONFIG_DEBUG")) { Append("LOPT" => "-s"); } +# Decide how will lib/partmap.c work +Set("PARTMAP_IS_MMAP") if IsSet("CPU_64BIT_POINTERS"); + # If debugging memory allocations: #LIBS+=-lefence #CDEBUG+=-DDEBUG_DMALLOC diff --git a/lib/partmap.c b/lib/partmap.c index 60ec168c..49f12322 100644 --- a/lib/partmap.c +++ b/lib/partmap.c @@ -1,7 +1,7 @@ /* * UCW Library -- Mapping of File Parts * - * (c) 2003 Martin Mares + * (c) 2003--2006 Martin Mares * (c) 2003--2005 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -20,11 +20,15 @@ #include #include +#ifdef CONFIG_PARTMAP_IS_MMAP +#define PARTMAP_WINDOW ~(size_t)0 +#else #ifdef TEST #define PARTMAP_WINDOW 4096 #else #define PARTMAP_WINDOW 16777216 #endif +#endif struct partmap * partmap_open(byte *name, int writeable) @@ -37,6 +41,9 @@ partmap_open(byte *name, int writeable) if ((p->file_size = sh_seek(p->fd, 0, SEEK_END)) < 0) die("lseek(%s): %m", name); p->writeable = writeable; +#ifdef CONFIG_PARTMAP_IS_MMAP + partmap_load(p, 0, p->file_size); +#endif return p; } @@ -62,7 +69,7 @@ partmap_load(struct partmap *p, sh_off_t start, uns size) 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; - uns win_len = PARTMAP_WINDOW; + size_t win_len = PARTMAP_WINDOW; if ((sh_off_t) (win_start+win_len) > p->file_size) win_len = ALIGN(p->file_size - win_start, PAGE_SIZE); if ((sh_off_t) (win_start+win_len) < end) @@ -72,6 +79,7 @@ partmap_load(struct partmap *p, sh_off_t start, uns size) die("mmap failed at position %Ld: %m", (long long)win_start); p->start_off = win_start; p->end_off = win_start+win_len; + madvise(p->start_map, win_len, MADV_SEQUENTIAL); } #ifdef TEST diff --git a/lib/partmap.h b/lib/partmap.h index b5c48099..1be70ded 100644 --- a/lib/partmap.h +++ b/lib/partmap.h @@ -1,7 +1,7 @@ /* * UCW Library -- Mapping of File Parts * - * (c) 2003 Martin Mares + * (c) 2003--2006 Martin Mares * (c) 2003--2005 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -25,18 +25,22 @@ sh_off_t partmap_size(struct partmap *p); void partmap_load(struct partmap *p, sh_off_t start, uns size); static inline void * -partmap_map(struct partmap *p, sh_off_t start, uns size) +partmap_map(struct partmap *p, sh_off_t start, uns size UNUSED) { +#ifndef CONFIG_PARTMAP_IS_MMAP if (unlikely(!p->start_map || start < p->start_off || (sh_off_t) (start+size) > p->end_off)) partmap_load(p, start, size); +#endif return p->start_map + (start - p->start_off); } static inline void * -partmap_map_forward(struct partmap *p, sh_off_t start, uns size) +partmap_map_forward(struct partmap *p, sh_off_t start, uns size UNUSED) { +#ifndef CONFIG_PARTMAP_IS_MMAP if (unlikely((sh_off_t) (start+size) > p->end_off)) partmap_load(p, start, size); +#endif return p->start_map + (start - p->start_off); }