PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
#include "threads/palloc.h"
#include <bitmap.h>
#include <debug.h>
#include <inttypes.h>
#include <round.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "threads/loader.h"
#include "threads/synch.h"
#include "threads/vaddr.h"
Go to the source code of this file.
Data Structures | |
struct | pool |
Page allocator. More... | |
Functions | |
static void | init_pool (struct pool *p, void *base, size_t page_cnt, const char *name) |
Initializes pool P as starting at START and ending at END, naming it NAME for debugging purposes. More... | |
static bool | page_from_pool (const struct pool *pool, void *page) |
Returns true if PAGE was allocated from POOL, false otherwise. More... | |
void | palloc_init (size_t user_page_limit) |
Initializes the page allocator. More... | |
void * | palloc_get_multiple (enum palloc_flags flags, size_t page_cnt) |
Obtains and returns a group of PAGE_CNT contiguous free pages. More... | |
void * | palloc_get_page (enum palloc_flags flags) |
Obtains a single free page and returns its kernel virtual address. More... | |
void | palloc_free_multiple (void *pages, size_t page_cnt) |
Frees the PAGE_CNT pages starting at PAGES. More... | |
void | palloc_free_page (void *page) |
Frees the page at PAGE. More... | |
Variables | |
static struct pool kernel_pool | user_pool |
Two pools: one for kernel data, one for user pages. More... | |
Initializes pool P as starting at START and ending at END, naming it NAME for debugging purposes.
Definition at line 154 of file palloc.c.
References pool::base, bitmap_buf_size(), bitmap_create_in_buf(), DIV_ROUND_UP, pool::lock, lock_init(), name, PANIC, PGSIZE, printf(), and pool::used_map.
Referenced by palloc_init().
Returns true if PAGE was allocated from POOL, false otherwise.
Definition at line 175 of file palloc.c.
References pool::base, bitmap_size(), pg_no(), and pool::used_map.
Referenced by palloc_free_multiple().
void palloc_free_multiple | ( | void * | pages, |
size_t | page_cnt | ||
) |
Frees the PAGE_CNT pages starting at PAGES.
Definition at line 118 of file palloc.c.
References ASSERT, pool::base, bitmap_all(), bitmap_set_multiple(), memset(), NOT_REACHED, NULL, page_from_pool(), pg_no(), pg_ofs(), PGSIZE, pool::used_map, and user_pool.
Referenced by free(), and palloc_free_page().
void palloc_free_page | ( | void * | page | ) |
Frees the page at PAGE.
Definition at line 146 of file palloc.c.
References palloc_free_multiple().
Referenced by free(), fsutil_cat(), load_segment(), pagedir_destroy(), process_execute(), setup_stack(), start_process(), and thread_schedule_tail().
void * palloc_get_multiple | ( | enum palloc_flags | flags, |
size_t | page_cnt | ||
) |
Obtains and returns a group of PAGE_CNT contiguous free pages.
If PAL_USER is set, the pages are obtained from the user pool, otherwise from the kernel pool. If PAL_ZERO is set in FLAGS, then the pages are filled with zeros. If too few pages are available, returns a null pointer, unless PAL_ASSERT is set in FLAGS, in which case the kernel panics.
Definition at line 71 of file palloc.c.
References pool::base, BITMAP_ERROR, bitmap_scan_and_flip(), pool::lock, lock_acquire(), lock_release(), memset(), NULL, PAL_ASSERT, PAL_USER, PAL_ZERO, PANIC, PGSIZE, pool::used_map, and user_pool.
Referenced by malloc(), and palloc_get_page().
void * palloc_get_page | ( | enum palloc_flags | flags | ) |
Obtains a single free page and returns its kernel virtual address.
If PAL_USER is set, the page is obtained from the user pool, otherwise from the kernel pool. If PAL_ZERO is set in FLAGS, then the page is filled with zeros. If no pages are available, returns a null pointer, unless PAL_ASSERT is set in FLAGS, in which case the kernel panics.
Definition at line 111 of file palloc.c.
References palloc_get_multiple().
Referenced by fsutil_cat(), load_segment(), lookup_page(), malloc(), pagedir_create(), paging_init(), process_execute(), setup_stack(), thread_create(), and tss_init().
void palloc_init | ( | size_t | user_page_limit | ) |
Initializes the page allocator.
At most USER_PAGE_LIMIT pages are put into the user pool.
Definition at line 46 of file palloc.c.
References init_pool(), init_ram_pages, PGSIZE, ptov(), user_page_limit, and user_pool.
Referenced by pintos_init().
|
static |
Two pools: one for kernel data, one for user pages.
Definition at line 37 of file palloc.c.
Referenced by palloc_free_multiple(), palloc_get_multiple(), and palloc_init().