Changeset 3dbe4ca2 in mainline for kernel/generic/src/mm/frame.c


Ignore:
Timestamp:
2011-04-29T11:10:24Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce8f4f4
Parents:
d260a95 (diff), 933cadf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    rd260a95 r3dbe4ca2  
    4545#include <typedefs.h>
    4646#include <mm/frame.h>
     47#include <mm/reserve.h>
    4748#include <mm/as.h>
    4849#include <panic.h>
     
    5960#include <macros.h>
    6061#include <config.h>
     62#include <str.h>
    6163
    6264zones_t zones;
     
    472474 * @param frame_idx Frame index relative to zone.
    473475 *
    474  */
    475 NO_TRACE static void zone_frame_free(zone_t *zone, size_t frame_idx)
     476 * @return          Number of freed frames.
     477 *
     478 */
     479NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx)
    476480{
    477481        ASSERT(zone_flags_available(zone->flags));
    478482       
    479483        frame_t *frame = &zone->frames[frame_idx];
    480        
    481         /* Remember frame order */
    482         uint8_t order = frame->buddy_order;
     484        size_t size = 0;
    483485       
    484486        ASSERT(frame->refcount);
    485487       
    486488        if (!--frame->refcount) {
    487                 buddy_system_free(zone->buddy_system, &frame->buddy_link);
    488                
     489                size = 1 << frame->buddy_order;
     490                buddy_system_free(zone->buddy_system, &frame->buddy_link);             
    489491                /* Update zone information. */
    490                 zone->free_count += (1 << order);
    491                 zone->busy_count -= (1 << order);
    492         }
     492                zone->free_count += size;
     493                zone->busy_count -= size;
     494        }
     495       
     496        return size;
    493497}
    494498
     
    516520        ASSERT(link);
    517521        zone->free_count--;
     522        reserve_force_alloc(1);
    518523}
    519524
     
    645650        for (i = 0; i < cframes; i++) {
    646651                zones.info[znum].busy_count++;
    647                 zone_frame_free(&zones.info[znum],
     652                (void) zone_frame_free(&zones.info[znum],
    648653                    pfn - zones.info[znum].base + i);
    649654        }
     
    683688        /* Free unneeded frames */
    684689        for (i = count; i < (size_t) (1 << order); i++)
    685                 zone_frame_free(&zones.info[znum], i + frame_idx);
     690                (void) zone_frame_free(&zones.info[znum], i + frame_idx);
    686691}
    687692
     
    695700 * not to be 2^order size. Once the allocator is running it is no longer
    696701 * possible, merged configuration data occupies more space :-/
    697  *
    698  * The function uses
    699702 *
    700703 */
     
    837840                        buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link);
    838841                }
     842
     843                /* "Unreserve" new frames. */
     844                reserve_free(count);
    839845        } else
    840846                zone->frames = NULL;
     
    9991005        size_t hint = pzone ? (*pzone) : 0;
    10001006       
     1007        /*
     1008         * If not told otherwise, we must first reserve the memory.
     1009         */
     1010        if (!(flags & FRAME_NO_RESERVE))
     1011                reserve_force_alloc(size);
     1012
    10011013loop:
    10021014        irq_spinlock_lock(&zones.lock, true);
     
    10331045                if (flags & FRAME_ATOMIC) {
    10341046                        irq_spinlock_unlock(&zones.lock, true);
     1047                        if (!(flags & FRAME_NO_RESERVE))
     1048                                reserve_free(size);
    10351049                        return NULL;
    10361050                }
     
    10881102}
    10891103
     1104void *frame_alloc(uint8_t order, frame_flags_t flags)
     1105{
     1106        return frame_alloc_generic(order, flags, NULL);
     1107}
     1108
     1109void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags)
     1110{
     1111        return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL);
     1112}
     1113
    10901114/** Free a frame.
    10911115 *
     
    10951119 *
    10961120 * @param frame Physical Address of of the frame to be freed.
    1097  *
    1098  */
    1099 void frame_free(uintptr_t frame)
    1100 {
     1121 * @param flags Flags to control memory reservation.
     1122 *
     1123 */
     1124void frame_free_generic(uintptr_t frame, frame_flags_t flags)
     1125{
     1126        size_t size;
     1127       
    11011128        irq_spinlock_lock(&zones.lock, true);
    11021129       
     
    11061133        pfn_t pfn = ADDR2PFN(frame);
    11071134        size_t znum = find_zone(pfn, 1, 0);
     1135
    11081136       
    11091137        ASSERT(znum != (size_t) -1);
    11101138       
    1111         zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
     1139        size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
    11121140       
    11131141        irq_spinlock_unlock(&zones.lock, true);
     
    11181146        mutex_lock(&mem_avail_mtx);
    11191147        if (mem_avail_req > 0)
    1120                 mem_avail_req--;
     1148                mem_avail_req -= min(mem_avail_req, size);
    11211149       
    11221150        if (mem_avail_req == 0) {
     
    11251153        }
    11261154        mutex_unlock(&mem_avail_mtx);
     1155       
     1156        if (!(flags & FRAME_NO_RESERVE))
     1157                reserve_free(size);
     1158}
     1159
     1160void frame_free(uintptr_t frame)
     1161{
     1162        frame_free_generic(frame, 0);
     1163}
     1164
     1165void frame_free_noreserve(uintptr_t frame)
     1166{
     1167        frame_free_generic(frame, FRAME_NO_RESERVE);
    11271168}
    11281169
     
    13551396        bool available = zone_flags_available(flags);
    13561397       
     1398        uint64_t size;
     1399        const char *size_suffix;
     1400        bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false);
     1401       
    13571402        printf("Zone number:       %zu\n", znum);
    13581403        printf("Zone base address: %p\n", (void *) base);
    1359         printf("Zone size:         %zu frames (%zu KiB)\n", count,
    1360             SIZE2KB(FRAMES2SIZE(count)));
     1404        printf("Zone size:         %zu frames (%" PRIu64 " %s)\n", count,
     1405            size, size_suffix);
    13611406        printf("Zone flags:        %c%c%c\n",
    13621407            available ? 'A' : ' ',
     
    13651410       
    13661411        if (available) {
    1367                 printf("Allocated space:   %zu frames (%zu KiB)\n",
    1368                     busy_count, SIZE2KB(FRAMES2SIZE(busy_count)));
    1369                 printf("Available space:   %zu frames (%zu KiB)\n",
    1370                     free_count, SIZE2KB(FRAMES2SIZE(free_count)));
     1412                bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix,
     1413                    false);
     1414                printf("Allocated space:   %zu frames (%" PRIu64 " %s)\n",
     1415                    busy_count, size, size_suffix);
     1416                bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix,
     1417                    false);
     1418                printf("Available space:   %zu frames (%" PRIu64 " %s)\n",
     1419                    free_count, size, size_suffix);
    13711420        }
    13721421}
Note: See TracChangeset for help on using the changeset viewer.