Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] refactoring: drop excess 16Kb bss buffer
@ 2020-01-09 20:06 Sergey Kaplun
  2020-01-09 20:15 ` Cyrill Gorcunov
  2020-01-13 22:00 ` Vladislav Shpilevoy
  0 siblings, 2 replies; 4+ messages in thread
From: Sergey Kaplun @ 2020-01-09 20:06 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Vladislav Shpilevoy

We already have 12Kb thread-safe static buffer
in `lib/small/small/static.h`, that can be used instead of 16Kb
bss buffer in `src/lib/core/backtrace.cc` for backtrace payload.

Closes #4650
---

branch: https://github.com/tarantool/tarantool/tree/skaplun/drop-bss-buff
issue: https://github.com/tarantool/tarantool/issues/4650

 src/lib/core/backtrace.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/lib/core/backtrace.cc b/src/lib/core/backtrace.cc
index 77f77b05c..eabd986df 100644
--- a/src/lib/core/backtrace.cc
+++ b/src/lib/core/backtrace.cc
@@ -47,6 +47,7 @@
 #include <libunwind.h>
 
 #include "small/region.h"
+#include "small/static.h"
 /*
  * We use a global static buffer because it is too late to do any
  * allocation when we are printing backtrace and fiber stack is
@@ -55,8 +56,6 @@
 
 #define BACKTRACE_NAME_MAX 200
 
-static char backtrace_buf[4096 * 4];
-
 static __thread struct region cache_region;
 static __thread struct mh_i64ptr_t *proc_cache = NULL;
 
@@ -140,8 +139,9 @@ backtrace()
 	unw_getcontext(&unw_context);
 	unw_cursor_t unw_cur;
 	unw_init_local(&unw_cur, &unw_context);
+	char *backtrace_buf = (char *)static_alloc(SMALL_STATIC_SIZE);
 	char *p = backtrace_buf;
-	char *end = p + sizeof(backtrace_buf) - 1;
+	char *end = p + SMALL_STATIC_SIZE - 1;
 	int unw_status;
 	*p = '\0';
 	while ((unw_status = unw_step(&unw_cur)) > 0) {
-- 
2.24.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] refactoring: drop excess 16Kb bss buffer
  2020-01-09 20:06 [Tarantool-patches] [PATCH] refactoring: drop excess 16Kb bss buffer Sergey Kaplun
@ 2020-01-09 20:15 ` Cyrill Gorcunov
  2020-01-09 20:18   ` Cyrill Gorcunov
  2020-01-13 22:00 ` Vladislav Shpilevoy
  1 sibling, 1 reply; 4+ messages in thread
From: Cyrill Gorcunov @ 2020-01-09 20:15 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches, Vladislav Shpilevoy

On Thu, Jan 09, 2020 at 11:06:36PM +0300, Sergey Kaplun wrote:
> We already have 12Kb thread-safe static buffer
> in `lib/small/small/static.h`, that can be used instead of 16Kb
> bss buffer in `src/lib/core/backtrace.cc` for backtrace payload.
> 
> Closes #4650
> ---
> 
> branch: https://github.com/tarantool/tarantool/tree/skaplun/drop-bss-buff
> issue: https://github.com/tarantool/tarantool/issues/4650
> 
>  src/lib/core/backtrace.cc | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/lib/core/backtrace.cc b/src/lib/core/backtrace.cc
> index 77f77b05c..eabd986df 100644
> --- a/src/lib/core/backtrace.cc
> +++ b/src/lib/core/backtrace.cc
> @@ -47,6 +47,7 @@
>  #include <libunwind.h>
>  
>  #include "small/region.h"
> +#include "small/static.h"
>  /*
>   * We use a global static buffer because it is too late to do any
>   * allocation when we are printing backtrace and fiber stack is
> @@ -55,8 +56,6 @@
>  
>  #define BACKTRACE_NAME_MAX 200
>  
> -static char backtrace_buf[4096 * 4];
> -
>  static __thread struct region cache_region;
>  static __thread struct mh_i64ptr_t *proc_cache = NULL;
>  
> @@ -140,8 +139,9 @@ backtrace()
>  	unw_getcontext(&unw_context);
>  	unw_cursor_t unw_cur;
>  	unw_init_local(&unw_cur, &unw_context);
> +	char *backtrace_buf = (char *)static_alloc(SMALL_STATIC_SIZE);
>  	char *p = backtrace_buf;
> -	char *end = p + sizeof(backtrace_buf) - 1;
> +	char *end = p + SMALL_STATIC_SIZE - 1;
>  	int unw_status;
>  	*p = '\0';
>  	while ((unw_status = unw_step(&unw_cur)) > 0) {

static_alloc has all rights to return NULL, thus you better add
a test at least.

NAK for a while

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] refactoring: drop excess 16Kb bss buffer
  2020-01-09 20:15 ` Cyrill Gorcunov
@ 2020-01-09 20:18   ` Cyrill Gorcunov
  0 siblings, 0 replies; 4+ messages in thread
From: Cyrill Gorcunov @ 2020-01-09 20:18 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches, Vladislav Shpilevoy

On Thu, Jan 09, 2020 at 11:15:33PM +0300, Cyrill Gorcunov wrote:
...
> > @@ -140,8 +139,9 @@ backtrace()
> >  	unw_getcontext(&unw_context);
> >  	unw_cursor_t unw_cur;
> >  	unw_init_local(&unw_cur, &unw_context);
> > +	char *backtrace_buf = (char *)static_alloc(SMALL_STATIC_SIZE);
> >  	char *p = backtrace_buf;
> > -	char *end = p + sizeof(backtrace_buf) - 1;
> > +	char *end = p + SMALL_STATIC_SIZE - 1;
> >  	int unw_status;
> >  	*p = '\0';
> >  	while ((unw_status = unw_step(&unw_cur)) > 0) {
> 
> static_alloc has all rights to return NULL, thus you better add
> a test at least.
> 
> NAK for a while

Surely it should not fail for this exact size such as SMALL_STATIC_SIZE,
still the situation may change at future, so as a minimum we need
some kind of assert(backtrace_buf != NULL);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] refactoring: drop excess 16Kb bss buffer
  2020-01-09 20:06 [Tarantool-patches] [PATCH] refactoring: drop excess 16Kb bss buffer Sergey Kaplun
  2020-01-09 20:15 ` Cyrill Gorcunov
@ 2020-01-13 22:00 ` Vladislav Shpilevoy
  1 sibling, 0 replies; 4+ messages in thread
From: Vladislav Shpilevoy @ 2020-01-13 22:00 UTC (permalink / raw)
  To: Sergey Kaplun, tarantool-patches

Hi! Thanks for the patch!

> diff --git a/src/lib/core/backtrace.cc b/src/lib/core/backtrace.cc
> index 77f77b05c..eabd986df 100644
> --- a/src/lib/core/backtrace.cc
> +++ b/src/lib/core/backtrace.cc
> @@ -55,8 +56,6 @@
>  
>  #define BACKTRACE_NAME_MAX 200
>  
> -static char backtrace_buf[4096 * 4];
> -
>  static __thread struct region cache_region;
>  static __thread struct mh_i64ptr_t *proc_cache = NULL;
>  
> @@ -140,8 +139,9 @@ backtrace()
>  	unw_getcontext(&unw_context);
>  	unw_cursor_t unw_cur;
>  	unw_init_local(&unw_cur, &unw_context);
> +	char *backtrace_buf = (char *)static_alloc(SMALL_STATIC_SIZE);

Perhaps it is worth increasing SMALL_STATIC_SIZE with 4096
additional bytes so as not to decrease backtrace buffer size.
Backtrace was using 4096 * 4, while SMALL_STATIC_SIZE is
4096 * 3.

On the other hand, increase of static buffer size would make
total size of BSS section even bigger than before the patch,
because the static buffer is thread local. So + 4096 for this
buffer means at least + 4096 * 3 because we have at least 3
threads.

I am ok with both options. Because I don't know whether do we
really need so big buffer for a backtrace or not.

Also Cyrill is right, it is worth adding an assertion
that static_alloc does not fail.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-13 22:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-09 20:06 [Tarantool-patches] [PATCH] refactoring: drop excess 16Kb bss buffer Sergey Kaplun
2020-01-09 20:15 ` Cyrill Gorcunov
2020-01-09 20:18   ` Cyrill Gorcunov
2020-01-13 22:00 ` Vladislav Shpilevoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox