Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Why mincore() returns different value of stat ?

2.338 Aufrufe

Veröffentlicht am

Analyzer of MongoDB 2.4 's new feature returned ununderstandable results.
The value of "resident" totally different from "pagesInMemory".
But why ?
-"resident" are coming from STAT.
-"pageInMemory" are coming from mincore().
This slide illustrates this issue.

Veröffentlicht in: Technologie
  • Loggen Sie sich ein, um Kommentare anzuzeigen.

Why mincore() returns different value of stat ?

  1. 1. Why mincore()returns different value of stat ?
  2. 2. mapped file
  3. 3. Interior of a processUser-land Kernel-land virtual mem physical mem mapped area mmap() 1MB mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  4. 4. User-land Kernel-land virtual mem physical mem mapped area page 1 page 2 page 3 page 4 page 5 page 6 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  5. 5. Major page fault User-land Kernel-land virtual mem physical mem mapped areatouch page 1 page 2 page 3 page 4 page 5 page 6 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  6. 6. Major page fault User-land Kernel-land virtual mem physical mem mapped areatouch page 1 page 2 page 2 page 3 Read page from disk page 4 page 5 page 6 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  7. 7. Major page fault User-land Kernel-land virtual mem physical mem mapped area Associate physical memory with virtual memorytouch page 1 page 2 page 2 page 3 page 4 page 5 page 6 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  8. 8. User-land Kernel-land virtual mem physical mem mapped area page 1 page 2touch page 2 page 3 page 3 page 4 page 5 page 6 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  9. 9. User-land Kernel-land virtual mem physical mem mapped area page 1 page 2 page 2 page 3 page 3 page 6 page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  10. 10. swap out (Just image , not actual)
  11. 11. User-land Kernel-land virtual mem physical mem mapped area page 1 page 2 page 2 page 3 page 3 page 6touch page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  12. 12. User-land Kernel-land virtual mem physical mem mapped area page 1 page 2 page 2 page 3 page 3 page 6touch page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  13. 13. User-land Kernel-land virtual mem physical mem mapped area page 1 page 2 page 3 page 3 page 6touch page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  14. 14. User-land Kernel-land virtual mem physical mem mapped area page 1 page 5 page 2 page 3 page 3 page 6touch page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  15. 15. restart the process
  16. 16. Old processUser-land Kernel-land virtual mem physical mem mapped area page 1 page 5 page 2 page 3 page 3 page 6 page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  17. 17. Kill processNothing Kernel-land physical mem page 5 page 3 page 6 page 7 page 1 page 4 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  18. 18. New processUser-land Kernel-land virtual mem physical mem page 5 page 3 page 6 page 7 page 1 page 4 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  19. 19. User-land Kernel-land virtual mem physical mem mapped area page 1 page 5 page 2 page 3 page 3 page 6 page 4 page 7 page 5 page 1 page 6 page 4 page 7 mmap() 1MB page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  20. 20. User-land Kernel-land virtual mem physical mem mapped area page 1 Actually, some pages are page 5 page 3 page 2 page 3 on memory page 6 page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  21. 21. Minor page fault User-land Kernel-land virtual mem physical mem mapped area ONLY associate physical page 1 memory with virtual memory page 5 page 2 page 3 page 3 page 6touch page 4 page 7 page 5 page 1 page 6 page 4 page 7 page 256 mapped file page 1 used by page 2 page 3 FS others page 4 page 5 page 6 page 7 page 256
  22. 22. names & seeing
  23. 23. User-land Kernel-land virtual mem physical memtop mapped area/proc/<pid>/smaps/proc/<pid>/statm page 1 PTE VMA page 5 : page 2 page 3 page 3 page 6 page 4 page 7 page 5 page 1 page 6 page 4 page 7VIRT(virtual) page 256RES(resident) mapped file page 1 used bySHR page 2 FS others page 3 page 4 page 5mincore() page 6 page 7 page 256
  24. 24. Kernel code
  25. 25. fs/proc/task_mmu.c#L447 mm/mincore.c#L108static void smaps_pte_entry(pte_t ptent, unsigned long addr, static void mincore_pte_range(struct vm_area_struct *vma, unsigned long ptent_size, struct mm_walk pmd_t *pmd,*walk) unsigned long addr, unsigned long end,{ unsigned char *vec) struct mem_size_stats *mss = walk->private; { struct vm_area_struct *vma = mss->vma; unsigned long next; pgoff_t pgoff = linear_page_index(vma, addr); spinlock_t *ptl; struct page *page = NULL; pte_t *ptep; int mapcount; ptep = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); if (pte_present(ptent)) { do { page = vm_normal_page(vma, addr, ptent); pte_t pte = *ptep; } else if (is_swap_pte(ptent)) { pgoff_t pgoff; swp_entry_t swpent = pte_to_swp_entry(ptent); next = addr + PAGE_SIZE; if (!non_swap_entry(swpent)) if (pte_none(pte)) mss->swap += ptent_size; mincore_unmapped_range(vma, addr, next, vec); else if (is_migration_entry(swpent)) else if (pte_present(pte)) page = migration_entry_to_page(swpent); *vec = 1; } else if (pte_file(ptent)) { else if (pte_file(pte)) { if (pte_to_pgoff(ptent) != pgoff) pgoff = pte_to_pgoff(pte); mss->nonlinear += ptent_size; *vec = mincore_page(vma->vm_file->f_mapping, pgoff); } } else { /* pte is a swap entry */ swp_entry_t entry = pte_to_swp_entry(pte); if (!page) : return; : if (PageAnon(page)) mss->anonymous += ptent_size; if (page->index != pgoff) mss->nonlinear += ptent_size; mss->resident += ptent_size; : :

×