git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Unifying the Lunaix's Physical Memory Model (#28)
[lunaix-os.git]
/
lunaix-os
/
kernel
/
fs
/
pcache.c
diff --git
a/lunaix-os/kernel/fs/pcache.c
b/lunaix-os/kernel/fs/pcache.c
index 8283fd1f56d899a222ff0d779891ca2b22457361..26e7ac4882035b0362eaa148931e79e1a816d3d5 100644
(file)
--- a/
lunaix-os/kernel/fs/pcache.c
+++ b/
lunaix-os/kernel/fs/pcache.c
@@
-2,9
+2,7
@@
#include <lunaix/ds/btrie.h>
#include <lunaix/fs.h>
#include <lunaix/mm/page.h>
#include <lunaix/ds/btrie.h>
#include <lunaix/fs.h>
#include <lunaix/mm/page.h>
-#include <lunaix/mm/pmm.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/mm/valloc.h>
-#include <lunaix/mm/vmm.h>
#include <lunaix/spike.h>
#define PCACHE_DIRTY 0x1
#include <lunaix/spike.h>
#define PCACHE_DIRTY 0x1
@@
-22,22
+20,24
@@
__pcache_try_evict(struct lru_node* obj)
static void
pcache_free_page(void* va)
{
static void
pcache_free_page(void* va)
{
- ptr_t pa = vmm_del_mapping(VMS_SELF, (ptr_t)va);
- pmm_free_page(KERNEL_PID, pa);
+ pte_t* ptep = mkptep_va(VMS_SELF, (ptr_t)va);
+ pte_t pte = pte_at(ptep);
+ leaflet_return(pte_leaflet(pte));
}
static void*
pcache_alloc_page()
{
int i = 0;
}
static void*
pcache_alloc_page()
{
int i = 0;
- ptr_t pp = pmm_alloc_page(KERNEL_PID, 0), va = 0;
+ ptr_t va = 0;
+ struct leaflet* leaflet = alloc_leaflet(0);
- if (!
pp
) {
+ if (!
leaflet
) {
return NULL;
}
return NULL;
}
- if (!(va = (ptr_t)vmap(
pp, PG_SIZE, PG_PREM_RW, 0
))) {
-
pmm_free_page(KERNEL_PID, pp
);
+ if (!(va = (ptr_t)vmap(
leaflet, KERNEL_DATA
))) {
+
leaflet_return(leaflet
);
return NULL;
}
return NULL;
}
@@
-47,7
+47,7
@@
pcache_alloc_page()
void
pcache_init(struct pcache* pcache)
{
void
pcache_init(struct pcache* pcache)
{
- btrie_init(&pcache->tree, P
G_SIZE_BITS
);
+ btrie_init(&pcache->tree, P
AGE_SHIFT
);
llist_init_head(&pcache->dirty);
llist_init_head(&pcache->pages);
llist_init_head(&pcache->dirty);
llist_init_head(&pcache->pages);
@@
-134,19
+134,18
@@
pcache_write(struct v_inode* inode, void* data, u32_t len, u32_t fpos)
struct pcache_pg* pg;
while (buf_off < len && errno >= 0) {
struct pcache_pg* pg;
while (buf_off < len && errno >= 0) {
- u32_t wr_bytes = MIN(P
G
_SIZE - pg_off, len - buf_off);
+ u32_t wr_bytes = MIN(P
AGE
_SIZE - pg_off, len - buf_off);
int new_page = pcache_get_page(pcache, fpos, &pg_off, &pg);
if (new_page) {
// Filling up the page
int new_page = pcache_get_page(pcache, fpos, &pg_off, &pg);
if (new_page) {
// Filling up the page
- errno =
- inode->default_fops->read_page(inode, pg->pg, PG_SIZE, pg->fpos);
+ errno = inode->default_fops->read_page(inode, pg->pg, pg->fpos);
if (errno < 0) {
break;
}
if (errno < 0) {
break;
}
- if (errno <
PG
_SIZE) {
+ if (errno <
(int)PAGE
_SIZE) {
// EOF
len = MIN(len, buf_off + errno);
}
// EOF
len = MIN(len, buf_off + errno);
}
@@
-178,20
+177,19
@@
pcache_read(struct v_inode* inode, void* data, u32_t len, u32_t fpos)
int new_page = pcache_get_page(pcache, fpos, &pg_off, &pg);
if (new_page) {
// Filling up the page
int new_page = pcache_get_page(pcache, fpos, &pg_off, &pg);
if (new_page) {
// Filling up the page
- errno =
- inode->default_fops->read_page(inode, pg->pg, PG_SIZE, pg->fpos);
+ errno = inode->default_fops->read_page(inode, pg->pg, pg->fpos);
if (errno < 0) {
break;
}
if (errno < 0) {
break;
}
- if (errno <
PG
_SIZE) {
+ if (errno <
(int)PAGE
_SIZE) {
// EOF
len = MIN(len, buf_off + errno);
}
pg->len = errno;
} else if (!pg) {
// EOF
len = MIN(len, buf_off + errno);
}
pg->len = errno;
} else if (!pg) {
- errno = inode->default_fops->read
_page
(
+ errno = inode->default_fops->read(
inode, (data + buf_off), len - buf_off, pg->fpos);
buf_off = len;
break;
inode, (data + buf_off), len - buf_off, pg->fpos);
buf_off = len;
break;
@@
-231,8
+229,7
@@
pcache_commit(struct v_inode* inode, struct pcache_pg* page)
return 0;
}
return 0;
}
- int errno =
- inode->default_fops->write_page(inode, page->pg, PG_SIZE, page->fpos);
+ int errno = inode->default_fops->write_page(inode, page->pg, page->fpos);
if (!errno) {
page->flags &= ~PCACHE_DIRTY;
if (!errno) {
page->flags &= ~PCACHE_DIRTY;