git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 03/17] index-helper: new daemon for caching index and related stuff

From
Duy Nguyen <pclouds@gmail.com>
Date
Mar 29, 2016, 02:31 UTC
Message-ID
<CACsJy8Bk19NNacDwez6BzicThnVUDQEoGe3m+ThiorP8uP9+eA@mail.gmail.com>
In-Reply-To
<1458349490-1704-4-git-send-email-dturner@twopensource.com>
On Sat, Mar 19, 2016 at 8:04 AM, David Turner <dturner@twopensource.com> wrote:
Show 15 quoted lines
> From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>
> Instead of reading the index from disk and worrying about disk
> corruption, the index is cached in memory (memory bit-flips happen
> too, but hopefully less often). The result is faster read. Read time
> is reduced by 70%.
>
> The biggest gain is not having to verify the trailing SHA-1, which
> takes lots of time especially on large index files. But this also
> opens doors for further optimiztions:
>
>  - we could create an in-memory format that's essentially the memory
>    dump of the index to eliminate most of parsing/allocation
>    overhead. The mmap'd memory can be used straight away. Experiment
>    [1] shows we could reduce read time by 88%.

This reference [1] is missing (even in my old version). I believe it's http://thread.gmane.org/gmane.comp.version-control.git/247268/focus=248771, comparing 256.442ms in that mail with v4 number, 2245.113ms in 0/8 mail from the same thread.

Show 5 quoted lines
> Git can poke the daemon via named pipes to tell it to refresh the
> index cache, or to keep it alive some more minutes. It can't give any
> real index data directly to the daemon. Real data goes to disk first,
> then the daemon reads and verifies it from there. Poking only happens
> for $GIT_DIR/index, not temporary index files.

I think we should go with unix socket on *nix platform instead of named pipe. UNIX named pipe only allows one communication channel at a time. Windows named pipe is different and allows multiple clients, which is the same as unix socket.

Show 5 quoted lines
> $GIT_DIR/index-helper.pipe is the named pipe for daemon process. The
> daemon reads from the pipe and executes commands.  Commands that need
> replies from the daemon will have to open their own pipe, since a
> named pipe should only have one reader.  Unix domain sockets don't
> have this problem, but are less portable.

Hm..NO_UNIX_SOCKETS is only set for Windows in config.mak.uname and Windows will need to be specially tailored anyway, I think unix socket would be more elegant.

Show 24 quoted lines
> +static void share_index(struct index_state *istate, struct shm *is)
> +{
> +       void *new_mmap;
> +       if (istate->mmap_size <= 20 ||
> +           hashcmp(istate->sha1,
> +                   (unsigned char *)istate->mmap + istate->mmap_size - 20) ||
> +           !hashcmp(istate->sha1, is->sha1) ||
> +           git_shm_map(O_CREAT | O_EXCL | O_RDWR, 0700, istate->mmap_size,
> +                       &new_mmap, PROT_READ | PROT_WRITE, MAP_SHARED,
> +                       "git-index-%s", sha1_to_hex(istate->sha1)) < 0)
> +               return;
> +
> +       release_index_shm(is);
> +       is->size = istate->mmap_size;
> +       is->shm = new_mmap;
> +       hashcpy(is->sha1, istate->sha1);
> +       memcpy(new_mmap, istate->mmap, istate->mmap_size - 20);
> +
> +       /*
> +        * The trailing hash must be written last after everything is
> +        * written. It's the indication that the shared memory is now
> +        * ready.
> +        */
> +       hashcpy((unsigned char *)new_mmap + istate->mmap_size - 20, is->sha1);

You commented here [1] a long time ago about memory barrier. I'm not entirely sure if compilers dare to reorder function calls, but when hashcpy is inlined and memcpy is builtin, I suppose that's possible...

[1] http://article.gmane.org/gmane.comp.version-control.git/280729
> +}
-- 
Duy
Previous: David TurnerNext: David Turner
Message 5 of 25 in “index-helper, watchman”
  1. 00/15 index-helper, watchmanDavid Turner, Mar 19, 2016
  2. 01/17 read-cache.c: fix constness of verify_hdr()David Turner, Mar 19, 2016
  3. 02/17 read-cache: allow to keep mmap'd memory after readingDavid Turner, Mar 19, 2016
  4. 03/17 index-helper: new daemon for caching index and related stuffDavid Turner, Mar 19, 2016
  5. Duy NguyenMar 29, 2016
  6. David TurnerMar 29, 2016
  7. 04/17 index-helper: add --strictDavid Turner, Mar 19, 2016
  8. 05/17 daemonize(): set a flag before exiting the main processDavid Turner, Mar 19, 2016
  9. 06/17 index-helper: add --detachDavid Turner, Mar 19, 2016
  10. Duy NguyenMar 29, 2016
  11. 07/17 read-cache: add watchman 'WAMA' extensionDavid Turner, Mar 19, 2016
  12. 08/17 read-cache: invalidate untracked cache data when reading WAMADavid Turner, Mar 19, 2016
  13. Duy NguyenMar 29, 2016
  14. David TurnerMar 29, 2016
  15. 09/17 Add watchman support to reduce index refresh costDavid Turner, Mar 19, 2016
  16. Jeff HostetlerMar 24, 2016
  17. David TurnerMar 24, 2016
  18. 10/17 index-helper: use watchman to avoid refreshing index with lstat()David Turner, Mar 19, 2016
  19. 11/17 update-index: enable/disable watchman supportDavid Turner, Mar 19, 2016
  20. 12/17 unpack-trees: preserve index extensionsDavid Turner, Mar 19, 2016
  21. 13/17 index-helper: kill modeDavid Turner, Mar 19, 2016
  22. 14/17 index-helper: don't run if already runningDavid Turner, Mar 19, 2016
  23. 15/17 index-helper: autorun modeDavid Turner, Mar 19, 2016
  24. 16/17 index-helper: optionally automatically runDavid Turner, Mar 19, 2016
  25. 17/17 read-cache: config for waiting for index-helperDavid Turner, Mar 19, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.