{"thread":{"id":"49903","subject":"[PATCH v1] mem_pool: add GIT_TRACE_MEMPOOL support","startedAt":"2018-11-27T19:53:50Z","lastAt":"2018-11-29T15:37:54Z","messageCount":4,"participants":["Ben Peart","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"364156","messageId":"20181127195337.3264-1-peartben@gmail.com","threadId":"49903","inReplyTo":null,"subject":"[PATCH v1] mem_pool: add GIT_TRACE_MEMPOOL support","fromName":"Ben Peart","fromEmail":"peartben@gmail.com","sentAt":"2018-11-27T19:53:37Z","receivedAt":"2018-11-27T19:53:50Z","isPatch":true,"sender":{"key":"benpeart@microsoft.com","avatar":"https://avatars.githubusercontent.com/u/15252029?v=4"},"body":"From: Ben Peart <benpeart@microsoft.com>\n\nAdd tracing around initializing and discarding mempools. In discard report\non the amount of memory unused in the current block to help tune setting\nthe initial_size.\n\nSigned-off-by: Ben Peart <benpeart@microsoft.com>\n---\n\nNotes:\n    Base Ref: * git-trace-mempool\n    Web-Diff: https://github.com/benpeart/git/commit/9ac84bbca2\n    Checkout: git fetch https://github.com/benpeart/git git-trace-mempool-v1 && git checkout 9ac84bbca2\n\n mem-pool.c | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/mem-pool.c b/mem-pool.c\nindex a2841a4a9a..065389aaec 100644\n--- a/mem-pool.c\n+++ b/mem-pool.c\n@@ -5,6 +5,7 @@\n #include \"cache.h\"\n #include \"mem-pool.h\"\n \n+static struct trace_key trace_mem_pool = TRACE_KEY_INIT(MEMPOOL);\n #define BLOCK_GROWTH_SIZE 1024*1024 - sizeof(struct mp_block);\n \n /*\n@@ -48,12 +49,16 @@ void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size)\n \t\tmem_pool_alloc_block(pool, initial_size, NULL);\n \n \t*mem_pool = pool;\n+\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): init (%\"PRIuMAX\") initial size\\n\",\n+\t\tpool, (uintmax_t)initial_size);\n }\n \n void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)\n {\n \tstruct mp_block *block, *block_to_free;\n \n+\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): discard (%\"PRIuMAX\") unused\\n\",\n+\t\tmem_pool, (uintmax_t)(mem_pool->mp_block->end - mem_pool->mp_block->next_free));\n \tblock = mem_pool->mp_block;\n \twhile (block)\n \t{\n\nbase-commit: bb75be6cb916297f271c846f2f9caa3daaaec718\n-- \n2.18.0.windows.1\n\n"},{"id":"364205","messageId":"nycvar.QRO.7.76.6.1811281036300.41@tvgsbejvaqbjf.bet","threadId":"49903","inReplyTo":"20181127195337.3264-1-peartben@gmail.com","subject":"Re: [PATCH v1] mem_pool: add GIT_TRACE_MEMPOOL support","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-11-28T09:37:36Z","receivedAt":"2018-11-28T09:37:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ben,\n\nOn Tue, 27 Nov 2018, Ben Peart wrote:\n\n> From: Ben Peart <benpeart@microsoft.com>\n> \n> Add tracing around initializing and discarding mempools. In discard report\n> on the amount of memory unused in the current block to help tune setting\n> the initial_size.\n> \n> Signed-off-by: Ben Peart <benpeart@microsoft.com>\n> ---\n\nLooks good.\n\nMy only question: should we also trace calls to _alloc(), _calloc() and\n_combine()?\n\nCiao,\nJohannes\n\n> \n> Notes:\n>     Base Ref: * git-trace-mempool\n>     Web-Diff: https://github.com/benpeart/git/commit/9ac84bbca2\n>     Checkout: git fetch https://github.com/benpeart/git git-trace-mempool-v1 && git checkout 9ac84bbca2\n> \n>  mem-pool.c | 5 +++++\n>  1 file changed, 5 insertions(+)\n> \n> diff --git a/mem-pool.c b/mem-pool.c\n> index a2841a4a9a..065389aaec 100644\n> --- a/mem-pool.c\n> +++ b/mem-pool.c\n> @@ -5,6 +5,7 @@\n>  #include \"cache.h\"\n>  #include \"mem-pool.h\"\n>  \n> +static struct trace_key trace_mem_pool = TRACE_KEY_INIT(MEMPOOL);\n>  #define BLOCK_GROWTH_SIZE 1024*1024 - sizeof(struct mp_block);\n>  \n>  /*\n> @@ -48,12 +49,16 @@ void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size)\n>  \t\tmem_pool_alloc_block(pool, initial_size, NULL);\n>  \n>  \t*mem_pool = pool;\n> +\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): init (%\"PRIuMAX\") initial size\\n\",\n> +\t\tpool, (uintmax_t)initial_size);\n>  }\n>  \n>  void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)\n>  {\n>  \tstruct mp_block *block, *block_to_free;\n>  \n> +\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): discard (%\"PRIuMAX\") unused\\n\",\n> +\t\tmem_pool, (uintmax_t)(mem_pool->mp_block->end - mem_pool->mp_block->next_free));\n>  \tblock = mem_pool->mp_block;\n>  \twhile (block)\n>  \t{\n> \n> base-commit: bb75be6cb916297f271c846f2f9caa3daaaec718\n> -- \n> 2.18.0.windows.1\n> \n> \n"},{"id":"364316","messageId":"9ce2df67-d698-0372-4770-32659668ab7e@gmail.com","threadId":"49903","inReplyTo":"nycvar.QRO.7.76.6.1811281036300.41@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v1] mem_pool: add GIT_TRACE_MEMPOOL support","fromName":"Ben Peart","fromEmail":"peartben@gmail.com","sentAt":"2018-11-29T14:09:04Z","receivedAt":"2018-11-29T14:09:08Z","isPatch":true,"sender":{"key":"benpeart@microsoft.com","avatar":"https://avatars.githubusercontent.com/u/15252029?v=4"},"body":"\nOn 11/28/2018 4:37 AM, Johannes Schindelin wrote:\n> Hi Ben,\n>\n> On Tue, 27 Nov 2018, Ben Peart wrote:\n>\n>> From: Ben Peart <benpeart@microsoft.com>\n>>\n>> Add tracing around initializing and discarding mempools. In discard report\n>> on the amount of memory unused in the current block to help tune setting\n>> the initial_size.\n>>\n>> Signed-off-by: Ben Peart <benpeart@microsoft.com>\n>> ---\n> Looks good.\n>\n> My only question: should we also trace calls to _alloc(), _calloc() and\n> _combine()?\n\nI was trying to tune the initial size in my use of the mem_pool and so \nfound this tracing useful to see how much memory was actually being \nused.  I'm inclined to only add tracing as it is needed rather that \nproactively because we think it _might_ be needed.  I suspect _alloc() \nand _calloc() would get very noisy and not add much value.\n\n>\n> Ciao,\n> Johannes\n>\n>> Notes:\n>>      Base Ref: * git-trace-mempool\n>>      Web-Diff: https://github.com/benpeart/git/commit/9ac84bbca2\n>>      Checkout: git fetch https://github.com/benpeart/git git-trace-mempool-v1 && git checkout 9ac84bbca2\n>>\n>>   mem-pool.c | 5 +++++\n>>   1 file changed, 5 insertions(+)\n>>\n>> diff --git a/mem-pool.c b/mem-pool.c\n>> index a2841a4a9a..065389aaec 100644\n>> --- a/mem-pool.c\n>> +++ b/mem-pool.c\n>> @@ -5,6 +5,7 @@\n>>   #include \"cache.h\"\n>>   #include \"mem-pool.h\"\n>>   \n>> +static struct trace_key trace_mem_pool = TRACE_KEY_INIT(MEMPOOL);\n>>   #define BLOCK_GROWTH_SIZE 1024*1024 - sizeof(struct mp_block);\n>>   \n>>   /*\n>> @@ -48,12 +49,16 @@ void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size)\n>>   \t\tmem_pool_alloc_block(pool, initial_size, NULL);\n>>   \n>>   \t*mem_pool = pool;\n>> +\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): init (%\"PRIuMAX\") initial size\\n\",\n>> +\t\tpool, (uintmax_t)initial_size);\n>>   }\n>>   \n>>   void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)\n>>   {\n>>   \tstruct mp_block *block, *block_to_free;\n>>   \n>> +\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): discard (%\"PRIuMAX\") unused\\n\",\n>> +\t\tmem_pool, (uintmax_t)(mem_pool->mp_block->end - mem_pool->mp_block->next_free));\n>>   \tblock = mem_pool->mp_block;\n>>   \twhile (block)\n>>   \t{\n>>\n>> base-commit: bb75be6cb916297f271c846f2f9caa3daaaec718\n>> -- \n>> 2.18.0.windows.1\n>>\n>>\n"},{"id":"364335","messageId":"nycvar.QRO.7.76.6.1811291637330.41@tvgsbejvaqbjf.bet","threadId":"49903","inReplyTo":"9ce2df67-d698-0372-4770-32659668ab7e@gmail.com","subject":"Re: [PATCH v1] mem_pool: add GIT_TRACE_MEMPOOL support","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-11-29T15:37:50Z","receivedAt":"2018-11-29T15:37:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ben,\n\nOn Thu, 29 Nov 2018, Ben Peart wrote:\n\n> On 11/28/2018 4:37 AM, Johannes Schindelin wrote:\n> > Hi Ben,\n> >\n> > On Tue, 27 Nov 2018, Ben Peart wrote:\n> >\n> > > From: Ben Peart <benpeart@microsoft.com>\n> > >\n> > > Add tracing around initializing and discarding mempools. In discard report\n> > > on the amount of memory unused in the current block to help tune setting\n> > > the initial_size.\n> > >\n> > > Signed-off-by: Ben Peart <benpeart@microsoft.com>\n> > > ---\n> > Looks good.\n> >\n> > My only question: should we also trace calls to _alloc(), _calloc() and\n> > _combine()?\n> \n> I was trying to tune the initial size in my use of the mem_pool and so found\n> this tracing useful to see how much memory was actually being used.  I'm\n> inclined to only add tracing as it is needed rather that proactively because\n> we think it _might_ be needed.  I suspect _alloc() and _calloc() would get\n> very noisy and not add much value.\n\nIn other words, YAGNI. Makes sense.\n\nThanks,\nJohannes\n\n> \n> >\n> > Ciao,\n> > Johannes\n> >\n> > > Notes:\n> > >      Base Ref: * git-trace-mempool\n> > >      Web-Diff: https://github.com/benpeart/git/commit/9ac84bbca2\n> > >      Checkout: git fetch https://github.com/benpeart/git\n> > >      git-trace-mempool-v1 && git checkout 9ac84bbca2\n> > >\n> > >   mem-pool.c | 5 +++++\n> > >   1 file changed, 5 insertions(+)\n> > >\n> > > diff --git a/mem-pool.c b/mem-pool.c\n> > > index a2841a4a9a..065389aaec 100644\n> > > --- a/mem-pool.c\n> > > +++ b/mem-pool.c\n> > > @@ -5,6 +5,7 @@\n> > >   #include \"cache.h\"\n> > >   #include \"mem-pool.h\"\n> > >   \n> > > +static struct trace_key trace_mem_pool = TRACE_KEY_INIT(MEMPOOL);\n> > >   #define BLOCK_GROWTH_SIZE 1024*1024 - sizeof(struct mp_block);\n> > >   \n> > >   /*\n> > > @@ -48,12 +49,16 @@ void mem_pool_init(struct mem_pool **mem_pool, size_t\n> > > initial_size)\n> > >     mem_pool_alloc_block(pool, initial_size, NULL);\n> > >   \n> > >   \t*mem_pool = pool;\n> > > +\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): init (%\"PRIuMAX\")\n> > > initial size\\n\",\n> > > +\t\tpool, (uintmax_t)initial_size);\n> > >   }\n> > >   \n> > >   void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)\n> > >   {\n> > >    struct mp_block *block, *block_to_free;\n> > >   +\ttrace_printf_key(&trace_mem_pool, \"mem_pool (%p): discard (%\"PRIuMAX\")\n> > > unused\\n\",\n> > > +\t\tmem_pool, (uintmax_t)(mem_pool->mp_block->end -\n> > > mem_pool->mp_block->next_free));\n> > >    block = mem_pool->mp_block;\n> > >    while (block)\n> > >    {\n> > >\n> > > base-commit: bb75be6cb916297f271c846f2f9caa3daaaec718\n> > > -- \n> > > 2.18.0.windows.1\n> > >\n> > >\n> \n> "}]}