Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is red black tree in kernel not protected?

In Linux kernel, to store the memory regions of a process, Linux uses both a linked list and a red-black tree. find_vma is a function which locates the first memory region whose vm_end field is greater than the passed address through red black tree. However, I find it there is has no protection (like a lock) for the red black tree inside find_vma(). What if another thread calls rb_erase function to delete some element on the tree at the same?

like image 235
HuangJie Avatar asked Oct 31 '22 14:10

HuangJie


1 Answers

Yes , find_vma function call is protected from concurrent access via semaphore. In scheduler also function is used with semaphore calls.

        2209         down_read(&mm->mmap_sem);
        2210         vma = find_vma(mm, start);
        ....
                     up_read(&mm->mmap_sem);



    mmap_sem is used to protect this function call which is a read-write semaphore.
    struct rw_semaphore mmap_sem; defined inside struct mm_struct.
like image 163
anshul garg Avatar answered Nov 02 '22 10:11

anshul garg