Ignore:
File:
1 edited

Legend:

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

    r2fc3b2d r0705fc5  
    4848#include <synch/mutex.h>
    4949#include <adt/list.h>
     50#include <adt/btree.h>
    5051#include <errno.h>
    5152#include <typedefs.h>
     
    121122         */
    122123        mutex_lock(&area->sh_info->lock);
    123         used_space_ival_t *ival = used_space_first(&area->used_space);
    124         while (ival != NULL) {
    125                 uintptr_t base = ival->page;
    126                 size_t count = ival->count;
    127                 unsigned int j;
    128 
    129                 for (j = 0; j < count; j++) {
    130                         pte_t pte;
    131                         bool found;
    132 
    133                         page_table_lock(area->as, false);
    134                         found = page_mapping_find(area->as, base + P2SZ(j),
    135                             false, &pte);
    136 
    137                         (void)found;
    138                         assert(found);
    139                         assert(PTE_VALID(&pte));
    140                         assert(PTE_PRESENT(&pte));
    141 
    142                         as_pagemap_insert(&area->sh_info->pagemap,
    143                             (base + P2SZ(j)) - area->base, PTE_GET_FRAME(&pte));
    144                         page_table_unlock(area->as, false);
    145 
    146                         pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte));
    147                         frame_reference_add(pfn);
     124        list_foreach(area->used_space.leaf_list, leaf_link, btree_node_t,
     125            node) {
     126                unsigned int i;
     127
     128                for (i = 0; i < node->keys; i++) {
     129                        uintptr_t base = node->key[i];
     130                        size_t count = (size_t) node->value[i];
     131                        unsigned int j;
     132
     133                        for (j = 0; j < count; j++) {
     134                                pte_t pte;
     135                                bool found;
     136
     137                                page_table_lock(area->as, false);
     138                                found = page_mapping_find(area->as,
     139                                    base + P2SZ(j), false, &pte);
     140
     141                                (void)found;
     142                                assert(found);
     143                                assert(PTE_VALID(&pte));
     144                                assert(PTE_PRESENT(&pte));
     145
     146                                btree_insert(&area->sh_info->pagemap,
     147                                    (base + P2SZ(j)) - area->base,
     148                                    (void *) PTE_GET_FRAME(&pte), NULL);
     149                                page_table_unlock(area->as, false);
     150
     151                                pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte));
     152                                frame_reference_add(pfn);
     153                        }
     154
    148155                }
    149 
    150                 ival = used_space_next(ival);
    151156        }
    152157        mutex_unlock(&area->sh_info->lock);
     
    196201        mutex_lock(&area->sh_info->lock);
    197202        if (area->sh_info->shared) {
     203                btree_node_t *leaf;
     204
    198205                /*
    199206                 * The area is shared, chances are that the mapping can be found
     
    203210                 * mapping, a new frame is allocated and the mapping is created.
    204211                 */
    205                 errno_t rc = as_pagemap_find(&area->sh_info->pagemap,
    206                     upage - area->base, &frame);
    207                 if (rc != EOK) {
    208                         /* Need to allocate the frame */
    209                         kpage = km_temporary_page_get(&frame,
    210                             FRAME_NO_RESERVE);
    211                         memsetb((void *) kpage, PAGE_SIZE, 0);
    212                         km_temporary_page_put(kpage);
     212                frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
     213                    upage - area->base, &leaf);
     214                if (!frame) {
     215                        bool allocate = true;
     216                        unsigned int i;
    213217
    214218                        /*
    215                          * Insert the address of the newly allocated
    216                          * frame to the pagemap.
     219                         * Zero can be returned as a valid frame address.
     220                         * Just a small workaround.
    217221                         */
    218                         as_pagemap_insert(&area->sh_info->pagemap,
    219                             upage - area->base, frame);
     222                        for (i = 0; i < leaf->keys; i++) {
     223                                if (leaf->key[i] == upage - area->base) {
     224                                        allocate = false;
     225                                        break;
     226                                }
     227                        }
     228                        if (allocate) {
     229                                kpage = km_temporary_page_get(&frame,
     230                                    FRAME_NO_RESERVE);
     231                                memsetb((void *) kpage, PAGE_SIZE, 0);
     232                                km_temporary_page_put(kpage);
     233
     234                                /*
     235                                 * Insert the address of the newly allocated
     236                                 * frame to the pagemap.
     237                                 */
     238                                btree_insert(&area->sh_info->pagemap,
     239                                    upage - area->base, (void *) frame, leaf);
     240                        }
    220241                }
    221242                frame_reference_add(ADDR2PFN(frame));
     
    259280         */
    260281        page_mapping_insert(AS, upage, frame, as_area_get_flags(area));
    261         if (!used_space_insert(&area->used_space, upage, 1))
     282        if (!used_space_insert(area, upage, 1))
    262283                panic("Cannot insert used space.");
    263284
Note: See TracChangeset for help on using the changeset viewer.