Code Monkey home page Code Monkey logo

Comments (3)

nyh avatar nyh commented on June 3, 2024

One thing in common for these use cases you report is that free() happens while exiting. Can we have a flag set when we're exiting (and there is just a single thread alive) that will allow at that stage free() of any memory from any thread to succeed?
Come to think of it, at that point, free() might as well just be a no-op - it's an utter waste of time to do a real free() at that point, when the program is going down.
I.e., instead of

assert(((reinterpret_cast<uintptr_t>(ptr) >> cpu_id_shift) & 0xff) == cpu_id);

how about
if(((reinterpret_cast<uintptr_t>(ptr) >> cpu_id_shift) & 0xff) != cpu_id) {
if (going_down)
return;
abort(); // or whatever
}

from seastar.

avikivity avatar avikivity commented on June 3, 2024

It is now legal to do cross-cpu frees, although this is quite slow.

from seastar.

tgrabiec avatar tgrabiec commented on June 3, 2024

@avikivity I'm not sure this issue can be closed. We don't handle the case when the "cpu" thread in which the memory was allocated was terminated before we try to free it. In such case the storage for such objects will be removed before free() is called on them and the final free() will result in SIGSEGV.

It's easy to run into this when you have global structures which are destroyed after reactor was shut down.

Example trace:

#0  0x0000000000474271 in load (__m=std::memory_order_relaxed, this=0x7ffff45ff500) at /usr/include/c++/4.9/bits/atomic_base.h:809
#1  load (__m=std::memory_order_relaxed, this=0x7ffff45ff500) at /usr/include/c++/4.9/atomic:390
#2  memory::cpu_pages::free_cross_cpu (this=0x7ffff7fc5800, cpu_id=0x1, ptr=0x6010000505e8) at core/memory.cc:449
#3  0x000000000046728e in deallocate (this=<optimized out>, __p=<optimized out>) at /usr/include/c++/4.9/ext/new_allocator.h:110
#4  deallocate (__a=..., __n=0x1, __p=<optimized out>) at /usr/include/c++/4.9/bits/alloc_traits.h:383
#5  _M_put_node (this=0x6f6c30 <instance+176>, __p=<optimized out>) at /usr/include/c++/4.9/bits/stl_tree.h:389
#6  _M_destroy_node (this=0x6f6c30 <instance+176>, __p=<optimized out>) at /usr/include/c++/4.9/bits/stl_tree.h:438
#7  std::_Rb_tree<std::string, std::string, std::_Identity<std::string>, std::less<std::string>, std::allocator<std::string> >::_M_erase (this=this@entry=0x6f6c30 <instance+176>, __x=<optimized out>) at /usr/include/c++/4.9/bits/stl_tree.h:1247
#8  0x000000000049719f in ~_Rb_tree (this=0x6f6c30 <instance+176>, __in_chrg=<optimized out>) at /usr/include/c++/4.9/bits/stl_tree.h:715
#9  ~set (this=0x6f6c30 <instance+176>, __in_chrg=<optimized out>) at /usr/include/c++/4.9/bits/stl_set.h:90
#10 ~variables_map (this=0x6f6bf0 <instance+112>, __in_chrg=<optimized out>) at /usr/include/boost/program_options/variables_map.hpp:146
#11 destroy_impl (this=0x6f6be8 <instance+104>) at /usr/include/boost/optional/optional.hpp:479
#12 destroy (this=0x6f6be8 <instance+104>) at /usr/include/boost/optional/optional.hpp:439
#13 ~optional_base (this=0x6f6be8 <instance+104>, __in_chrg=<optimized out>) at /usr/include/boost/optional/optional.hpp:268
#14 ~optional (this=0x6f6be8 <instance+104>, __in_chrg=<optimized out>) at /usr/include/boost/optional/optional.hpp:567
#15 ~app_template (this=0x6f6b80 <instance>, __in_chrg=<optimized out>) at ./core/app-template.hh:11
#16 test_runner::~test_runner (this=0x6f6b80 <instance>, __in_chrg=<optimized out>) at tests/test_runner.cc:8
#17 0x00007ffff5005259 in __run_exit_handlers (status=0x0, listp=0x7ffff53886c8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=0x1) at exit.c:82
#18 0x00007ffff50052a5 in __GI_exit (status=<optimized out>) at exit.c:104
#19 0x00007ffff4feaecc in __libc_start_main (main=0x40bf30 <main(int, char**)>, argc=0x1, argv=0x7fffffffda18, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffda08) at libc-start.c:321
#20 0x000000000040e5f5 in _start ()

from seastar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.