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
Second Extended Filesystem (ext2) and other improvements (#33)
[lunaix-os.git]
/
lunaix-os
/
kernel
/
mm
/
cake.c
diff --git
a/lunaix-os/kernel/mm/cake.c
b/lunaix-os/kernel/mm/cake.c
index 2a70ab76d823f7d09d6d62cbc08bc6e70f70372b..d9ef3810d5c5831aaaa05d81e889df2df38f6698 100644
(file)
--- a/
lunaix-os/kernel/mm/cake.c
+++ b/
lunaix-os/kernel/mm/cake.c
@@
-12,8
+12,7
@@
#include <klibc/string.h>
#include <lunaix/mm/cake.h>
#include <klibc/string.h>
#include <lunaix/mm/cake.h>
-#include <lunaix/mm/pmm.h>
-#include <lunaix/mm/vmm.h>
+#include <lunaix/mm/page.h>
#include <lunaix/spike.h>
#include <lunaix/syslog.h>
#include <lunaix/spike.h>
#include <lunaix/syslog.h>
@@
-28,11
+27,12
@@
struct llist_header piles = { .next = &piles, .prev = &piles };
void*
__alloc_cake(unsigned int cake_pg)
{
void*
__alloc_cake(unsigned int cake_pg)
{
-
ptr_t pa = (ptr_t)pmm_alloc_cpage(KERNEL_PID, cake_pg, 0
);
- if (!
pa
) {
+
struct leaflet* leaflet = alloc_leaflet(count_order(cake_pg)
);
+ if (!
leaflet
) {
return NULL;
}
return NULL;
}
- return vmap(pa, cake_pg * PG_SIZE, PG_PREM_RW, 0);
+
+ return (void*)vmap(leaflet, KERNEL_DATA);
}
struct cake_s*
}
struct cake_s*
@@
-84,9
+84,9
@@
__init_pile(struct cake_pile* pile,
piece_size = ROUNDUP(piece_size, offset);
*pile = (struct cake_pile){ .piece_size = piece_size,
piece_size = ROUNDUP(piece_size, offset);
*pile = (struct cake_pile){ .piece_size = piece_size,
- .cakes_count =
1
,
+ .cakes_count =
0
,
.pieces_per_cake =
.pieces_per_cake =
- (pg_per_cake * P
G
_SIZE) /
+ (pg_per_cake * P
AGE
_SIZE) /
(piece_size + sizeof(piece_index_t)),
.pg_per_cake = pg_per_cake };
(piece_size + sizeof(piece_index_t)),
.pg_per_cake = pg_per_cake };
@@
-117,6
+117,9
@@
cake_new_pile(char* name,
{
struct cake_pile* pile = (struct cake_pile*)cake_grab(&master_pile);
{
struct cake_pile* pile = (struct cake_pile*)cake_grab(&master_pile);
+ // must aligned to napot order!
+ assert(is_pot(pg_per_cake));
+
__init_pile(pile, name, piece_size, pg_per_cake, options);
return pile;
__init_pile(pile, name, piece_size, pg_per_cake, options);
return pile;
@@
-149,7
+152,7
@@
cake_grab(struct cake_pile* pile)
pile->alloced_pieces++;
llist_delete(&pos->cakes);
pile->alloced_pieces++;
llist_delete(&pos->cakes);
- if (pos->
next_free
== EO_FREE_PIECE) {
+ if (pos->
free_list[pos->next_free]
== EO_FREE_PIECE) {
llist_append(&pile->full, &pos->cakes);
} else {
llist_append(&pile->partial, &pos->cakes);
llist_append(&pile->full, &pos->cakes);
} else {
llist_append(&pile->partial, &pos->cakes);
@@
-169,6
+172,7
@@
int
cake_release(struct cake_pile* pile, void* area)
{
piece_index_t piece_index;
cake_release(struct cake_pile* pile, void* area)
{
piece_index_t piece_index;
+ size_t dsize = 0;
struct cake_s *pos, *n;
struct llist_header* hdrs[2] = { &pile->full, &pile->partial };
struct cake_s *pos, *n;
struct llist_header* hdrs[2] = { &pile->full, &pile->partial };
@@
-178,7
+182,8
@@
cake_release(struct cake_pile* pile, void* area)
if (pos->first_piece > area) {
continue;
}
if (pos->first_piece > area) {
continue;
}
- piece_index = (ptr_t)(area - pos->first_piece) / pile->piece_size;
+ dsize = (ptr_t)(area - pos->first_piece);
+ piece_index = dsize / pile->piece_size;
if (piece_index < pile->pieces_per_cake) {
goto found;
}
if (piece_index < pile->pieces_per_cake) {
goto found;
}
@@
-188,8
+193,12
@@
cake_release(struct cake_pile* pile, void* area)
return 0;
found:
return 0;
found:
+ assert(!(dsize % pile->piece_size));
pos->free_list[piece_index] = pos->next_free;
pos->next_free = piece_index;
pos->free_list[piece_index] = pos->next_free;
pos->next_free = piece_index;
+
+ assert_msg(pos->free_list[piece_index] != pos->next_free, "double free");
+
pos->used_pieces--;
pile->alloced_pieces--;
pos->used_pieces--;
pile->alloced_pieces--;
@@
-200,6
+209,8
@@
found:
llist_append(&pile->partial, &pos->cakes);
}
llist_append(&pile->partial, &pos->cakes);
}
+ *((unsigned int*)area) = DEADCAKE_MARK;
+
return 1;
}
return 1;
}