---
 read-cache.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/read-cache.c b/read-cache.c
index 9e742c7..3100a59 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1462,6 +1462,35 @@ static struct cache_entry *create_from_disk(struct 
ondisk_cache_entry *ondisk,
        return ce;
 }
 
+static void *try_shm(void *mmap, size_t mmap_size)
+{
+       struct strbuf sb = STRBUF_INIT;
+       void *new_mmap;
+       struct stat st;
+       int fd;
+
+       if (mmap_size <= 20)
+               return mmap;
+
+       strbuf_addf(&sb, "/git-index-%s",
+                   sha1_to_hex((unsigned char *)mmap + mmap_size - 20));
+       fd = shm_open(sb.buf, O_RDONLY, 0777);
+       strbuf_release(&sb);
+       if (fd < 0)
+               return mmap;
+       if (fstat(fd, &st) || st.st_size != mmap_size) {
+               close(fd);
+               return mmap;
+       }
+       new_mmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       close(fd);
+       if (new_mmap == MAP_FAILED)
+               return mmap;
+       munmap(mmap, mmap_size);
+       return new_mmap;
+}
+
+
 /* remember to discard_cache() before reading a different cache! */
 int do_read_index(struct index_state *istate, const char *path, int must_exist)
 {
@@ -1501,6 +1530,7 @@ int do_read_index(struct index_state *istate, const char 
*path, int must_exist)
        }
        close(fd);
 
+       mmap = try_shm(mmap, mmap_size);
        hdr = mmap;
        if (verify_hdr(hdr, mmap_size) < 0)
                goto unmap;
-- 
1.9.1.346.ga2b5940

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to