AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vm_object.c File Reference

The page cache: a file's pages in memory, for mmap(). More...

#include <core/system.h>
#include <core/string.h>
#include <mm/vm.h>
#include <mm/pmap.h>

Go to the source code of this file.

Functions

static int vm_page_eq (void *_a, void *_b)
 Says whether a cached page is the one at the offset _b points to.
struct vm_object * vm_object_vnode (struct vnode *vnode)
 Gets a vnode's vm object, making it the first time.
struct vm_page * vnode_page_in (struct vm_object *vm_object, size_t off)
 Reads a page of a file into its vm object: the vnode pager's page in.
void vnode_pages_update (struct vnode *vnode, off_t start, off_t end)
 Reads a file's cached pages again after a write or a truncation changed a range of it.
void vnode_pages_free (struct vnode *vnode)
 Frees a vnode's vm object and its cached pages, when the vnode itself is freed.

Variables

static struct vm_pager vnode_pager

Detailed Description

The page cache: a file's pages in memory, for mmap().

A vnode that is mapped has a vm object, which keeps the file's pages by their offset; its pager reads a page in the first time a process touches it (see mm/fault.c), and every process that maps the file shares it.

Definition in file vm_object.c.

Function Documentation

◆ vm_object_vnode()

struct vm_object * vm_object_vnode ( struct vnode * vnode)

Gets a vnode's vm object, making it the first time.

Parameters
vnodethe vnode
Returns
its vm object, or NULL if vnode is NULL or there was no memory

Definition at line 31 of file vm_object.c.

References kfree(), kmalloc(), M_ZERO, NULL, vm_object::p, vm_object::pager, vm_object::pages, vm_object::type, vnode::vm_object, vm_object_vnode(), vm_page_eq(), VMOBJ_FILE, and vnode_pager.

Referenced by binfmt_elf_load_segments(), sys_mmap(), and vm_object_vnode().

◆ vm_page_eq()

int vm_page_eq ( void * _a,
void * _b )
static

Says whether a cached page is the one at the offset _b points to.

Definition at line 16 of file vm_object.c.

References vm_page::off, and vm_page_eq().

◆ vnode_page_in()

struct vm_page * vnode_page_in ( struct vm_object * vm_object,
size_t off )

Reads a page of a file into its vm object: the vnode pager's page in.

Past the end of the file, the page reads as zeros.

Parameters
vm_objectthe file's vm object
offthe page's offset in the file
Returns
the page, or NULL if there was no memory or the read failed

Definition at line 67 of file vm_object.c.

References hashmap_node::entry, hashmap_node::hash, kfree(), kmalloc(), M_ZERO, mm_page_alloc(), mm_page_dealloc(), NULL, vm_page::off, vm_object::p, vm_page::paddr, PAGE_ALIGN, PAGE_SIZE, vm_object::pages, pmap_page_write(), vm_page::ref, vfs_read(), vm_page::vm_object, vm_object_page_insert(), and vnode_page_in().

Referenced by vnode_page_in().

◆ vnode_pages_free()

void vnode_pages_free ( struct vnode * vnode)

Frees a vnode's vm object and its cached pages, when the vnode itself is freed.

Nothing maps them then, since a mapping holds the vnode (vm_object_incref()).

Parameters
vnodethe vnode

Definition at line 172 of file vm_object.c.

References hashmap_node::entry, hashmap_for, kfree(), mm_page_dealloc(), NULL, vm_page::paddr, vm_object::pages, qnode::value, vnode::vm_object, and vnode_pages_free().

Referenced by ext2_close(), procfs_close(), pseudofs_close(), and vnode_pages_free().

◆ vnode_pages_update()

void vnode_pages_update ( struct vnode * vnode,
off_t start,
off_t end )

Reads a file's cached pages again after a write or a truncation changed a range of it.

A page stays where it is, mapped by every process that maps the file, so its contents change but not the page; past the file's end it reads zeros. A private mapping's copies, made when it wrote to a page, are its own and don't change.

Parameters
vnodethe file
startthe start of the range that changed
endits end (exclusive)

Definition at line 128 of file vm_object.c.

References hashmap::count, hashmap_node::entry, hashmap_node::hash, kfree(), kmalloc(), memset(), NULL, vm_page::off, vm_page::paddr, PAGE_ALIGN, PAGE_SIZE, vm_object::pages, pmap_page_write(), printk(), vfs_read(), vnode::vm_object, and vnode_pages_update().

Referenced by vfs_trunc(), vfs_write_io(), and vnode_pages_update().

Variable Documentation

◆ vnode_pager

struct vm_pager vnode_pager
static
Initial value:
= {
.out = NULL,
}
struct vm_page * vnode_page_in(struct vm_object *vm_object, size_t off)
Reads a page of a file into its vm object: the vnode pager's page in.
Definition vm_object.c:67
#define NULL
Definition stddef.h:27

Definition at line 13 of file vm_object.c.

Referenced by vm_object_vnode().