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

Re: [PATCH 2/5] parallel-checkout: make it truly parallel

From
Matheus Tavares Bernardino <matheus.bernardino@usp.br>
Date
Apr 2, 2021, 14:42 UTC
Message-ID
<CAHd-oW7+x17uf2AuCrdYWUv9Ln2bq+V4rMPKo3VoYe3ZouQjLA@mail.gmail.com>
In-Reply-To
<CAP8UFD0CmPmvK7a-+5fKk0e0=te_e7cCFf6_-vSFrX9COTBg-w@mail.gmail.com>

On Wed, Mar 31, 2021 at 1:32 AM Christian Couder <christian.couder@gmail.com> wrote:

Show 15 quoted lines
>
> On Wed, Mar 17, 2021 at 10:12 PM Matheus Tavares
> <matheus.bernardino@usp.br> wrote:
>
> > diff --git a/.gitignore b/.gitignore
> > index 3dcdb6bb5a..26f8ddfc55 100644
> > --- a/.gitignore
> > +++ b/.gitignore
> > @@ -33,6 +33,7 @@
> >  /git-check-mailmap
> >  /git-check-ref-format
> >  /git-checkout
> > +/git-checkout--helper
>
> I wonder if "checkout--worker" would be better than "checkout--helper".
Yeah, good idea, I'll change that.
Show 15 quoted lines
> >  /git-checkout-index
> >  /git-cherry
> >  /git-cherry-pick
>
> [...]
>
> > +#define ASSERT_PC_ITEM_RESULT_SIZE(got, exp) \
> > +{ \
> > +       if (got != exp) \
> > +               BUG("corrupted result from checkout worker (got %dB, exp %dB)", \
>
> Maybe precompilers are smart enough to not replace the "got" and "exp"
> in the above string, but it might be a bit confusing for readers.
> Anway I wonder if this macro could just be a regular (possibly inline)
> function.
Ok, I will replace this with an inline function.
Show 31 quoted lines
> > +                   got, exp); \
> > +} while(0)
>
> > +static void parse_and_save_result(const char *line, int len,
> > +                                 struct pc_worker *worker)
> > +{
> > +       struct pc_item_result *res;
> > +       struct parallel_checkout_item *pc_item;
> > +       struct stat *st = NULL;
> > +
> > +       if (len < PC_ITEM_RESULT_BASE_SIZE)
> > +               BUG("too short result from checkout worker (got %dB, exp %dB)",
> > +                   len, (int)PC_ITEM_RESULT_BASE_SIZE);
> > +
> > +       res = (struct pc_item_result *)line;
> > +
> > +       /*
> > +        * Worker should send either the full result struct on success, or
> > +        * just the base (i.e. no stat data), otherwise.
> > +        */
> > +       if (res->status == PC_ITEM_WRITTEN) {
> > +               ASSERT_PC_ITEM_RESULT_SIZE(len, (int)sizeof(struct pc_item_result));
> > +               st = &res->st;
> > +       } else {
> > +               ASSERT_PC_ITEM_RESULT_SIZE(len, (int)PC_ITEM_RESULT_BASE_SIZE);
> > +       }
> > +
> > +       if (!worker->nr_items_to_complete || res->id != worker->next_item_to_complete)
>
> Nit: maybe it could be useful to distinguish between these 2 potential
> bugs and have a specific BUG() for each one.
Right, will do.
Show 29 quoted lines
> > +static void gather_results_from_workers(struct pc_worker *workers,
> > +                                       int num_workers)
> > +{
> > +       int i, active_workers = num_workers;
> > +       struct pollfd *pfds;
> > +
> > +       CALLOC_ARRAY(pfds, num_workers);
> > +       for (i = 0; i < num_workers; i++) {
> > +               pfds[i].fd = workers[i].cp.out;
> > +               pfds[i].events = POLLIN;
> > +       }
> > +
> > +       while (active_workers) {
> > +               int nr = poll(pfds, num_workers, -1);
> > +
> > +               if (nr < 0) {
> > +                       if (errno == EINTR)
> > +                               continue;
> > +                       die_errno("failed to poll checkout workers");
> > +               }
> > +
> > +               for (i = 0; i < num_workers && nr > 0; i++) {
>
> Is it possible that nr is 0? If that happens, it looks like we would
> be in an infinite `while (active_workers) { ... }` loop.
>
> Actually in poll(2) there is: "A value of 0 indicates that the call
> timed out and no file descriptors were ready." So it seems that it
> could, at least theorically, happen.

I think a 0 return might not be possible in this case because we call poll() with -1 as the timeout, which means "infinite timeout". So the call should block until either an error occurs (negative return code) or there is a file descriptor available for reading (positive return code).

Show 32 quoted lines
> > +enum pc_item_status {
> > +       PC_ITEM_PENDING = 0,
> > +       PC_ITEM_WRITTEN,
> > +       /*
> > +        * The entry could not be written because there was another file
> > +        * already present in its path or leading directories. Since
> > +        * checkout_entry_ca() removes such files from the working tree before
> > +        * enqueueing the entry for parallel checkout, it means that there was
> > +        * a path collision among the entries being written.
> > +        */
> > +       PC_ITEM_COLLIDED,
> > +       PC_ITEM_FAILED,
> > +};
> > +
> > +struct parallel_checkout_item {
> > +       /*
> > +        * In main process ce points to a istate->cache[] entry. Thus, it's not
> > +        * owned by us. In workers they own the memory, which *must be* released.
> > +        */
> > +       struct cache_entry *ce;
> > +       struct conv_attrs ca;
> > +       size_t id; /* position in parallel_checkout.items[] of main process */
> > +
> > +       /* Output fields, sent from workers. */
> > +       enum pc_item_status status;
> > +       struct stat st;
> > +};
>
> Maybe the previous patch could have declared both 'enum
> pc_item_status' and 'struct parallel_checkout_item' here, in
> parallel-checkout.h, so that this patch wouldn't need to move them
> here.

Yeah, while I was writing this patch I went back and forth on whether to declare these here from the start. But because I wanted to have the "parallel-checkout users" / "checkout--helper interface" division in parallel-checkout.h, I thought it would be better to move the structs to this header only after the checkout--helper was introduced.

Previous: Christian CouderNext: Junio C Hamano
Message 13 of 40 in “Parallel Checkout (part 2)”
  1. 0/5 Parallel Checkout (part 2)Matheus Tavares, Mar 17, 2021
  2. 1/5 unpack-trees: add basic support for parallel checkoutMatheus Tavares, Mar 17, 2021
  3. Christian CouderMar 31, 2021
  4. Matheus Tavares BernardinoApr 2, 2021
  5. 3/5 parallel-checkout: add configuration optionsMatheus Tavares, Mar 17, 2021
  6. Christian CouderMar 31, 2021
  7. Matheus Tavares BernardinoApr 2, 2021
  8. 5/5 parallel-checkout: add design documentationMatheus Tavares, Mar 17, 2021
  9. Christian CouderMar 31, 2021
  10. 4/5 parallel-checkout: support progress displayingMatheus Tavares, Mar 17, 2021
  11. 2/5 parallel-checkout: make it truly parallelMatheus Tavares, Mar 17, 2021
  12. Christian CouderMar 31, 2021
  13. Matheus Tavares BernardinoApr 2, 2021
  14. Junio C HamanoMar 18, 2021
  15. Matheus TavaresMar 19, 2021
  16. Junio C HamanoMar 19, 2021
  17. Christian CouderMar 31, 2021
  18. 0/5 Parallel Checkout (part 2)Matheus Tavares, Apr 8, 2021
  19. 1/5 unpack-trees: add basic support for parallel checkoutMatheus Tavares, Apr 8, 2021
  20. 2/5 parallel-checkout: make it truly parallelMatheus Tavares, Apr 8, 2021
  21. 3/5 parallel-checkout: add configuration optionsMatheus Tavares, Apr 8, 2021
  22. 4/5 parallel-checkout: support progress displayingMatheus Tavares, Apr 8, 2021
  23. 5/5 parallel-checkout: add design documentationMatheus Tavares, Apr 8, 2021
  24. Junio C HamanoApr 8, 2021
  25. Junio C HamanoApr 16, 2021
  26. Matheus Tavares BernardinoApr 17, 2021
  27. Christian CouderApr 19, 2021
  28. 0/5 Parallel Checkout (part 2)Matheus Tavares, Apr 19, 2021
  29. 1/5 unpack-trees: add basic support for parallel checkoutMatheus Tavares, Apr 19, 2021
  30. 2/5 parallel-checkout: make it truly parallelMatheus Tavares, Apr 19, 2021
  31. 3/5 parallel-checkout: add configuration optionsMatheus Tavares, Apr 19, 2021
  32. 4/5 parallel-checkout: support progress displayingMatheus Tavares, Apr 19, 2021
  33. 5/5 parallel-checkout: add design documentationMatheus Tavares, Apr 19, 2021
  34. Christian CouderApr 19, 2021
  35. 0/5 Parallel Checkout (part 2)Matheus Tavares, Apr 19, 2021
  36. 1/5 unpack-trees: add basic support for parallel checkoutMatheus Tavares, Apr 19, 2021
  37. 2/5 parallel-checkout: make it truly parallelMatheus Tavares, Apr 19, 2021
  38. 3/5 parallel-checkout: add configuration optionsMatheus Tavares, Apr 19, 2021
  39. 4/5 parallel-checkout: support progress displayingMatheus Tavares, Apr 19, 2021
  40. 5/5 parallel-checkout: add design documentationMatheus Tavares, Apr 19, 2021

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.