Changes in kernel/generic/src/mm/frame.c [c626117:d1582b50] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/frame.c
rc626117 rd1582b50 63 63 #include <proc/thread.h> /* THREAD */ 64 64 65 zones_t zones = { 66 .count = 0, 67 .lock = IRQ_SPINLOCK_INITIALIZER("frame.zones.lock"), 68 }; 65 zones_t zones; 69 66 70 67 /* … … 72 69 * available. 73 70 */ 74 static IRQ_SPINLOCK_INITIALIZE(mem_avail_lock);75 static CONDVAR_INITIALIZE(mem_avail_cv);71 static mutex_t mem_avail_mtx; 72 static condvar_t mem_avail_cv; 76 73 static size_t mem_avail_req = 0; /**< Number of frames requested. */ 77 74 static size_t mem_avail_gen = 0; /**< Generation counter. */ … … 373 370 { 374 371 assert(zone->flags & ZONE_AVAILABLE); 375 assert(zone->free_count >= count);376 372 377 373 /* Allocate frames from zone */ … … 414 410 415 411 frame_t *frame = zone_get_frame(zone, index); 412 416 413 assert(frame->refcount > 0); 417 414 418 415 if (!--frame->refcount) { 419 assert(zone->busy_count > 0);420 421 416 bitmap_set(&zone->bitmap, index, 0); 422 417 … … 437 432 438 433 frame_t *frame = zone_get_frame(zone, index); 439 assert(frame->refcount <= 1);440 441 434 if (frame->refcount > 0) 442 435 return; 443 436 444 assert(zone->free_count > 0);445 446 437 frame->refcount = 1; 447 438 bitmap_set_range(&zone->bitmap, index, 1); … … 449 440 zone->free_count--; 450 441 reserve_force_alloc(1); 451 }452 453 /** Mark frame in zone available to allocation. */454 _NO_TRACE static void zone_mark_available(zone_t *zone, size_t index)455 {456 assert(zone->flags & ZONE_AVAILABLE);457 458 frame_t *frame = zone_get_frame(zone, index);459 assert(frame->refcount == 1);460 461 frame->refcount = 0;462 bitmap_set_range(&zone->bitmap, index, 0);463 464 zone->free_count++;465 442 } 466 443 … … 488 465 /* Difference between zone bases */ 489 466 pfn_t base_diff = zones.info[z2].base - zones.info[z1].base; 490 pfn_t gap = base_diff - zones.info[z1].count;491 467 492 468 zones.info[z1].count = base_diff + zones.info[z2].count; … … 516 492 zones.info[z2].frames[i]; 517 493 } 518 519 /*520 * Mark the gap between the original zones as unavailable.521 */522 523 for (size_t i = 0; i < gap; i++) {524 frame_initialize(&zones.info[z1].frames[old_z1->count + i]);525 zone_mark_unavailable(&zones.info[z1], old_z1->count + i);526 }527 494 } 528 495 … … 551 518 552 519 for (size_t i = 0; i < cframes; i++) 553 zone_mark_available(&zones.info[znum],520 (void) zone_frame_free(&zones.info[znum], 554 521 pfn - zones.info[znum].base + i); 555 522 } … … 756 723 757 724 if (overlaps(addr, PFN2ADDR(confcount), 758 KA2PA( ballocs.base), ballocs.size))725 KA2PA(config.stack_base), config.stack_size)) 759 726 continue; 760 727 … … 951 918 #endif 952 919 953 /* Disabled interrupts needed to prevent deadlock with TLB shootdown. */ 954 irq_spinlock_lock(&mem_avail_lock, true); 920 /* 921 * Since the mem_avail_mtx is an active mutex, we need to 922 * disable interrupts to prevent deadlock with TLB shootdown. 923 */ 924 ipl_t ipl = interrupts_disable(); 925 mutex_lock(&mem_avail_mtx); 955 926 956 927 if (mem_avail_req > 0) … … 962 933 963 934 while (gen == mem_avail_gen) 964 condvar_wait(&mem_avail_cv, &mem_avail_lock); 965 966 irq_spinlock_unlock(&mem_avail_lock, true); 935 condvar_wait(&mem_avail_cv, &mem_avail_mtx); 936 937 mutex_unlock(&mem_avail_mtx); 938 interrupts_restore(ipl); 967 939 968 940 #ifdef CONFIG_DEBUG … … 1022 994 irq_spinlock_unlock(&zones.lock, true); 1023 995 1024 /* Signal that some memory has been freed. */ 1025 1026 /* Disabled interrupts needed to prevent deadlock with TLB shootdown. */ 1027 irq_spinlock_lock(&mem_avail_lock, true); 996 /* 997 * Signal that some memory has been freed. 998 * Since the mem_avail_mtx is an active mutex, 999 * we need to disable interruptsto prevent deadlock 1000 * with TLB shootdown. 1001 */ 1002 1003 ipl_t ipl = interrupts_disable(); 1004 mutex_lock(&mem_avail_mtx); 1028 1005 1029 1006 if (mem_avail_req > 0) … … 1035 1012 } 1036 1013 1037 irq_spinlock_unlock(&mem_avail_lock, true); 1014 mutex_unlock(&mem_avail_mtx); 1015 interrupts_restore(ipl); 1038 1016 1039 1017 if (!(flags & FRAME_NO_RESERVE)) … … 1100 1078 void frame_init(void) 1101 1079 { 1080 if (config.cpu_active == 1) { 1081 zones.count = 0; 1082 irq_spinlock_initialize(&zones.lock, "frame.zones.lock"); 1083 mutex_initialize(&mem_avail_mtx, MUTEX_ACTIVE); 1084 condvar_initialize(&mem_avail_cv); 1085 } 1086 1102 1087 /* Tell the architecture to create some memory */ 1103 1088 frame_low_arch_init(); … … 1106 1091 frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), 1107 1092 SIZE2FRAMES(config.kernel_size)); 1093 frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)), 1094 SIZE2FRAMES(config.stack_size)); 1108 1095 1109 1096 for (size_t i = 0; i < init.cnt; i++)
Note:
See TracChangeset
for help on using the changeset viewer.