Tuesday, August 25, 2009

Using Variable Page Sizes without revamping UVM

Here's an idea for a simple change to UVM to allow pmaps to take advantage of larger mappings.

The first part is to add "special" aligned free and inactive page lists apart from the normal free list. These lists contain pages who's physical address is aligned one of a power-of-2 boundaries: 16KB, 64KB, 256KB, 1MB, 4MB should be enough.

The second part is that when uvm_map maps a page from a map entry, it tries to allocate a physical page that conforms to va & (map_entry's alignment_mask). If this is the first page of the entry, it tries to allocate from off of the aligned page lists. If successful, simply use that page. If not, reset the alignment mask to 0.

When a page is other than the first page, see if the page at (first page pa + (new va - first page va)) , if there is a first, page, can be used and use it, if that fails, and this page's (va & alignment mask) == 0, act as if it's a first page.

Otherwise, if the page belonging to (va ^ PAGE_SIZE) and is mapped and (its pa ^ its va) & PAGE_SIZE == 0, try the physical page at (its pa ^ PAGE_SIZE).

Next, if the page is even, try the pa for the previous, or if odd, the pa for the next page...

Should at least in most instances give you contiguous runs of 2 pages, and hopefully more.

1 comment:

  1. You should let MD code specify which free lists to create. No point in creating lists for page sizes the hardware doesn't support.

    I'm a little concerned about the possible explosion in the size of vm_page_t. You wouldn't want pages to be on multiple free lists at any given time. Probably the best is to simply create free lists based on the physical color of the page... e.g. pick the largest page size you want to support, divide that by the smallest page size you want to support, and that gives you the number of buckets. Distribute the free pages among those based on page's PA. You could restructure the existing cache coloring support in UVM to do this, and build cache coloring on top of this (if needed; if you always try to align VA and PA, then it might not matter!)

    If an appropriately aligned page is not available, fall back to the next lower alignment bucket and try again, eventually looping around to the highest alignment bucket and back to the beginning. If you blow the first one for that VA window, you're not going to be able to create large pages in there anyway.

    You only need the multiple free-list thing for the first page -- just fall back onto the prev-PA / next-PA strategy when faulting in adjacent pages.

    ReplyDelete