eChung00
eChung00

Reputation: 633

How can we reduce page fault

I learned that on virtual memory, the penalty caused by page fault is expensive. How do we reduce this page fault??I saw one argument that says a smaller page size reduces the page fault. Why is this true??

Upvotes: 2

Views: 3380

Answers (1)

Eric J.
Eric J.

Reputation: 150108

To consider why smaller page sizes might reduce fault rates, consider and extreme example in the other direction. Assume you have 2GB of physical memory and pages that are 1GB in size. As soon as you allocate more than 2GB of virtual memory, you will have at least 3 pages, of which only 2 will fit in memory. More than 1-in-3 memory accesses would cause a page fault.

Having smaller page sizes means you have more granularity, allowing the OS to perform more targeted swapping.

Of course (isn't it always that way), there are trade-offs. For one, smaller page sizes means more pages, which means more overhead to manage pages.

One method to reduce page faults is to use a memory allocator that is smart about allocating memory likely to be used at the same time on the same pages.

For example, at the application level, bucket allocators (example) allow an application to request a chunk of memory that the application will then allocate from. The application can use the bucket for specific phases of program execution and then release the bucket as a unit. This helps to minimize memory fragmentation that might cause active and inactive parts of the program from receiving memory allocations from the same physical page.

Upvotes: 2

Related Questions