From owner-freebsd-hackers Thu Aug 2 11: 3:50 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from colnta.acns.ab.ca (h24-68-206-125.sbm.shawcable.net [24.68.206.125]) by hub.freebsd.org (Postfix) with ESMTP id 98A6537B42C for ; Thu, 2 Aug 2001 11:03:40 -0700 (PDT) (envelope-from davidc@colnta.acns.ab.ca) Received: (from davidc@localhost) by colnta.acns.ab.ca (8.11.4/8.11.3) id f72I3Zg11539 for freebsd-hackers@freebsd.org; Thu, 2 Aug 2001 12:03:35 -0600 (MDT) (envelope-from davidc) Date: Thu, 2 Aug 2001 12:03:35 -0600 From: Chad David To: freebsd-hackers@freebsd.org Subject: Page Coloring Message-ID: <20010802120335.A11520@colnta.acns.ab.ca> Mail-Followup-To: freebsd-hackers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG If I added this to a man page would I be telling the truth :). Note, these are my notes and not the exact text that I would add, and I have not bother with anything to do with object coloring etc. I just want to make sure I've got this part down. Chad page coloring ------------------------------------------- The general idea behind page color is to prevent the L2 cache from dumping pages in use for any given object when it loads the next required page. To start with you have to consider how the L2 addresses pages. If the L2 is 64k, to choose an easy number, then it can address at most 16 pages. If each page is 4096 bytes, then the first twelve bits of the address do not affect the page, but instead the contents of the page. The next four bits specifiy the page number, and the remaining sixteen bits can be ignored. u - unused. p - page number. b - page bytes. b11111111111111111111111111111111 or 0x0000FBBB uuuuuuuuuuuuuuuuppppbbbbbbbbbbbb uuuupbbb Note: only bits 13 - 16 affect L2 page addressing (256k L2). If the first page of an object is at 0x0A00F000 then the L2 will see page number 16 (0xF or b1111xxxxxxxxxxxx). If the second page of an object is at 0x0B00F000 the the page number will colide with the first page, and the first page will be removed from the L2 cache. If on the other hand the second page was allocated at 0xB00A000 then its page number would be 0xA and the first page would remain in the cache. FreeBSD creates as many colors as there are pages in the L2 cache, and then breaks up the physical memory as vm_pages are added into the various colors. When a object requests a new page, it asks for a pages of the color of the pages index into the object (there is a little more to it, but in general that is what it does). So page 1 would ask for color 1, page 2 would ask for color 2 and so on. Page coloring is calculated as follows: m->pc = (pa >> PAGE_SHIFT) & PQ_L2_MASK pa = physical address PAGE_SHIFT = 12 (LOG2 page size = 4096) PQ_L2_MASK = PQ_L2_SIZE - 1 (let PQ_L2_SIZE = 64) let pa = 0x00FF0000 m->pc = (0x00FF0000 >> 12) & 0x0000003F m->pc = 0x00000FF0 & 0x0000003F m->pc = 0x00000030 The page queue that a page is on is the queue number plus the page color. If the page is on the free queue then m->queue = PQ_FREE + m->pc. To determine the base queue you simple subtract the page color. The following is often seen in the code: if ((m->queue - m->pc) == PQ_FREE) {..}. A given page color will be used every PQ_L2_SIZE pages where PQ_L2_SIZE is the PQ_CACHESIZE (L2 cache size) divided by the page size (4096). So on a machine with a 256K L2 cache PQ_L2_SIZE would be 64. vm_page_queue cnt initializations (vm_page.h, vm_pageq.c) ------------------------------------------- For a 64k L2 Cache (PQ_L2_SIZE = 16) 0 N 16 F 32 C 1 F 17 I 33 C 2 F 18 A 34 C 3 F 19 C 4 F 20 C 5 F 21 C 6 F 22 C 7 F 23 C 8 F 24 C 9 F 25 C 10 F 26 C 11 F 27 C 12 F 28 C 13 F 29 C 14 F 30 C 15 F 31 C Note: As this is layed out any reference to PQ_FREE or PQ_CACHE must be relative to the page color, while PQ_ACTIVE, PQ_INACTIVE, and PQ_NONE must not be. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message