2009-08-25 2 views
1

모노 연속의 continuation_store (...)입니다.모노 연속 - store() 후 메모리가 계속 증가합니다.

  1. cont->saved_stack && num_bytes <= cont->stack_alloc_size
    • 직접 다른
    • GC는 무료 메모리를 사용 : 아래의 코드보고에서, 저장소()이 두 가지를 다음처럼 나타납니다 메모리를 사용하고 새로운 메모리를 만드십시오. 나는 반복 continuation_store() 메모리 사용량이 증가 나중 단계에서 거대하고 랙이 GC 작업이 완료 될 때까지를 사용하는 경우

그러나, 이상한 일이다. 왜 이런 일이 일어날 지 설명 할 수 있습니까?

감사

static int 
continuation_store (MonoContinuation *cont, int state, MonoException **e) 
{ 
    MonoLMF *lmf = mono_get_lmf(); 
    gsize num_bytes; 

    if (!cont->domain) 
     *e = mono_get_exception_argument ("cont", "Continuation not initialized"); 
    if (cont->domain != mono_domain_get() || cont->thread_id != GetCurrentThreadId()) 
     *e = mono_get_exception_argument ("cont", "Continuation from another thread or domain"); 

    cont->lmf = lmf; 
    cont->return_ip = __builtin_return_address (0); 
    cont->return_sp = __builtin_frame_address (0); 

    num_bytes = (char*)cont->top_sp - (char*)cont->return_sp; 

    /*g_print ("store: %d bytes, sp: %p, ip: %p, lmf: %p\n", num_bytes, cont->return_sp, cont->return_ip, lmf);*/ 

    if (cont->saved_stack && num_bytes <= cont->stack_alloc_size) 
    { 
     /* clear to avoid GC retention */ 
     if (num_bytes < cont->stack_used_size) 
      memset ((char*)cont->saved_stack + num_bytes, 0, cont->stack_used_size - num_bytes); 
    } 
    else 
    { 
     tasklets_lock(); 
     internal_init(); 
     if (cont->saved_stack) { 
      mono_g_hash_table_remove (keepalive_stacks, cont->saved_stack); 
      mono_gc_free_fixed (cont->saved_stack); 
     } 
     cont->stack_used_size = num_bytes; 
     cont->stack_alloc_size = num_bytes * 1.1; 
     cont->saved_stack = mono_gc_alloc_fixed (cont->stack_alloc_size, NULL); 
     mono_g_hash_table_insert (keepalive_stacks, cont->saved_stack, cont->saved_stack); 
     tasklets_unlock(); 
    } 
    memcpy (cont->saved_stack, cont->return_sp, num_bytes); 

    return state; 
} 

답변

1

참고 기본 뵘 집에서 아무것도하지 않는 mono_gc_free_fixed에 대한 호출 : https://github.com/mono/mono/blob/master/mono/metadata/boehm-gc.c#L528

다른 지점이 바로 keepalive_stacks 해시 테이블에서 메모리를 제거합니다. 이 해시 테이블은 가비지 수집되지 않도록 할당 된 메모리에 대한 참조를 유지합니다. 할당 된 메모리에 대한 포인터가이 해시 테이블에서 제거되면 다음 가비지 수집 중에 다시 회수됩니다. 이 컬렉션은 특정 양의 메모리 할당에 도달하면 나중에 트리거됩니다.

관련 문제