From owner-freebsd-hackers@FreeBSD.ORG Wed May 21 11:02:23 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4BC2937B401 for ; Wed, 21 May 2003 11:02:23 -0700 (PDT) Received: from mail02.svc.cra.dublin.eircom.net (mail02.svc.cra.dublin.eircom.net [159.134.118.18]) by mx1.FreeBSD.org (Postfix) with SMTP id 0FA3343F3F for ; Wed, 21 May 2003 11:02:22 -0700 (PDT) (envelope-from pmedwards@eircom.net) Received: (qmail 92201 messnum 36971 invoked from network[159.134.237.77/webmail00.eircom.net]); 21 May 2003 18:02:20 -0000 Received: from webmail00.eircom.net (HELO webmail.eircom.net) (159.134.237.77) by mail02.svc.cra.dublin.eircom.net (qp 92201) with SMTP; 21 May 2003 18:02:20 -0000 From: "Peter Edwards" To: hackers@freebsd.org Date: Wed, 21 May 2003 17:47:10 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit X-Originating-IP: 62.17.151.61 X-Mailer: Eircom Net CRC Webmail (http://www.eircom.net/) Organization: Eircom Net (http://www.eircom.net/) Message-Id: <20030521180222.0FA3343F3F@mx1.FreeBSD.org> Subject: Question on (ab)using the swap pager and VM X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 May 2003 18:02:23 -0000 Hi All, As a programming exercise, I'm trying to write what is in essence a synthetic filesystem where the synthetic files contain large amounts of data I want to use a swap pager as a cached store for the data I'm providing. (ie, it'll be generated in the kernel) I'm aware that this is probably almost criminal, but I just want to understand if what I'm doing is "correct", even if it is stupid. I'm happy enough with the VFS stuff (vnops, vfsops, etc), and I think I've pretty much worked out how to get the data in pages from the swap-pager and accessable in the kernel's address space, using vm_pager_get_pages() or vm_page_grab(), then vm_page_wire() to get the page in physical ram, and then kmem_malloc() and pmap_qenter() to get them into the kernel's memory map. What I'm less sure about is how to write to the swap pager. My best guess is that I can modify the page with impunity once it's wired, then do something like what vm_proc_swapout() does, calling vm_page_dirty() and vm_page_unwire() to put it back on to the correct queue, where the swapper can launder it if neccessary. Overall, can I do something like this to allocate and write a single page to the swap pager? (modulo locking stuff) pager = swap_pager_alloc(...); kmem = kmem_alloc_wait(kernel_map, PAGE_SIZE); page = vm_page_grab(pager, 0, ...); vm_page_wire(page); pmap_qenter(kmem, page); strcpy(kmem, "hello world"); pmap_qremove(); kmem_free_wakeup(kernel_map, kmem); vm_page_dirty(page); vm_page_unwire(page); And, at an arbitrary point in the future, possibly after the page is swapped out, bring it back in and find my "hello world" message intact. What I'm even less sure about is dealing with copy-on-write mappings from the swap pager I allocate. It's not a concern in the sense that it's a read-only file system, and the data will be in the swap pager, and immutable once there's a possibility of such a mapping happening, but it just leaves me with the feeling I'm missing something (probably quite big) I just want to get an idea if I'm in the right ballpark before hacking away. -- Peter Edwards.