1

Under Windows, the kernel can swap a physical memory page to a page in the paging file.

For simplicity, we assume there is only one paging file.

As far as I understand, the paging file consists of pages which have the same size of a physical memory page. i.e. 4K.

I just wonder:

How does the kernel know which page in the paging file is free to store?

(Free here means the page in the paging file doesn't previously store another physical memory page.)

xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • 1
    Physical memory is mapped to virtual memory whenever there's a context switch, and whenever a process page faults and is entitled to more memory. As such, the kernel has an idea of the "last used" time of a page of physical memory and can presumably chose to evict those to disk which haven't been requested in a while. – Kerrek SB Dec 22 '14 at 10:50
  • This question appears to be off-topic because it is about operating system design and is not a specific programming problem. If you can rephrase this in terms of a programming problem (e.g. code that needs to know this information in order to function properly), then it would be on topic. – Raymond Chen Dec 29 '14 at 02:08
  • http://stackoverflow.com/questions/18431261/how-does-x86-paging-work – Ciro Santilli OurBigBook.com Oct 27 '15 at 08:52

2 Answers2

1

At the risk of gross oversimplification . . . the usual approach in implementing virtual memory is that disk is the primary storage. Unless there is a mapping to a file, a virtual page does not exist. That mapping remains fixed for the life of the process.

The virtual memory on disk gets mapped to physical memory when available.

The kernel maintains some data structure (e.g. a bitmap) to indicate the free areas of the page file and other structures to maintain the mapping of logical addresses to the files.

user3344003
  • 20,574
  • 3
  • 26
  • 62
1

I believe you are asking about page replacement algorithms within memory management.

When the operating system needs to save a new page in memory and keep track of its information on the paging file (also known as the page table), there's no guarantee that there will be a free spot --meaning that other pages' information might have taken up all of it. In that case, the OS will have to evict an existing page. The OS doesn't need free space since, if there isn't any, it will make it.

If you're interested in learning more (this is a pretty large topic), you may find the lecture notes from NYU's "Operating Systems" class helpful. This is the demand paging unit, and further below you can read about a few page replacement algorithms ("WS Clock" and "Aging" are probably the most important).

Hopefully this is helpful!

aralar
  • 3,022
  • 7
  • 29
  • 44