Date: Wed, 21 May 2003 17:47:10 +0100 From: "Peter Edwards" <pmedwards@eircom.net> To: hackers@freebsd.org Subject: Question on (ab)using the swap pager and VM Message-ID: <20030521180222.0FA3343F3F@mx1.FreeBSD.org>
next in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030521180222.0FA3343F3F>