Skip to content

Instantly share code, notes, and snippets.

@devlights
Last active June 27, 2018 05:11
Show Gist options
  • Save devlights/439cab73f4eb3d7c2f78246fff5d2c41 to your computer and use it in GitHub Desktop.
Save devlights/439cab73f4eb3d7c2f78246fff5d2c41 to your computer and use it in GitHub Desktop.
[.NET][WPF] Page Fault が大量に発生して挙動が遅くなる?? のメモ (ページフォールト, virtual memory, パフォーマンス, Performance issue)

参考情報

  1. Why my WPF application becomes slow after a while of minimizing?
  2. 第2回 Visual Studioのプロファイラを使って性能評価を行う

拙訳

1に上げた参考情報の回答部分を引用と拙訳

This is not a property of WPF, it's a property of virtual memory.

これはWPFの特性じゃなくて、仮想メモリの特性です。

Basically, modern operating systems attempt to make the programs that are running as fast as possible - but they also allow many programs to run at once, more than all of their memory could fit into your measely RAM at once. So when the OS sees that a running program needs to allocate a new page of memory, but RAM is full of pages already, it kicks one of the pages (preferring ones that have not been used in a while) to the hard disk, into a file called the page file.

基本的に、最近のOSはプログラムを出来る限り速く動作させようとしますが、同時にたくさんのプログラムを動作させる必要や大量のメモリも必要とします。そこで、OSは動作しているプログラムが新たなメモリページの確保を必要としたとき、RAMが既にページングできる分が無かったら、一部のメモリページをハードディスクに追い出してページファイルと呼ばれるファイルキャッシュの中に入れます。

When the program for which that page of memory belonged to attempts to access it, this is called a 'page fault' - the OS detects the page is not in RAM but on disk, and has to read it into RAM before execution continues. This is relatively slow since reading from the hard disk is slower than reading from RAM. If a program hasn't been running for some time, it's conceivable that ALL of its pages have been paged out to RAM - and so it will be slow until it stops hitting page faults.

プログラムが上記のキャッシュ化されたメモリページにアクセスしようとすることを「ページフォールト」と呼びます。OSはRAM上にそのメモリがなくてハードディスク上にあると検知すると、プログラムの処理を実行する前に読み出してメモリ上に上げます。この挙動は、メモリから直接読むよりも遅いです。もし当該プログラムが、しばらく前から動いていない場合、そのプログラムが使うメモリページ全部がRAM上から追い出されていることが考えられ、当然ページフォールトにヒットしている限り遅くなるでしょう。

@devlights
Copy link
Author

以下、質問を書いた人がうまくいったと報告した内容の引用と拙訳

Thank you @Patashu, that's exactly what i wanted to know. to solve this problem, i avoid minimizing my App, so i send it out of the screen (set Position -1000), and made a timer that activate the window each 10 minutes, so it keeps on RAM, and it works fine, thank you.

ありがとう @Patashu、これこそ私が知りたかったことです。問題を解決するために、私はアプリケーションを最小化することを避けて、画面をスクリーン外に送るようにし、タイマーを設置して10分ごとにWindowをActiveにするようにしました。するとRAMに残り続けて、うまく動いています。ありがとう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment