On Fri, 7 Oct 2005, Alex Riesen wrote:I really think that you should just get rid of the mmap. As it is, you're just slowing the code down on sane architectures. That's not good. So I'd suggest something like this instead. Totally untested, of course. Linus ---- diff --git a/read-cache.c b/read-cache.c --- a/read-cache.c +++ b/read-cache.c @@ -454,13 +454,39 @@ static int verify_hdr(struct cache_heade return 0; } +static void *map_index_file(int fd, size_t size) +{ + void *map; +#ifdef NO_MMAP + map = malloc(size); + if (!map) + die("Unable to allocate index file mapping"); + if (read(fd, map, size) != size) + die("Unable to read %z bytes from inde +#else + map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + if (map == MAP_FAILED) + die("index file mmap failed (%s)", strerror(errno)); +#endif + return map; +} + +static void unmap_index_file(void *map, size_t size) +{ +#ifdef NO_MMAP + free(map); +#else + munmap(map, size); +#endif +} + int read_cache(void) { int fd, i; struct stat st; unsigned long size, offset; - void *map; struct cache_header *hdr; + void *map; errno = EBUSY; if (active_cache) @@ -475,16 +501,15 @@ int read_cache(void) } size = 0; // avoid gcc warning - map = MAP_FAILED; - if (!fstat(fd, &st)) { - size = st.st_size; - errno = EINVAL; - if (size >= sizeof(struct cache_header) + 20) - map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - } + if (fstat(fd, &st)) + die("unable to fstat index file"); + + size = st.st_size; + errno = EINVAL; + if (size < sizeof(struct cache_header) + 20) + goto corrupt; + map = map_index_file(fd, size); close(fd); - if (map == MAP_FAILED) - die("index file mmap failed (%s)", strerror(errno)); hdr = map; if (verify_hdr(hdr, size) < 0) @@ -503,8 +528,9 @@ int read_cache(void) return active_nr; unmap: - munmap(map, size); + unmap_index_file(map, size); errno = EINVAL; +corrupt: die("index file corrupt"); } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
| Mike Travis | [RFC 00/15] x86_64: Optimize percpu accesses |
| Nick Piggin | Re: [PATCH 0 of 4] Generic AIO by scheduling stacks |
| Trent Piepho | [PATCH] [POWERPC] Improve (in|out)_beXX() asm code |
| Bart Van Assche | Integration of SCST in the mainstream Linux kernel |
git: | |
| Kevin Ballard | Re: git on MacOSX and files with decomposed utf-8 file names |
| Jon Smirl | ! [rejected] master -> master (non-fast forward) |
| Linus Torvalds | Re: kernel.org mirroring (Re: [GIT PULL] MMC update) |
| Nguyen Thai Ngoc Duy | Re: VCS comparison table |
| Leon Dippenaar | New tcp stack attack |
| Richard Stallman | Real men don't attack straw men |
| Kevin Neff | Patching a SSH 'Weakness' |
| Chris | sudo & wheel group |
| David Miller | [GIT]: Networking |
| Wang Chen | [PATCH 2/15] netdevice 82596: Convert directly reference of netdev->priv to net... |
| Valentine Barshak | [PATCH] USB: net: Fix asix read transfer buffer allocations. |
| Natalie Protasevich | [BUG] New Kernel Bugs |
