Skip to content

Commit

Permalink
Merge pull request #96 from fritzprix/0.2
Browse files Browse the repository at this point in the history
- little improvement
  • Loading branch information
fritzprix authored May 1, 2017
2 parents dc3c694 + 026532d commit d586e12
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions source/kernel/mm/tch_kmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static wt_adapter kmalloc_adapter = {

static wtreeRoot_t kernel_heap_root_new;
static struct mem_region init_region;

static struct mem_segment* cached_seg = NULL;
static int init_segid;


Expand Down Expand Up @@ -119,10 +119,9 @@ static DECLARE_ONALLOCATE(km_onallocate) {
}

static DECLARE_ONFREE(km_onfree) {
struct mem_segment* pseg = tch_segmentLookup(init_segid);
if(wtnode->base_size) {
struct mem_region* free_reg = (struct mem_region*) &wtnode[1];
tch_segmentFreeRegion(free_reg, TRUE);
struct map_header* hdr = container_of(wtnode, struct map_header, wtnode);
tch_segmentFreeRegion(&hdr->mreg, TRUE);
}
return 0;
}
Expand All @@ -139,9 +138,12 @@ static DECLARE_ONREMOVED(km_onremoved) {

static DECLARE_ONADDED(km_onadded) {
if(node->base_size) {
// node that has base_size (meaning original allocated size) is mapped to init_mm (kernel logical memory management root)
struct map_header* hdr = container_of(node, struct map_header, wtnode);
struct mem_segment* seg = tch_segmentLookup(init_segid);
tch_initRegion(&hdr->mreg, seg, (size_t) (node->top - node->base_size) >> PAGE_OFFSET, node->base_size >> PAGE_OFFSET, KM_PERMISSION);
if(!cached_seg) {
cached_seg = tch_segmentLookup(init_segid);
}
tch_initRegion(&hdr->mreg, cached_seg, (size_t) (node->top - node->base_size) >> PAGE_OFFSET, node->base_size >> PAGE_OFFSET, KM_PERMISSION);
tch_mapRegion(&init_mm, &hdr->mreg);
}
}

0 comments on commit d586e12

Please sign in to comment.