Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果协程释放将内存也同时释放,为什么会崩溃 #35

Closed
enochi opened this issue Jan 30, 2023 · 2 comments
Closed

如果协程释放将内存也同时释放,为什么会崩溃 #35

enochi opened this issue Jan 30, 2023 · 2 comments

Comments

@enochi
Copy link

enochi commented Jan 30, 2023

我的使用场景是会同时创建大量协程,然后也会有大量释放,因为我们协程一直是保存在free_list里,导致内存始终是在一个高位,即使没什么负载的时候也是这样,对运维很困惑.所以就想把协程释放的同时内存也一起释放.
改动的地方在下面,不知道有什么问题,不管用mmap还是malloc模式,情况都是一样的
`/*

  • Free the stack for the current thread
    */
    void _st_stack_free(_st_stack_t ts)
    {
    if (!ts)
    return;
    _st_delete_stk_segment(ts->vaddr,ts->vaddr_size);
    // /
    Put the stack on the free list */
    // ST_APPEND_LINK(&ts->links, _st_free_stacks.prev);
    // _st_num_free_stacks++;
    }`

Program received signal SIGSEGV, Segmentation fault.
_int_free (av=0x7ffff7498760 <main_arena>, p=0xe5aff0, have_lock=0) at malloc.c:4010
4010 p->fd = fwd;
(gdb) bt
#0 _int_free (av=0x7ffff7498760 <main_arena>, p=0xe5aff0, have_lock=0) at malloc.c:4010
#1 0x0000000000687dfb in _st_delete_stk_segment (vaddr=0xe5b000 "8\217I\367\377\177", size=73728) at stk.c:157
#2 0x0000000000687db9 in _st_stack_free (ts=0xe50830) at stk.c:114
#3 0x0000000000686dfb in st_thread_exit (retval=0x0) at sched.c:303
#4 0x0000000000686ff0 in _st_thread_main () at sched.c:366
#5 0x000000000068784c in st_thread_create (start=0x5d584e SrsFastCoroutine::pfn(void*), arg=0x1e08400, joinable=1, stk_size=65536) at sched.c:694

@enochi
Copy link
Author

enochi commented Feb 20, 2023

明白了,上面之所以不行是因为_st_thread_t结构体保存在stack里,之后切换回来还会使用,不能在协程退出的时候释放,如果想要实现上述功能,可以在_st_vp_check_clock里添加释放协程的操作.

@enochi enochi closed this as completed Feb 20, 2023
@winlinvip
Copy link
Member

既然已经搞明白了,来个Patch撒,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants