1

私の目標は、スワップアウトされているページのプロセス ID を見つけることです。Linux カーネル関数swap_writepage()は、バッキング ストアでページをスワップする際に、構造体ページへのポインターを仮引数の一部として受け取ります。すべてのスワップアウト操作は、「kswapd」プロセスによって行われます。関数の引数としてページが渡されるプロセスのpidを見つける必要がありswap_writepage()ます。それを取得するために、 rmap構造を使用して、そのページに関連付けられているすべてのページ テーブル エントリを見つけることができました。

pteまたはstruct pageからpidを取得するにはどうすればよいですか? sytemtap を使用して、関数で引数として受け取った構造体ページ ポインターの値を取得しました。また、関数は、そのページが属するプロセスの pid ではなく、現在実行中のプロセスの pid を出力し、常にkswapdプロセスを出力します。swap_writepage()pid()

4

1 に答える 1

2

最新の Linux で使用されるリバース マッピングの例を次に示します (lxr からコピー):

1435 static int try_to_unmap_anon(struct page *page, enum ttu_flags flags)
1436 {
1437         struct anon_vma *anon_vma;
1438         struct anon_vma_chain *avc;
1439         int ret = SWAP_AGAIN;
1440 
1441         anon_vma = page_lock_anon_vma(page);
1442         if (!anon_vma)
1443                 return ret;
1444 
1445         list_for_each_entry(avc, &anon_vma->head, same_anon_vma) {
1446                 struct vm_area_struct *vma = avc->vma;
1447                 unsigned long address;
1448 
1449                 /*
1450                  * During exec, a temporary VMA is setup and later moved.
1451                  * The VMA is moved under the anon_vma lock but not the
1452                  * page tables leading to a race where migration cannot
1453                  * find the migration ptes. Rather than increasing the
1454                  * locking requirements of exec(), migration skips
1455                  * temporary VMAs until after exec() completes.
1456                  */
1457                 if (PAGE_MIGRATION && (flags & TTU_MIGRATION) &&
1458                                 is_vma_temporary_stack(vma))
1459                         continue;
1460 
1461                 address = vma_address(page, vma);
1462                 if (address == -EFAULT)
1463                         continue;
1464                 ret = try_to_unmap_one(page, vma, address, flags);
1465                 if (ret != SWAP_AGAIN || !page_mapped(page))
1466                         break;
1467         }
1468 
1469         page_unlock_anon_vma(anon_vma);
1470         return ret;
1471 }

この例は、ページのマッピング解除に使用される rmap を示しています。したがって、->mapping フィールドの各匿名ページは anon_vma オブジェクトを保持します。anon_vma は、ページがマップされる vma エリアのリストを保持します。vma があると mm があり、mm があると task_struct があります。それでおしまい。ご不明な点がございましたら、こちらのイラストをご覧ください 逆マッピング

Daniel P. Bovet、Marco Cesati Linux カーネルの理解 第 17.2 章

于 2015-04-15T18:31:34.123 に答える