@@ -41,8 +41,11 @@ static frames_array_t early_frames;
4141static list_head_t free_frames [MAX_PAGE_ORDER + 1 ];
4242static list_head_t busy_frames [MAX_PAGE_ORDER + 1 ];
4343
44- /* 1 frame for array frame, 3 for mapping it, times two for paging/pmm collisions */
45- #define MIN_NUM_4K_FRAMES 2 * (1 + 3)
44+ /* 3 for paging and 4 for refilling (1 array frame, 3 for mapping it) */
45+ #define MIN_NUM_4K_FRAMES 3 + (1 + 3)
46+ /* enough frames to refill the 4K frames in worst case without running our of space */
47+ #define MIN_NOREFILL_FREE_FRAMES_THRESHOLD \
48+ (MIN_FREE_FRAMES_THRESHOLD + MIN_NUM_4K_FRAMES + (MAX_PAGE_ORDER - PAGE_ORDER_4K))
4649static size_t frames_count [MAX_PAGE_ORDER + 1 ];
4750
4851static bool refilling ;
@@ -150,7 +153,6 @@ static frames_array_t *_new_frames_array(bool from_paging) {
150153}
151154
152155static frames_array_t * new_frames_array (void ) {
153- dprintk ("%s: new_frames_array\n" , __func__ );
154156 return _new_frames_array (true);
155157}
156158
@@ -603,22 +605,6 @@ static void merge_frames(frame_t *first) {
603605 merge_frames (first );
604606}
605607
606- static inline bool enough_array_frames (void ) {
607- frames_array_t * array ;
608- size_t count = 0 ;
609-
610- list_for_each_entry (array , & frames , list ) {
611- count += array -> meta .free_count ;
612- /* TODO is this number correct ? */
613- if (count >= (MIN_FREE_FRAMES_THRESHOLD + MIN_NUM_4K_FRAMES +
614- (MAX_PAGE_ORDER - PAGE_ORDER_4K ))) {
615- return true;
616- }
617- }
618-
619- return false;
620- }
621-
622608static inline bool enough_4k_frames (void ) {
623609 frame_t * frame ;
624610 int count = 0 ;
@@ -735,13 +721,12 @@ void map_frames_array(void) {
735721}
736722
737723void refill_from_paging (void ) {
738-
739724 spin_lock (& lock );
740725
741726 /* if a refill is already active then they are responsible */
742727 if (!refilling ) {
743- /* make sure we have enough space to refill the 4K frames */
744- while (! enough_array_frames () ) {
728+ /* ensure enough space to refill 4K frames without frame array allocation */
729+ while (total_free_frames < MIN_NOREFILL_FREE_FRAMES_THRESHOLD ) {
745730 _new_frames_array (false);
746731 }
747732
@@ -750,4 +735,4 @@ void refill_from_paging(void) {
750735 }
751736
752737 spin_unlock (& lock );
753- }
738+ }
0 commit comments