Changeset 1bb3766 in mainline


Ignore:
Timestamp:
2008-06-23T23:02:01Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ac0e791
Parents:
1a1744e
Message:

Finer grained waiting for memory with consideration of the number
of available memory frames.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/frame.c

    r1a1744e r1bb3766  
    110110 * available.
    111111 */
    112 mutex_t zones_mtx;
    113 condvar_t zones_cv;
    114 int new_freed_mem = false;
     112mutex_t mem_avail_mtx;
     113condvar_t mem_avail_cv;
     114unsigned long mem_avail_frames = 0;     /**< Number of available frames. */
     115unsigned long mem_avail_gen = 0;        /**< Generation counter. */
    115116
    116117/********************/
     
    141142/** Initialize frame structure.
    142143 *
    143  * @param framei        Frame structure to be initialized.
     144 * @param frame         Frame structure to be initialized.
    144145 */
    145146static void frame_initialize(frame_t *frame)
     
    540541
    541542/** Return frame from zone. */
    542 static frame_t * zone_get_frame(zone_t *zone, index_t frame_idx)
     543static frame_t *zone_get_frame(zone_t *zone, index_t frame_idx)
    543544{
    544545        ASSERT(frame_idx < zone->count);
     
    559560        ASSERT(link);
    560561        zone->free_count--;
     562
     563        mutex_lock(&mem_avail_mtx);
     564        mem_avail_frames--;
     565        mutex_unlock(&mem_avail_mtx);
    561566}
    562567
     
    736741                goto errout;
    737742        /* We can join only 2 zones with none existing inbetween */
    738         if (z2-z1 != 1)
     743        if (z2 - z1 != 1)
    739744                goto errout;
    740745
     
    797802
    798803        while (zones.count > 1 && --count) {
    799                 zone_merge(0,1);
     804                zone_merge(0, 1);
    800805                break;
    801806        }
     
    894899         */
    895900        confcount = SIZE2FRAMES(zone_conf_size(count));
    896         if (confframe >= start && confframe < start+count) {
    897                 for (;confframe < start + count; confframe++) {
     901        if (confframe >= start && confframe < start + count) {
     902                for (; confframe < start + count; confframe++) {
    898903                        addr = PFN2ADDR(confframe);
    899904                        if (overlaps(addr, PFN2ADDR(confcount),
     
    929934                return -1;
    930935
     936        mutex_lock(&mem_avail_mtx);
     937        mem_avail_frames += count;
     938        mutex_unlock(&mem_avail_mtx);
     939
    931940        /* If confdata in zone, mark as unavailable */
    932941        if (confframe >= start && confframe < start + count)
     
    934943                        zone_mark_unavailable(z, i - z->base);
    935944                }
     945       
    936946        return znum;
    937947}
     
    947957        ASSERT(zone);
    948958
    949         zone_get_frame(zone, pfn-zone->base)->parent = data;
     959        zone_get_frame(zone, pfn - zone->base)->parent = data;
    950960        spinlock_unlock(&zone->lock);
    951961}
     
    978988        pfn_t v;
    979989        zone_t *zone;
     990        unsigned long gen = 0;
    980991       
    981992loop:
     
    10091020               
    10101021#ifdef CONFIG_DEBUG
    1011                 printf("Thread %" PRIu64 " falling asleep, low memory.\n", THREAD->tid);
     1022                unsigned long avail;
     1023
     1024                mutex_lock(&mem_avail_mtx);
     1025                avail = mem_avail_frames;
     1026                mutex_unlock(&mem_avail_mtx);
     1027
     1028                printf("Thread %" PRIu64 " waiting for %u frames, "
     1029                    "%u available.\n", THREAD->tid, 1ULL << order, avail);
    10121030#endif
    10131031
    1014                 mutex_lock(&zones_mtx);
    1015                 if (!new_freed_mem)
    1016                         condvar_wait(&zones_cv, &zones_mtx);
    1017                 new_freed_mem = false;
    1018                 mutex_unlock(&zones_mtx);
     1032                mutex_lock(&mem_avail_mtx);
     1033                while ((mem_avail_frames < (1ULL << order)) ||
     1034                    gen == mem_avail_gen)
     1035                        condvar_wait(&mem_avail_cv, &mem_avail_mtx);
     1036                gen = mem_avail_gen;
     1037                mutex_unlock(&mem_avail_mtx);
    10191038
    10201039#ifdef CONFIG_DEBUG
    1021                 printf("Thread %" PRIu64 " woken up, memory available.\n", THREAD->tid);
     1040                mutex_lock(&mem_avail_mtx);
     1041                avail = mem_avail_frames;
     1042                mutex_unlock(&mem_avail_mtx);
     1043
     1044                printf("Thread %" PRIu64 " woken up, %u frames available.\n",
     1045                    THREAD->tid, avail);
    10221046#endif
    10231047
     
    10301054
    10311055        spinlock_unlock(&zone->lock);
     1056       
     1057        mutex_lock(&mem_avail_mtx);
     1058        mem_avail_frames -= (1ULL << order);
     1059        mutex_unlock(&mem_avail_mtx);
     1060
    10321061        interrupts_restore(ipl);
    10331062
     
    10661095         * Signal that some memory has been freed.
    10671096         */
    1068         mutex_lock(&zones_mtx);
    1069         new_freed_mem = true;
    1070         condvar_broadcast(&zones_cv);
    1071         mutex_unlock(&zones_mtx);
     1097        mutex_lock(&mem_avail_mtx);
     1098        mem_avail_frames++;
     1099        mem_avail_gen++;
     1100        condvar_broadcast(&mem_avail_cv);
     1101        mutex_unlock(&mem_avail_mtx);
    10721102
    10731103        interrupts_restore(ipl);
     
    11251155                zones.count = 0;
    11261156                spinlock_initialize(&zones.lock, "zones.lock");
     1157                mutex_initialize(&mem_avail_mtx, MUTEX_ACTIVE);
     1158                condvar_initialize(&mem_avail_cv);
    11271159        }
    11281160        /* Tell the architecture to create some memory */
     
    11491181                frame_mark_unavailable(0, 1);
    11501182        }
    1151 
    1152         mutex_initialize(&zones_mtx, MUTEX_ACTIVE);     /* mimic spinlock */
    1153         condvar_initialize(&zones_cv);
    11541183}
    11551184
Note: See TracChangeset for help on using the changeset viewer.