Called when the last reference to the mm is dropped: either by a lazy thread or by mmput. Free the page directory and the mm.
时间: 2024-03-10 18:46:37 浏览: 90
In the Linux kernel, the function called when the last reference to the mm is dropped is `mmput()`. This function decrements the reference count of the mm and releases it if the count reaches zero. When the mm is released, the function `mm_release()` is called. This function is responsible for freeing the page directory and the mm.
Here are the steps involved in freeing the page directory and the mm:
1. First, you need to obtain the page table directory pointer (pgd) from the mm.
```
pgd_t *pgd = mm->pgd;
```
2. Next, you need to release the page table pages by calling the function `pgd_free()`. This function takes the pgd pointer and the address space identifier (asid) as arguments.
```
pgd_free(mm, pgd, mm->asid);
```
Note that the asid is a unique identifier for the address space that is used to flush the TLB (Translation Lookaside Buffer) entries.
3. Finally, you can release the memory used by the mm by calling the function `kmem_cache_free()`. This function takes the pointer to the memory block and the cache descriptor as arguments.
```
kmem_cache_free(mm_cachep, mm);
```
Here, `mm_cachep` is the cache descriptor for the mm_struct cache.
That's it! You have now freed the page directory and the mm in the Linux kernel.
阅读全文