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

Re: [PATCH 1/1] pcre2: allow overriding the system allocator

From
Carlo Arenas <carenas@gmail.com>
Date
Aug 6, 2019, 06:24 UTC
Message-ID
<CAPUEsphMh_ZqcH3M7PXC9jHTfEdQN3mhTAK2JDkdvKBp53YBoA@mail.gmail.com>
In-Reply-To
<xmqq36ifmg7v.fsf@gitster-ct.c.googlers.com>
On Mon, Aug 5, 2019 at 2:53 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
>
> Carlo Arenas <carenas@gmail.com> writes:
>
> > LGTM except from the suggestion below that might make the code more "standard"
> > and probably be a good base for a similar PCRE1 fix
> >>
> >> +static pcre2_general_context *get_pcre2_context(void)
> >> +{
> >> +       static pcre2_general_context *context;
> >> +
> >> +       if (!context)
> >> +               context = pcre2_general_context_create(pcre2_malloc,
> >> +                                                      pcre2_free, NULL);
> >> +
> >> +       return context;
> >> +}
> >
> > instead of using a static variable inside this helper function it
> > might be better to use
> > one extra field inside the (struct grep_pat *p), where all other
> > variables are kept
> >
> > Additionally to being more consistent will avoid creating the global
>
> "standard" and "more consistent" are good things, but I am not sure
> I should agree with the argument without knowing what you are
> comparing your suggested improvement with.  Whose standard practice
> are we trying to be consistent with?  Keeping dynamic resources hooked
> to "struct grep_pat" so that (1) different patterns could use different
> settings when they desire and (2) the resources are not hidden behind
> a function-scope static and can be discarded when we are done with
> the pattern, which is the standard in our "grep" subsystem?

It was my impression that we were abusing the struct grep_pat to avoid having to deal properly with threading and interlocks.

I agree my wording wasn't clear enough and my hinting a little obscure but the original code is racy and it wouldn't be if the "global context" will be initialized/maintained there; as an added benefit it will be straight forward to clear (together with the rest)

I am not advocating that as a good design, but also think the code will be shorter (which was another rationale for the proposed change, to avoid introducing yet more bugs and since it was even suggested for inclusion in the next release)

Show 5 quoted lines
> I think general context probably corresponds to a bit higher level
> than individual grep_pat.  E.g. when running "grep -e foo -e bar",
> do we expect resources needed by patterns "foo" and "bar" would want
> to be allocated and freed by potentially separate <alloc,free>
> function pairs?

no with a different design; but currently even if almost all the time we have the same pattern for all workers (ex: -e foo), why are we doing the compilation (plus JIT translation) and creating this table and all other context pointers (plus a jit stack) once per thread?

just so we can move forward with a better design will send a proposed patch that does things a little be better as an RFC

Show 8 quoted lines
> > context for the
> > most common case (when the locale is either C/POSIX or UTF-8) and therefore
> > have a smaller impact on performance.
>
> I am not sure about the impact on performance, but if it helps us
> keep the subsystem reusable by avoiding function-scope static that
> we cannot clear, that would be a good thing.  But "struct grep_pat"
> may be a bit too fine-grained to control general context.

the "performance" point I was making was that with the current code the chartable is only created when it is strictly needed (meaning the pattern/haystack will do matching in non UTF-8 mode but with characters with code higher than 127 and therefore MUST agree in a codepage)

most of the time (like when using UTF-8) the chartable (and therefore the global context) is not needed (even when using alternate allocators)

there is a chance that PCRE2 might perform better with NED, but not in my system and since we haven't been using NED with PCRE2 until this proposed change it might be better to do that independently anyway.

Carlo
Previous: Junio C HamanoNext: Carlo Marcelo Arenas Belón
Message 8 of 67 in “Fix a problem with PCRE2 and nedmalloc, found via Azure Pipelines”
  1. 0/1 Fix a problem with PCRE2 and nedmalloc, found via Azure PipelinesJohannes Schindelin via GitGitGadget, Aug 5, 2019
  2. 1/1 pcre2: allow overriding the system allocatorJohannes Schindelin via GitGitGadget, Aug 5, 2019
  3. Carlo ArenasAug 5, 2019
  4. Carlo ArenasAug 5, 2019
  5. Johannes SchindelinAug 5, 2019
  6. Johannes SchindelinAug 5, 2019
  7. Junio C HamanoAug 5, 2019
  8. Carlo ArenasAug 6, 2019
  9. 0/3 grep: no leaks (WIP)Carlo Marcelo Arenas Belón, Aug 6, 2019
  10. 1/3 grep: make PCRE1 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 6, 2019
  11. Johannes SchindelinAug 8, 2019
  12. Carlo ArenasAug 8, 2019
  13. 3/3 grep: avoid leak of chartables in PCRE2Carlo Marcelo Arenas Belón, Aug 6, 2019
  14. 2/3 grep: make PCRE2 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 6, 2019
  15. Johannes SchindelinAug 8, 2019
  16. Carlo ArenasAug 8, 2019
  17. 0/3 grep: no leaks or crashes (windows testing needed)Carlo Marcelo Arenas Belón, Aug 6, 2019
  18. 2/3 grep: make PCRE2 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 6, 2019
  19. René ScharfeAug 7, 2019
  20. Carlo ArenasAug 7, 2019
  21. René ScharfeAug 7, 2019
  22. 1/2 nedmalloc: do assignments only after the declaration sectionRené Scharfe, Aug 7, 2019
  23. 2/2 nedmalloc: avoid compiler warning about unused valueRené Scharfe, Aug 7, 2019
  24. Carlo ArenasAug 8, 2019
  25. René ScharfeAug 8, 2019
  26. Carlo ArenasAug 8, 2019
  27. René ScharfeAug 8, 2019
  28. Johannes SchindelinAug 8, 2019
  29. Junio C HamanoAug 7, 2019
  30. 1/3 grep: make PCRE1 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 6, 2019
  31. 3/3 grep: avoid leak of chartables in PCRE2Carlo Marcelo Arenas Belón, Aug 6, 2019
  32. Junio C HamanoAug 6, 2019
  33. 0/3 grep: no leaks or crashes (windows testing needed)Carlo Marcelo Arenas Belón, Aug 7, 2019
  34. 1/3 grep: make PCRE1 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 7, 2019
  35. 2/3 grep: make PCRE2 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 7, 2019
  36. Junio C HamanoAug 7, 2019
  37. 3/3 grep: avoid leak of chartables in PCRE2Carlo Marcelo Arenas Belón, Aug 7, 2019
  38. 0/3 grep: almost no more leaks, hopefully no crashesCarlo Marcelo Arenas Belón, Aug 9, 2019
  39. 1/3 grep: make PCRE1 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 9, 2019
  40. 3/3 grep: avoid leak of chartables in PCRE2Carlo Marcelo Arenas Belón, Aug 9, 2019
  41. 2/3 grep: make PCRE2 aware of custom allocatorCarlo Marcelo Arenas Belón, Aug 9, 2019
  42. Johannes SchindelinAug 27, 2019
  43. Carlo ArenasAug 27, 2019
  44. Junio C HamanoOct 3, 2019
  45. Johannes SchindelinOct 3, 2019
  46. Carlo ArenasOct 3, 2019
  47. Johannes SchindelinOct 3, 2019
  48. Junio C HamanoOct 3, 2019
  49. Carlo ArenasAug 9, 2019
  50. René ScharfeAug 9, 2019
  51. Junio C HamanoAug 9, 2019
  52. Johannes SchindelinAug 9, 2019
  53. SQUASHCarlo Marcelo Arenas Belón, Aug 10, 2019
  54. René ScharfeAug 10, 2019
  55. Carlo ArenasAug 10, 2019
  56. René ScharfeAug 10, 2019
  57. Carlo ArenasAug 12, 2019
  58. René ScharfeAug 12, 2019
  59. Carlo ArenasAug 12, 2019
  60. Johannes SchindelinAug 10, 2019
  61. Carlo ArenasAug 10, 2019
  62. René ScharfeAug 10, 2019
  63. Carlo ArenasAug 10, 2019
  64. René ScharfeAug 10, 2019
  65. Johannes SchindelinAug 8, 2019
  66. Carlo ArenasAug 9, 2019
  67. Johannes SchindelinAug 9, 2019

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.