Changeset 7be8d4d in mainline for kernel/generic/src/mm/backend_elf.c


Ignore:
Timestamp:
2018-12-08T23:32:55Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Children:
dd74b5b
Parents:
de0af3a
git-author:
Jiri Svoboda <jiri@…> (2018-12-05 18:39:06)
git-committer:
Jiri Svoboda <jiri@…> (2018-12-08 23:32:55)
Message:

Replace B+tree with ordered dict. for used space

Replace the use of B+tree with ordered dictionary for used space,
adding a little bit more abstraction around used space tracking.
This allows performing TLB shootdown while shrinking an area
in a single sequence. A generic used_space_remove() is no longer
needed.

File:
1 edited

Legend:

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

    rde0af3a r7be8d4d  
    153153{
    154154        elf_segment_header_t *entry = area->backend_data.segment;
    155         link_t *cur;
    156         btree_node_t *leaf, *node;
     155        used_space_ival_t *start;
     156        used_space_ival_t *cur;
    157157        uintptr_t start_anon = entry->p_vaddr + entry->p_filesz;
    158158
     
    164164         */
    165165        if (area->flags & AS_AREA_WRITE) {
    166                 node = list_get_instance(list_first(&area->used_space.leaf_list),
    167                     btree_node_t, leaf_link);
     166                start = used_space_first(&area->used_space);
    168167        } else {
    169                 (void) btree_search(&area->used_space, start_anon, &leaf);
    170                 node = btree_leaf_node_left_neighbour(&area->used_space, leaf);
    171                 if (!node)
    172                         node = leaf;
     168                /* Find first interval containing addresses >= start_anon */
     169                start = used_space_find_gteq(&area->used_space, start_anon);
    173170        }
    174171
     
    177174         */
    178175        mutex_lock(&area->sh_info->lock);
    179         for (cur = &node->leaf_link; cur != &area->used_space.leaf_list.head;
    180             cur = cur->next) {
     176        cur = start;
     177        while (cur != NULL) {
     178                uintptr_t base = cur->page;
     179                size_t count = cur->count;
    181180                unsigned int i;
    182181
    183                 node = list_get_instance(cur, btree_node_t, leaf_link);
    184 
    185                 for (i = 0; i < node->keys; i++) {
    186                         uintptr_t base = node->key[i];
    187                         size_t count = (size_t) node->value[i];
    188                         unsigned int j;
     182                /*
     183                 * Skip read-only areas of used space that are backed
     184                 * by the ELF image.
     185                 */
     186                if (!(area->flags & AS_AREA_WRITE))
     187                        if (base >= entry->p_vaddr &&
     188                            base + P2SZ(count) <= start_anon)
     189                                continue;
     190
     191                for (i = 0; i < count; i++) {
     192                        pte_t pte;
     193                        bool found;
    189194
    190195                        /*
    191                          * Skip read-only areas of used space that are backed
    192                          * by the ELF image.
     196                         * Skip read-only pages that are backed by the
     197                         * ELF image.
    193198                         */
    194199                        if (!(area->flags & AS_AREA_WRITE))
    195200                                if (base >= entry->p_vaddr &&
    196                                     base + P2SZ(count) <= start_anon)
     201                                    base + P2SZ(i + 1) <= start_anon)
    197202                                        continue;
    198203
    199                         for (j = 0; j < count; j++) {
    200                                 pte_t pte;
    201                                 bool found;
    202 
    203                                 /*
    204                                  * Skip read-only pages that are backed by the
    205                                  * ELF image.
    206                                  */
    207                                 if (!(area->flags & AS_AREA_WRITE))
    208                                         if (base >= entry->p_vaddr &&
    209                                             base + P2SZ(j + 1) <= start_anon)
    210                                                 continue;
    211 
    212                                 page_table_lock(area->as, false);
    213                                 found = page_mapping_find(area->as,
    214                                     base + P2SZ(j), false, &pte);
    215 
    216                                 (void) found;
    217                                 assert(found);
    218                                 assert(PTE_VALID(&pte));
    219                                 assert(PTE_PRESENT(&pte));
    220 
    221                                 as_pagemap_insert(&area->sh_info->pagemap,
    222                                     (base + P2SZ(j)) - area->base,
    223                                     PTE_GET_FRAME(&pte));
    224                                 page_table_unlock(area->as, false);
    225 
    226                                 pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte));
    227                                 frame_reference_add(pfn);
    228                         }
    229 
     204                        page_table_lock(area->as, false);
     205                        found = page_mapping_find(area->as,
     206                            base + P2SZ(i), false, &pte);
     207
     208                        (void) found;
     209                        assert(found);
     210                        assert(PTE_VALID(&pte));
     211                        assert(PTE_PRESENT(&pte));
     212
     213                        as_pagemap_insert(&area->sh_info->pagemap,
     214                            (base + P2SZ(i)) - area->base,
     215                            PTE_GET_FRAME(&pte));
     216                        page_table_unlock(area->as, false);
     217
     218                        pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte));
     219                        frame_reference_add(pfn);
    230220                }
    231         }
     221
     222                cur = used_space_next(cur);
     223        }
     224
    232225        mutex_unlock(&area->sh_info->lock);
    233226}
     
    310303                        page_mapping_insert(AS, upage, frame,
    311304                            as_area_get_flags(area));
    312                         if (!used_space_insert(area, upage, 1))
     305                        if (!used_space_insert(&area->used_space, upage, 1))
    313306                                panic("Cannot insert used space.");
    314307                        mutex_unlock(&area->sh_info->lock);
     
    405398
    406399        page_mapping_insert(AS, upage, frame, as_area_get_flags(area));
    407         if (!used_space_insert(area, upage, 1))
     400        if (!used_space_insert(&area->used_space, upage, 1))
    408401                panic("Cannot insert used space.");
    409402
Note: See TracChangeset for help on using the changeset viewer.