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

Re: [PATCH 13/13] alloc: allow arbitrary repositories for alloc functions

From
Stefan Beller <sbeller@google.com>
Date
May 3, 2018, 17:25 UTC
Message-ID
<CAGZ79ka6rTsRL7e-Dr5TZZeQRDCq6m4C-_DsRpDuuxAh48=-VQ@mail.gmail.com>
In-Reply-To
<20180502135029.051dcaed75b18fb95ae6b28f@google.com>
On Wed, May 2, 2018 at 1:50 PM, Jonathan Tan <jonathantanmy@google.com> wrote:
Show 36 quoted lines
> On Tue,  1 May 2018 14:34:03 -0700
> Stefan Beller <sbeller@google.com> wrote:
>
>> +void *allocate_alloc_state(void)
>> +{
>> +     return xcalloc(1, sizeof(struct alloc_state));
>> +}
>> +
>> +void clear_alloc_state(struct alloc_state *s)
>> +{
>> +     while (s->slab_nr > 0) {
>> +             s->slab_nr--;
>> +             free(s->slabs[s->slab_nr]);
>> +     }
>> +}
>
> These functions are asymmetrical. I understand why it is this way
> (because we use pointers, and we want to use FREE_AND_NULL), but would
> still prefer _INIT and _release().
>
>>  static inline void *alloc_node(struct alloc_state *s, size_t node_size)
>>  {
>>       void *ret;
>> @@ -45,54 +63,56 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)
>>       ret = s->p;
>>       s->p = (char *)s->p + node_size;
>>       memset(ret, 0, node_size);
>> +
>> +     ALLOC_GROW(s->slabs, s->slab_nr + 1, s->slab_alloc);
>> +     s->slabs[s->slab_nr++] = ret;
>> +
>>       return ret;
>>  }
>
> This unconditionally grows the slabs for each node allocation. Shouldn't
> more than one node fit in each slab?

Yes. I'll go with Duy's idea and make it a linked list by using the first object as a pointer to the next slab.

Show 11 quoted lines
>
>> +extern struct alloc_state the_repository_blob_state;
>> +extern struct alloc_state the_repository_tree_state;
>> +extern struct alloc_state the_repository_commit_state;
>> +extern struct alloc_state the_repository_tag_state;
>> +extern struct alloc_state the_repository_object_state;
>
> (Context: these were in alloc.h)
>
> These seem to be used only in object.c, and only in one function - could
> we declare them "static" inside that function instead?
ok
Show 25 quoted lines
>
>> -struct object_parser *object_parser_new(void)
>> +struct object_parser *object_parser_new(int is_the_repo)
>>  {
>>       struct object_parser *o = xmalloc(sizeof(*o));
>>       memset(o, 0, sizeof(*o));
>> +
>> +     if (is_the_repo) {
>> +             o->blob_state = &the_repository_blob_state;
>> +             o->tree_state = &the_repository_tree_state;
>> +             o->commit_state = &the_repository_commit_state;
>> +             o->tag_state = &the_repository_tag_state;
>> +             o->object_state = &the_repository_object_state;
>> +     } else {
>> +             o->blob_state = allocate_alloc_state();
>> +             o->tree_state = allocate_alloc_state();
>> +             o->commit_state = allocate_alloc_state();
>> +             o->tag_state = allocate_alloc_state();
>> +             o->object_state = allocate_alloc_state();
>> +     }
>>       return o;
>>  }
>
> I don't think saving 5 allocations is worth the code complexity (of the
> additional parameter).
Ok, I'll remove this overhead.

Thanks, Stefan

Previous: Jonathan TanNext: Duy Nguyen
Message 20 of 95 in “object store: alloc”
  1. 00/13 object store: allocStefan Beller, May 1, 2018
  2. 01/13 repository: introduce object parser fieldStefan Beller, May 1, 2018
  3. Duy NguyenMay 2, 2018
  4. Stefan BellerMay 2, 2018
  5. Duy NguyenMay 2, 2018
  6. Jonathan TanMay 2, 2018
  7. 02/13 object: add repository argument to create_objectStefan Beller, May 1, 2018
  8. Eric SunshineMay 1, 2018
  9. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 1, 2018
  10. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 1, 2018
  11. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 1, 2018
  12. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 1, 2018
  13. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 1, 2018
  14. Jonathan TanMay 2, 2018
  15. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 1, 2018
  16. Duy NguyenMay 2, 2018
  17. Stefan BellerMay 3, 2018
  18. Duy NguyenMay 3, 2018
  19. Jonathan TanMay 2, 2018
  20. Stefan BellerMay 3, 2018
  21. Duy NguyenMay 3, 2018
  22. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 1, 2018
  23. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 1, 2018
  24. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 1, 2018
  25. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 1, 2018
  26. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 1, 2018
  27. Jonathan TanMay 2, 2018
  28. Duy NguyenMay 2, 2018
  29. Jameson MillerMay 2, 2018
  30. Duy NguyenMay 2, 2018
  31. Jameson MillerMay 2, 2018
  32. Stefan BellerMay 3, 2018
  33. Junio C HamanoMay 7, 2018
  34. Stefan BellerMay 7, 2018
  35. 00/13 object store: allocStefan Beller, May 7, 2018
  36. 02/13 object: add repository argument to create_objectStefan Beller, May 7, 2018
  37. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 7, 2018
  38. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 7, 2018
  39. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 7, 2018
  40. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 7, 2018
  41. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 7, 2018
  42. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 7, 2018
  43. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 7, 2018
  44. Jeff KingMay 8, 2018
  45. Duy NguyenMay 8, 2018
  46. Stefan BellerMay 8, 2018
  47. Jonathan TanMay 8, 2018
  48. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 7, 2018
  49. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 7, 2018
  50. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 7, 2018
  51. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 7, 2018
  52. 01/13 repository: introduce parsed objects fieldStefan Beller, May 7, 2018
  53. Jonathan TanMay 8, 2018
  54. 00/13 object store: allocStefan Beller, May 8, 2018
  55. 01/13 repository: introduce parsed objects fieldStefan Beller, May 8, 2018
  56. 02/13 object: add repository argument to create_objectStefan Beller, May 8, 2018
  57. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 8, 2018
  58. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 8, 2018
  59. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 8, 2018
  60. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 8, 2018
  61. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 8, 2018
  62. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 8, 2018
  63. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 8, 2018
  64. Jonathan TanMay 8, 2018
  65. Stefan BellerMay 8, 2018
  66. Duy NguyenMay 9, 2018
  67. Duy NguyenMay 9, 2018
  68. Stefan BellerMay 9, 2018
  69. Duy NguyenMay 10, 2018
  70. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 8, 2018
  71. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 8, 2018
  72. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 8, 2018
  73. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 8, 2018
  74. 00/13 object store: allocStefan Beller, May 10, 2018
  75. 01/13 repository: introduce parsed objects fieldStefan Beller, May 10, 2018
  76. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 10, 2018
  77. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 10, 2018
  78. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 10, 2018
  79. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 10, 2018
  80. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 10, 2018
  81. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 10, 2018
  82. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 10, 2018
  83. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 10, 2018
  84. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 10, 2018
  85. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 10, 2018
  86. 02/13 object: add repository argument to create_objectStefan Beller, May 10, 2018
  87. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 10, 2018
  88. Jonathan TanMay 10, 2018
  89. Stefan BellerMay 10, 2018
  90. Jonathan TanMay 10, 2018
  91. Stefan BellerMay 10, 2018
  92. alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 11, 2018
  93. Eric SunshineMay 11, 2018
  94. alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 15, 2018
  95. Junio C HamanoMay 16, 2018

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.