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

Re: [RFC PATCH] trace2 API: don't save a copy of constant "thread_name"

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Oct 12, 2022, 13:31 UTC
Message-ID
<e138b178-99d9-e537-2cb1-c240962a35f2@jeffhostetler.com>
In-Reply-To
<221011.86h70ao4g6.gmgdl@evledraar.gmail.com>
On 10/11/22 9:31 AM, Ævar Arnfjörð Bjarmason wrote:
Show 12 quoted lines
> 
> On Mon, Oct 10 2022, Jeff Hostetler wrote:
> 
>> On 10/7/22 6:03 AM, Ævar Arnfjörð Bjarmason wrote:
>>> On Thu, Oct 06 2022, Junio C Hamano wrote:
>>>
>>>> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>>>>
>>>>> A cleaned up version of the test code I had on top of "master", RFC
>>>>> because I may still be missing some context here. E.g. maybe there's a
>>>>> plan to dynamically construct these thread names?
>>>>
[...]
Show 23 quoted lines
> I left more extensive commentary in the side-thread in
> https://lore.kernel.org/git/221011.86lepmo5dn.gmgdl@evledraar.gmail.com/,
> just a quick reply here.
> 
>> WRT optimizing memory usage.  We're talking about ~25 byte buffer
>> per thread.  Most commands execute in 1 thread -- if they read the
>> index they may have ~10 threads (depending on the size of the index
>> and if preload-index is enabled).  So, I don't think we really need
>> to optimize this.  Threading is used extensively in fsmonitor-daemon,
>> but it creates a fixed thread-pool at startup, so it may have ~12
>> threads.  Again, not worth optimizing for the thread-name field.
> 
> Yes, I agree it's not worth optimizing.
> 
> The reason for commenting on this part is that it isn't clear to me why
> your proposed patch then isn't doing the more obvious "it's not worth
> optimizing" pattern, per Junio's [1] comment on the initial version.
> 
> The "flex array" method is seemingly taking pains to reduce the runtime
> memory use of these by embedding this string in the space reserved for
> the struct.
> 
> So it's just meant as a question for you & the proposed patch.

I think we're converging on some common understanding (and I think we've gone around on this topic more than enough). :-)

I really was just trying to get rid of the strbuf and make it a fixed string -- I chose a flex-array rather than just detaching the buffer from a local in the thread-start code. I should have done the latter. I saw the flex-array as a fixed-size object that can't be replaced or extended (without recreating the thread-local storage) -- yes, people could overwrite existing bytes in-place in the flex-array, but who does that??

I understood what you were asking (illustrated in your RFC). That is, I understood the "what/how" you wanted to do to refactor / redesign the field, but I couldn't understand the "why". That is, why you've taken such interest in this field (and such a relatively unimportant change). We've spent nearly a week discussing it and we both agree that the optimization that I didn't suggest isn't worth doing. (I'm paraphrasing slightly.) :-)

So, rather than continuing with the back-n-forth, let me skip over the remaining questions in this thread and prepare a re-roll. Hopefully, I can simplify and more clearly explain the method to my madness and we can move on.

Show 6 quoted lines
>> Now, if you want to optimize over all trace2 events (a completely
>> different topic), you could create a large scratch strbuf buffer in
>> each thread context and use it so that we don't have to malloc/free
>> during each trace message.  That might be worth while.
> 
> *nod*
I'll make a note to revisit this idea in a future series.

Thanks Jeff

Previous: Ævar Arnfjörð BjarmasonNext: Jeff Hostetler
Message 19 of 73 in “Trace2 timers and counters and some cleanup”
  1. 0/9 Trace2 timers and counters and some cleanupJeff Hostetler via GitGitGadget, Oct 4, 2022
  2. 1/9 builtin/merge-file: fix compiler warning on MacOS with clang 11.0.0Jeff Hostetler via GitGitGadget, Oct 4, 2022
  3. 2/9 builtin/unpack-objects.c: fix compiler warning on MacOS with clang 11.0.0Jeff Hostetler via GitGitGadget, Oct 4, 2022
  4. 3/9 trace2: use size_t alloc,nr_open_regions in tr2tls_thread_ctxJeff Hostetler via GitGitGadget, Oct 4, 2022
  5. 4/9 tr2tls: clarify TLS terminologyJeff Hostetler via GitGitGadget, Oct 4, 2022
  6. 5/9 trace2: rename trace2 thread_name argument as name_hintJeff Hostetler via GitGitGadget, Oct 4, 2022
  7. 6/9 trace2: convert ctx.thread_name to flex arrayJeff Hostetler via GitGitGadget, Oct 4, 2022
  8. Ævar Arnfjörð BjarmasonOct 5, 2022
  9. Jeff HostetlerOct 6, 2022
  10. Jeff HostetlerOct 10, 2022
  11. Junio C HamanoOct 5, 2022
  12. Ævar Arnfjörð BjarmasonOct 6, 2022
  13. Junio C HamanoOct 6, 2022
  14. trace2 API: don't save a copy of constant "thread_name"Ævar Arnfjörð Bjarmason, Oct 7, 2022
  15. Junio C HamanoOct 7, 2022
  16. Ævar Arnfjörð BjarmasonOct 7, 2022
  17. Jeff HostetlerOct 10, 2022
  18. Ævar Arnfjörð BjarmasonOct 11, 2022
  19. Jeff HostetlerOct 12, 2022
  20. Jeff HostetlerOct 10, 2022
  21. Ævar Arnfjörð BjarmasonOct 11, 2022
  22. Junio C HamanoOct 11, 2022
  23. Jeff HostetlerOct 10, 2022
  24. 7/9 api-trace2.txt: elminate section describing the public trace2 APIJeff Hostetler via GitGitGadget, Oct 4, 2022
  25. 8/9 trace2: add stopwatch timersJeff Hostetler via GitGitGadget, Oct 4, 2022
  26. 9/9 trace2: add global counter mechanismJeff Hostetler via GitGitGadget, Oct 4, 2022
  27. Ævar Arnfjörð BjarmasonOct 5, 2022
  28. Jeff HostetlerOct 6, 2022
  29. Derrick StoleeOct 6, 2022
  30. 0/7 Trace2 timers and counters and some cleanupJeff Hostetler via GitGitGadget, Oct 12, 2022
  31. 1/7 trace2: use size_t alloc,nr_open_regions in tr2tls_thread_ctxJeff Hostetler via GitGitGadget, Oct 12, 2022
  32. 2/7 tr2tls: clarify TLS terminologyJeff Hostetler via GitGitGadget, Oct 12, 2022
  33. Junio C HamanoOct 13, 2022
  34. 3/7 api-trace2.txt: elminate section describing the public trace2 APIJeff Hostetler via GitGitGadget, Oct 12, 2022
  35. 4/7 trace2: rename the thread_name argument to trace2_thread_startJeff Hostetler via GitGitGadget, Oct 12, 2022
  36. Ævar Arnfjörð BjarmasonOct 12, 2022
  37. Jeff HostetlerOct 20, 2022
  38. Junio C HamanoOct 13, 2022
  39. 5/7 trace2: convert ctx.thread_name from strbuf to pointerJeff Hostetler via GitGitGadget, Oct 12, 2022
  40. Junio C HamanoOct 13, 2022
  41. 7/7 trace2: add global counter mechanismJeff Hostetler via GitGitGadget, Oct 12, 2022
  42. 6/7 trace2: add stopwatch timersJeff Hostetler via GitGitGadget, Oct 12, 2022
  43. Junio C HamanoOct 13, 2022
  44. Jeff HostetlerOct 20, 2022
  45. 0/8 Trace2 timers and counters and some cleanupJeff Hostetler via GitGitGadget, Oct 20, 2022
  46. 1/8 trace2: use size_t alloc,nr_open_regions in tr2tls_thread_ctxJeff Hostetler via GitGitGadget, Oct 20, 2022
  47. 2/8 tr2tls: clarify TLS terminologyJeff Hostetler via GitGitGadget, Oct 20, 2022
  48. 4/8 trace2: rename the thread_name argument to trace2_thread_startJeff Hostetler via GitGitGadget, Oct 20, 2022
  49. 3/8 api-trace2.txt: elminate section describing the public trace2 APIJeff Hostetler via GitGitGadget, Oct 20, 2022
  50. 5/8 trace2: improve thread-name documentation in the thread-contextJeff Hostetler via GitGitGadget, Oct 20, 2022
  51. Ævar Arnfjörð BjarmasonOct 20, 2022
  52. Jeff HostetlerOct 20, 2022
  53. 6/8 trace2: convert ctx.thread_name from strbuf to pointerJeff Hostetler via GitGitGadget, Oct 20, 2022
  54. 7/8 trace2: add stopwatch timersJeff Hostetler via GitGitGadget, Oct 20, 2022
  55. Junio C HamanoOct 20, 2022
  56. Jeff HostetlerOct 20, 2022
  57. Junio C HamanoOct 20, 2022
  58. Jeff HostetlerOct 21, 2022
  59. 8/8 trace2: add global counter mechanismJeff Hostetler via GitGitGadget, Oct 20, 2022
  60. 0/8 Trace2 timers and counters and some cleanupJeff Hostetler via GitGitGadget, Oct 24, 2022
  61. 1/8 trace2: use size_t alloc,nr_open_regions in tr2tls_thread_ctxJeff Hostetler via GitGitGadget, Oct 24, 2022
  62. Junio C HamanoOct 24, 2022
  63. Derrick StoleeOct 25, 2022
  64. Junio C HamanoOct 25, 2022
  65. 3/8 api-trace2.txt: elminate section describing the public trace2 APIJeff Hostetler via GitGitGadget, Oct 24, 2022
  66. 7/8 trace2: add stopwatch timersJeff Hostetler via GitGitGadget, Oct 24, 2022
  67. 2/8 tr2tls: clarify TLS terminologyJeff Hostetler via GitGitGadget, Oct 24, 2022
  68. 8/8 trace2: add global counter mechanismJeff Hostetler via GitGitGadget, Oct 24, 2022
  69. 6/8 trace2: convert ctx.thread_name from strbuf to pointerJeff Hostetler via GitGitGadget, Oct 24, 2022
  70. 5/8 trace2: improve thread-name documentation in the thread-contextJeff Hostetler via GitGitGadget, Oct 24, 2022
  71. 4/8 trace2: rename the thread_name argument to trace2_thread_startJeff Hostetler via GitGitGadget, Oct 24, 2022
  72. Derrick StoleeOct 25, 2022
  73. Junio C HamanoOct 25, 2022

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.