Changeset fc47885 in mainline


Ignore:
Timestamp:
2011-02-03T13:41:07Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bd81386
Parents:
86d7bfa
Message:

keep track of the number of resident pages on-the-fly (do not traverse the B+ tree while reading sysinfo)
cstyle updates (mostly update of comments)

Location:
kernel/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/mm/as.h

    r86d7bfa rfc47885  
    115115       
    116116        /**
    117          * Number of processors on wich is this address space active.
    118          * Protected by asidlock.
     117         * Number of processors on which this
     118         * address space is active. Protected by
     119         * asidlock.
    119120         */
    120121        size_t cpu_refcount;
    121122       
    122         /**
    123          * Address space identifier.
    124          * Constant on architectures that do not support ASIDs.
    125          * Protected by asidlock.
     123        /** Address space identifier.
     124         *
     125         * Constant on architectures that do not
     126         * support ASIDs. Protected by asidlock.
     127         *
    126128         */
    127129        asid_t asid;
    128130       
    129         /** Number of references (i.e tasks that reference this as). */
     131        /** Number of references (i.e. tasks that reference this as). */
    130132        atomic_t refcount;
    131133       
     
    199201typedef struct {
    200202        mutex_t lock;
     203       
    201204        /** Containing address space. */
    202205        as_t *as;
    203206       
    204         /**
    205          * Flags related to the memory represented by the address space area.
    206          */
     207        /** Memory flags. */
    207208        unsigned int flags;
    208209       
    209         /** Attributes related to the address space area itself. */
     210        /** Address space area attributes. */
    210211        unsigned int attributes;
    211         /** Size of this area in multiples of PAGE_SIZE. */
     212       
     213        /** Number of pages in the area. */
    212214        size_t pages;
     215       
     216        /** Number of resident pages in the area. */
     217        size_t resident;
     218       
    213219        /** Base address of this area. */
    214220        uintptr_t base;
     221       
    215222        /** Map of used space. */
    216223        btree_t used_space;
    217224       
    218225        /**
    219          * If the address space area has been shared, this pointer will
    220          * reference the share info structure.
     226         * If the address space area is shared. this is
     227         * a reference to the share info structure.
    221228         */
    222229        share_info_t *sh_info;
     
    261268extern bool as_area_check_access(as_area_t *, pf_access_t);
    262269extern size_t as_area_get_size(uintptr_t);
    263 extern int used_space_insert(as_area_t *, uintptr_t, size_t);
    264 extern int used_space_remove(as_area_t *, uintptr_t, size_t);
    265 
     270extern bool used_space_insert(as_area_t *, uintptr_t, size_t);
     271extern bool used_space_remove(as_area_t *, uintptr_t, size_t);
    266272
    267273/* Interface to be implemented by architectures. */
  • kernel/generic/src/mm/as.c

    r86d7bfa rfc47885  
    8686 * Each architecture decides what functions will be used to carry out
    8787 * address space operations such as creating or locking page tables.
    88  *
    8988 */
    9089as_operations_t *as_operations = NULL;
    9190
    92 /**
    93  * Slab for as_t objects.
     91/** Slab for as_t objects.
    9492 *
    9593 */
    9694static slab_cache_t *as_slab;
    9795
    98 /**
    99  * This lock serializes access to the ASID subsystem.
    100  * It protects:
     96/** ASID subsystem lock.
     97 *
     98 * This lock protects:
    10199 * - inactive_as_with_asid_head list
    102100 * - as->asid for each as of the as_t type
     
    107105
    108106/**
    109  * This list contains address spaces that are not active on any
    110  * processor and that have valid ASID.
    111  *
     107 * Inactive address spaces (on all processors)
     108 * that have valid ASID.
    112109 */
    113110LIST_INITIALIZE(inactive_as_with_asid_head);
     
    123120        mutex_initialize(&as->lock, MUTEX_PASSIVE);
    124121       
    125         int rc = as_constructor_arch(as, flags);
    126        
    127         return rc;
     122        return as_constructor_arch(as, flags);
    128123}
    129124
    130125NO_TRACE static size_t as_destructor(void *obj)
    131126{
    132         as_t *as = (as_t *) obj;
    133         return as_destructor_arch(as);
     127        return as_destructor_arch((as_t *) obj);
    134128}
    135129
     
    146140                panic("Cannot create kernel address space.");
    147141       
    148         /* Make sure the kernel address space
     142        /*
     143         * Make sure the kernel address space
    149144         * reference count never drops to zero.
    150145         */
     
    195190{
    196191        DEADLOCK_PROBE_INIT(p_asidlock);
    197 
     192       
    198193        ASSERT(as != AS);
    199194        ASSERT(atomic_get(&as->refcount) == 0);
     
    203198         * lock its mutex.
    204199         */
    205 
     200       
    206201        /*
    207202         * We need to avoid deadlock between TLB shootdown and asidlock.
     
    210205         * disabled to prevent nested context switches. We also depend on the
    211206         * fact that so far no spinlocks are held.
    212          *
    213207         */
    214208        preemption_disable();
     
    235229        spinlock_unlock(&asidlock);
    236230        interrupts_restore(ipl);
    237 
     231       
    238232       
    239233        /*
     
    241235         * The B+tree must be walked carefully because it is
    242236         * also being destroyed.
    243          *
    244237         */
    245238        bool cond = true;
     
    268261/** Hold a reference to an address space.
    269262 *
    270  * Holding a reference to an address space prevents destruction of that address
    271  * space.
     263 * Holding a reference to an address space prevents destruction
     264 * of that address space.
    272265 *
    273266 * @param as Address space to be held.
     
    281274/** Release a reference to an address space.
    282275 *
    283  * The last one to release a reference to an address space destroys the address
    284  * space.
     276 * The last one to release a reference to an address space
     277 * destroys the address space.
    285278 *
    286279 * @param asAddress space to be released.
     
    310303        /*
    311304         * We don't want any area to have conflicts with NULL page.
    312          *
    313305         */
    314306        if (overlaps(va, size, (uintptr_t) NULL, PAGE_SIZE))
     
    321313         * record in the left neighbour, the leftmost record in the right
    322314         * neighbour and all records in the leaf node itself.
    323          *
    324315         */
    325316        btree_node_t *leaf;
     
    382373         * So far, the area does not conflict with other areas.
    383374         * Check if it doesn't conflict with kernel address space.
    384          *
    385375         */
    386376        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
     
    437427        area->attributes = attrs;
    438428        area->pages = SIZE2FRAMES(size);
     429        area->resident = 0;
    439430        area->base = base;
    440431        area->sh_info = NULL;
     
    479470         * to find out whether this is a miss or va belongs to an address
    480471         * space area found there.
    481          *
    482472         */
    483473       
     
    499489         * Second, locate the left neighbour and test its last record.
    500490         * Because of its position in the B+tree, it must have base < va.
    501          *
    502491         */
    503492        btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
     
    534523        /*
    535524         * Locate the area.
    536          *
    537525         */
    538526        as_area_t *area = find_area_and_lock(as, address);
     
    546534                 * Remapping of address space areas associated
    547535                 * with memory mapped devices is not supported.
    548                  *
    549536                 */
    550537                mutex_unlock(&area->lock);
     
    557544                 * Remapping of shared address space areas
    558545                 * is not supported.
    559                  *
    560546                 */
    561547                mutex_unlock(&area->lock);
     
    568554                /*
    569555                 * Zero size address space areas are not allowed.
    570                  *
    571556                 */
    572557                mutex_unlock(&area->lock);
     
    581566                 * Shrinking the area.
    582567                 * No need to check for overlaps.
    583                  *
    584568                 */
    585569               
     
    588572                /*
    589573                 * Start TLB shootdown sequence.
    590                  *
    591574                 */
    592575                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
     
    599582                 * is also the right way to remove part of the used_space
    600583                 * B+tree leaf list.
    601                  *
    602584                 */
    603585                bool cond = true;
     
    623605                                                 * completely in the resized
    624606                                                 * address space area.
    625                                                  *
    626607                                                 */
    627608                                                break;
     
    632613                                         * to b and c overlaps with the resized
    633614                                         * address space area.
    634                                          *
    635615                                         */
    636616                                       
     
    673653                /*
    674654                 * Finish TLB shootdown sequence.
    675                  *
    676655                 */
    677656               
     
    681660                /*
    682661                 * Invalidate software translation caches (e.g. TSB on sparc64).
    683                  *
    684662                 */
    685663                as_invalidate_translation_cache(as, area->base +
     
    692670                 * Growing the area.
    693671                 * Check for overlaps with other address space areas.
    694                  *
    695672                 */
    696673                if (!check_area_conflicts(as, address, pages * PAGE_SIZE,
     
    813790        /*
    814791         * Finish TLB shootdown sequence.
    815          *
    816792         */
    817793       
     
    821797         * Invalidate potential software translation caches (e.g. TSB on
    822798         * sparc64).
    823          *
    824799         */
    825800        as_invalidate_translation_cache(as, area->base, area->pages);
     
    839814        /*
    840815         * Remove the empty area from address space.
    841          *
    842816         */
    843817        btree_remove(&as->as_area_btree, base, NULL);
     
    881855                /*
    882856                 * Could not find the source address space area.
    883                  *
    884857                 */
    885858                mutex_unlock(&src_as->lock);
     
    891864                 * There is no backend or the backend does not
    892865                 * know how to share the area.
    893                  *
    894866                 */
    895867                mutex_unlock(&src_area->lock);
     
    918890         * First, prepare the area for sharing.
    919891         * Then it will be safe to unlock it.
    920          *
    921892         */
    922893        share_info_t *sh_info = src_area->sh_info;
     
    930901                /*
    931902                 * Call the backend to setup sharing.
    932                  *
    933903                 */
    934904                src_area->backend->share(src_area);
     
    949919         * The flags of the source area are masked against dst_flags_mask
    950920         * to support sharing in less privileged mode.
    951          *
    952921         */
    953922        as_area_t *dst_area = as_area_create(dst_as, dst_flags_mask, src_size,
     
    966935         * fully initialized. Clear the AS_AREA_ATTR_PARTIAL
    967936         * attribute and set the sh_info.
    968          *
    969937         */
    970938        mutex_lock(&dst_as->lock);
     
    989957NO_TRACE bool as_area_check_access(as_area_t *area, pf_access_t access)
    990958{
     959        ASSERT(mutex_locked(&area->lock));
     960       
    991961        int flagmap[] = {
    992962                [PF_ACCESS_READ] = AS_AREA_READ,
     
    994964                [PF_ACCESS_EXEC] = AS_AREA_EXEC
    995965        };
    996 
    997         ASSERT(mutex_locked(&area->lock));
    998966       
    999967        if (!(area->flags & flagmap[access]))
     
    10661034        /*
    10671035         * Compute total number of used pages in the used_space B+tree
    1068          *
    10691036         */
    10701037        size_t used_pages = 0;
     
    10881055        /*
    10891056         * Start TLB shootdown sequence.
    1090          *
    10911057         */
    10921058        ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid, area->base,
     
    10961062         * Remove used pages from page tables and remember their frame
    10971063         * numbers.
    1098          *
    10991064         */
    11001065        size_t frame_idx = 0;
     
    11271092        /*
    11281093         * Finish TLB shootdown sequence.
    1129          *
    11301094         */
    11311095       
     
    11351099         * Invalidate potential software translation caches (e.g. TSB on
    11361100         * sparc64).
    1137          *
    11381101         */
    11391102        as_invalidate_translation_cache(as, area->base, area->pages);
     
    12171180                 * No area contained mapping for 'page'.
    12181181                 * Signal page fault to low-level handler.
    1219                  *
    12201182                 */
    12211183                mutex_unlock(&AS->lock);
     
    12371199                 * The address space area is not backed by any backend
    12381200                 * or the backend cannot handle page faults.
    1239                  *
    12401201                 */
    12411202                mutex_unlock(&area->lock);
     
    12491210         * To avoid race condition between two page faults on the same address,
    12501211         * we need to make sure the mapping has not been already inserted.
    1251          *
    12521212         */
    12531213        pte_t *pte;
     
    12671227        /*
    12681228         * Resort to the backend page fault handler.
    1269          *
    12701229         */
    12711230        if (area->backend->page_fault(area, page, access) != AS_PF_OK) {
     
    13221281                 * preemption is disabled. We should not be
    13231282                 * holding any other lock.
    1324                  *
    13251283                 */
    13261284                (void) interrupts_enable();
     
    13421300                         * list of inactive address spaces with assigned
    13431301                         * ASID.
    1344                          *
    13451302                         */
    13461303                        ASSERT(old_as->asid != ASID_INVALID);
     
    13531310                 * Perform architecture-specific tasks when the address space
    13541311                 * is being removed from the CPU.
    1355                  *
    13561312                 */
    13571313                as_deinstall_arch(old_as);
     
    13601316        /*
    13611317         * Second, prepare the new address space.
    1362          *
    13631318         */
    13641319        if ((new_as->cpu_refcount++ == 0) && (new_as != AS_KERNEL)) {
     
    13761331         * Perform architecture-specific steps.
    13771332         * (e.g. write ASID to hardware register etc.)
    1378          *
    13791333         */
    13801334        as_install_arch(new_as);
     
    13951349{
    13961350        ASSERT(mutex_locked(&area->lock));
    1397 
     1351       
    13981352        return area_flags_to_page_flags(area->flags);
    13991353}
     
    15161470 * @param count Number of page to be marked.
    15171471 *
    1518  * @return Zero on failure and non-zero on success.
    1519  *
    1520  */
    1521 int used_space_insert(as_area_t *area, uintptr_t page, size_t count)
     1472 * @return False on failure or true on success.
     1473 *
     1474 */
     1475bool used_space_insert(as_area_t *area, uintptr_t page, size_t count)
    15221476{
    15231477        ASSERT(mutex_locked(&area->lock));
     
    15301484                /*
    15311485                 * We hit the beginning of some used space.
    1532                  *
    1533                  */
    1534                 return 0;
     1486                 */
     1487                return false;
    15351488        }
    15361489       
    15371490        if (!leaf->keys) {
    15381491                btree_insert(&area->used_space, page, (void *) count, leaf);
    1539                 return 1;
     1492                goto success;
    15401493        }
    15411494       
     
    15511504                 * somewhere between the rightmost interval of
    15521505                 * the left neigbour and the first interval of the leaf.
    1553                  *
    15541506                 */
    15551507               
     
    15591511                    left_cnt * PAGE_SIZE)) {
    15601512                        /* The interval intersects with the left interval. */
    1561                         return 0;
     1513                        return false;
    15621514                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    15631515                    right_cnt * PAGE_SIZE)) {
    15641516                        /* The interval intersects with the right interval. */
    1565                         return 0;
     1517                        return false;
    15661518                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    15671519                    (page + count * PAGE_SIZE == right_pg)) {
     
    15691521                         * The interval can be added by merging the two already
    15701522                         * present intervals.
    1571                          *
    15721523                         */
    15731524                        node->value[node->keys - 1] += count + right_cnt;
    15741525                        btree_remove(&area->used_space, right_pg, leaf);
    1575                         return 1;
     1526                        goto success;
    15761527                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    15771528                        /*
    15781529                         * The interval can be added by simply growing the left
    15791530                         * interval.
    1580                          *
    15811531                         */
    15821532                        node->value[node->keys - 1] += count;
    1583                         return 1;
     1533                        goto success;
    15841534                } else if (page + count * PAGE_SIZE == right_pg) {
    15851535                        /*
     
    15871537                         * the right interval down and increasing its size
    15881538                         * accordingly.
    1589                          *
    15901539                         */
    15911540                        leaf->value[0] += count;
    15921541                        leaf->key[0] = page;
    1593                         return 1;
     1542                        goto success;
    15941543                } else {
    15951544                        /*
    15961545                         * The interval is between both neigbouring intervals,
    15971546                         * but cannot be merged with any of them.
    1598                          *
    15991547                         */
    16001548                        btree_insert(&area->used_space, page, (void *) count,
    16011549                            leaf);
    1602                         return 1;
     1550                        goto success;
    16031551                }
    16041552        } else if (page < leaf->key[0]) {
     
    16091557                 * Investigate the border case in which the left neighbour does
    16101558                 * not exist but the interval fits from the left.
    1611                  *
    16121559                 */
    16131560               
     
    16151562                    right_cnt * PAGE_SIZE)) {
    16161563                        /* The interval intersects with the right interval. */
    1617                         return 0;
     1564                        return false;
    16181565                } else if (page + count * PAGE_SIZE == right_pg) {
    16191566                        /*
     
    16211568                         * right interval down and increasing its size
    16221569                         * accordingly.
    1623                          *
    16241570                         */
    16251571                        leaf->key[0] = page;
    16261572                        leaf->value[0] += count;
    1627                         return 1;
     1573                        goto success;
    16281574                } else {
    16291575                        /*
    16301576                         * The interval doesn't adjoin with the right interval.
    16311577                         * It must be added individually.
    1632                          *
    16331578                         */
    16341579                        btree_insert(&area->used_space, page, (void *) count,
    16351580                            leaf);
    1636                         return 1;
     1581                        goto success;
    16371582                }
    16381583        }
     
    16491594                 * somewhere between the leftmost interval of
    16501595                 * the right neigbour and the last interval of the leaf.
    1651                  *
    16521596                 */
    16531597               
     
    16571601                    left_cnt * PAGE_SIZE)) {
    16581602                        /* The interval intersects with the left interval. */
    1659                         return 0;
     1603                        return false;
    16601604                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    16611605                    right_cnt * PAGE_SIZE)) {
    16621606                        /* The interval intersects with the right interval. */
    1663                         return 0;
     1607                        return false;
    16641608                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    16651609                    (page + count * PAGE_SIZE == right_pg)) {
     
    16671611                         * The interval can be added by merging the two already
    16681612                         * present intervals.
    1669                          *
    16701613                         */
    16711614                        leaf->value[leaf->keys - 1] += count + right_cnt;
    16721615                        btree_remove(&area->used_space, right_pg, node);
    1673                         return 1;
     1616                        goto success;
    16741617                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    16751618                        /*
    16761619                         * The interval can be added by simply growing the left
    16771620                         * interval.
    1678                          *
    16791621                         */
    1680                         leaf->value[leaf->keys - 1] +=  count;
    1681                         return 1;
     1622                        leaf->value[leaf->keys - 1] += count;
     1623                        goto success;
    16821624                } else if (page + count * PAGE_SIZE == right_pg) {
    16831625                        /*
     
    16851627                         * the right interval down and increasing its size
    16861628                         * accordingly.
    1687                          *
    16881629                         */
    16891630                        node->value[0] += count;
    16901631                        node->key[0] = page;
    1691                         return 1;
     1632                        goto success;
    16921633                } else {
    16931634                        /*
    16941635                         * The interval is between both neigbouring intervals,
    16951636                         * but cannot be merged with any of them.
    1696                          *
    16971637                         */
    16981638                        btree_insert(&area->used_space, page, (void *) count,
    16991639                            leaf);
    1700                         return 1;
     1640                        goto success;
    17011641                }
    17021642        } else if (page >= leaf->key[leaf->keys - 1]) {
     
    17071647                 * Investigate the border case in which the right neighbour
    17081648                 * does not exist but the interval fits from the right.
    1709                  *
    17101649                 */
    17111650               
     
    17131652                    left_cnt * PAGE_SIZE)) {
    17141653                        /* The interval intersects with the left interval. */
    1715                         return 0;
     1654                        return false;
    17161655                } else if (left_pg + left_cnt * PAGE_SIZE == page) {
    17171656                        /*
    17181657                         * The interval can be added by growing the left
    17191658                         * interval.
    1720                          *
    17211659                         */
    17221660                        leaf->value[leaf->keys - 1] += count;
    1723                         return 1;
     1661                        goto success;
    17241662                } else {
    17251663                        /*
    17261664                         * The interval doesn't adjoin with the left interval.
    17271665                         * It must be added individually.
    1728                          *
    17291666                         */
    17301667                        btree_insert(&area->used_space, page, (void *) count,
    17311668                            leaf);
    1732                         return 1;
     1669                        goto success;
    17331670                }
    17341671        }
     
    17381675         * only between two other intervals of the leaf. The two border cases
    17391676         * were already resolved.
    1740          *
    17411677         */
    17421678        btree_key_t i;
     
    17501686                        /*
    17511687                         * The interval fits between left_pg and right_pg.
    1752                          *
    17531688                         */
    17541689                       
     
    17581693                                 * The interval intersects with the left
    17591694                                 * interval.
    1760                                  *
    17611695                                 */
    1762                                 return 0;
     1696                                return false;
    17631697                        } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    17641698                            right_cnt * PAGE_SIZE)) {
     
    17661700                                 * The interval intersects with the right
    17671701                                 * interval.
    1768                                  *
    17691702                                 */
    1770                                 return 0;
     1703                                return false;
    17711704                        } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    17721705                            (page + count * PAGE_SIZE == right_pg)) {
     
    17741707                                 * The interval can be added by merging the two
    17751708                                 * already present intervals.
    1776                                  *
    17771709                                 */
    17781710                                leaf->value[i - 1] += count + right_cnt;
    17791711                                btree_remove(&area->used_space, right_pg, leaf);
    1780                                 return 1;
     1712                                goto success;
    17811713                        } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    17821714                                /*
    17831715                                 * The interval can be added by simply growing
    17841716                                 * the left interval.
    1785                                  *
    17861717                                 */
    17871718                                leaf->value[i - 1] += count;
    1788                                 return 1;
     1719                                goto success;
    17891720                        } else if (page + count * PAGE_SIZE == right_pg) {
    17901721                                /*
     
    17921723                                 * base of the right interval down and
    17931724                                 * increasing its size accordingly.
    1794                                  *
    17951725                                 */
    17961726                                leaf->value[i] += count;
    17971727                                leaf->key[i] = page;
    1798                                 return 1;
     1728                                goto success;
    17991729                        } else {
    18001730                                /*
     
    18021732                                 * intervals, but cannot be merged with any of
    18031733                                 * them.
    1804                                  *
    18051734                                 */
    18061735                                btree_insert(&area->used_space, page,
    18071736                                    (void *) count, leaf);
    1808                                 return 1;
     1737                                goto success;
    18091738                        }
    18101739                }
     
    18131742        panic("Inconsistency detected while adding %zu pages of used "
    18141743            "space at %p.", count, (void *) page);
     1744       
     1745success:
     1746        area->resident += count;
     1747        return true;
    18151748}
    18161749
     
    18231756 * @param count Number of page to be marked.
    18241757 *
    1825  * @return Zero on failure and non-zero on success.
    1826  *
    1827  */
    1828 int used_space_remove(as_area_t *area, uintptr_t page, size_t count)
     1758 * @return False on failure or true on success.
     1759 *
     1760 */
     1761bool used_space_remove(as_area_t *area, uintptr_t page, size_t count)
    18291762{
    18301763        ASSERT(mutex_locked(&area->lock));
     
    18371770                /*
    18381771                 * We are lucky, page is the beginning of some interval.
    1839                  *
    18401772                 */
    18411773                if (count > pages) {
    1842                         return 0;
     1774                        return false;
    18431775                } else if (count == pages) {
    18441776                        btree_remove(&area->used_space, page, leaf);
    1845                         return 1;
     1777                        goto success;
    18461778                } else {
    18471779                        /*
    18481780                         * Find the respective interval.
    18491781                         * Decrease its size and relocate its start address.
    1850                          *
    18511782                         */
    18521783                        btree_key_t i;
     
    18551786                                        leaf->key[i] += count * PAGE_SIZE;
    18561787                                        leaf->value[i] -= count;
    1857                                         return 1;
     1788                                        goto success;
    18581789                                }
    18591790                        }
     1791                       
    18601792                        goto error;
    18611793                }
     
    18761808                                 * removed by updating the size of the bigger
    18771809                                 * interval.
    1878                                  *
    18791810                                 */
    18801811                                node->value[node->keys - 1] -= count;
    1881                                 return 1;
     1812                                goto success;
    18821813                        } else if (page + count * PAGE_SIZE <
    18831814                            left_pg + left_cnt*PAGE_SIZE) {
     
    18881819                                 * the original interval and also inserting a
    18891820                                 * new interval.
    1890                                  *
    18911821                                 */
    18921822                                size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     
    18951825                                btree_insert(&area->used_space, page +
    18961826                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    1897                                 return 1;
     1827                                goto success;
    18981828                        }
    18991829                }
    1900                 return 0;
     1830               
     1831                return false;
    19011832        } else if (page < leaf->key[0])
    1902                 return 0;
     1833                return false;
    19031834       
    19041835        if (page > leaf->key[leaf->keys - 1]) {
     
    19141845                                 * interval of the leaf and can be removed by
    19151846                                 * updating the size of the bigger interval.
    1916                                  *
    19171847                                 */
    19181848                                leaf->value[leaf->keys - 1] -= count;
    1919                                 return 1;
     1849                                goto success;
    19201850                        } else if (page + count * PAGE_SIZE < left_pg +
    19211851                            left_cnt * PAGE_SIZE) {
     
    19261856                                 * original interval and also inserting a new
    19271857                                 * interval.
    1928                                  *
    19291858                                 */
    19301859                                size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     
    19331862                                btree_insert(&area->used_space, page +
    19341863                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    1935                                 return 1;
     1864                                goto success;
    19361865                        }
    19371866                }
    1938                 return 0;
     1867               
     1868                return false;
    19391869        }
    19401870       
    19411871        /*
    19421872         * The border cases have been already resolved.
    1943          * Now the interval can be only between intervals of the leaf. 
     1873         * Now the interval can be only between intervals of the leaf.
    19441874         */
    19451875        btree_key_t i;
     
    19621892                                         * be removed by updating the size of
    19631893                                         * the bigger interval.
    1964                                          *
    19651894                                         */
    19661895                                        leaf->value[i - 1] -= count;
    1967                                         return 1;
     1896                                        goto success;
    19681897                                } else if (page + count * PAGE_SIZE <
    19691898                                    left_pg + left_cnt * PAGE_SIZE) {
     
    19831912                                            count * PAGE_SIZE, (void *) new_cnt,
    19841913                                            leaf);
    1985                                         return 1;
     1914                                        goto success;
    19861915                                }
    19871916                        }
    1988                         return 0;
     1917                       
     1918                        return false;
    19891919                }
    19901920        }
     
    19931923        panic("Inconsistency detected while removing %zu pages of used "
    19941924            "space from %p.", count, (void *) page);
     1925       
     1926success:
     1927        area->resident -= count;
     1928        return true;
    19951929}
    19961930
  • kernel/generic/src/sysinfo/stats.c

    r86d7bfa rfc47885  
    160160static size_t get_task_virtmem(as_t *as)
    161161{
    162         size_t result = 0;
    163 
    164162        /*
    165          * We are holding some spinlocks here and therefore are not allowed to
    166          * block. Only attempt to lock the address space and address space area
    167          * mutexes conditionally. If it is not possible to lock either object,
    168          * allow the statistics to be inexact by skipping the respective object.
    169          *
    170          * Note that it may be infinitely better to let the address space
    171          * management code compute these statistics as it proceeds instead of
    172          * having them calculated over and over again here.
     163         * We are holding spinlocks here and therefore are not allowed to
     164         * block. Only attempt to lock the address space and address space
     165         * area mutexes conditionally. If it is not possible to lock either
     166         * object, return inexact statistics by skipping the respective object.
    173167         */
    174 
     168       
    175169        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    176                 return result * PAGE_SIZE;
     170                return 0;
     171       
     172        size_t pages = 0;
    177173       
    178174        /* Walk the B+ tree and count pages */
    179         link_t *cur;
    180         for (cur = as->as_area_btree.leaf_head.next;
    181             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
    182                 btree_node_t *node =
    183                     list_get_instance(cur, btree_node_t, leaf_link);
    184                
    185                 unsigned int i;
    186                 for (i = 0; i < node->keys; i++) {
    187                         as_area_t *area = node->value[i];
    188                        
    189                         if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    190                                 continue;
    191                         result += area->pages;
    192                         mutex_unlock(&area->lock);
    193                 }
    194         }
    195        
    196         mutex_unlock(&as->lock);
    197        
    198         return result * PAGE_SIZE;
    199 }
    200 
    201 /** Get the resident (used) size of a virtual address space
    202  *
    203  * @param as Address space.
    204  *
    205  * @return Size of the resident (used) virtual address space (bytes).
    206  *
    207  */
    208 static size_t get_task_resmem(as_t *as)
    209 {
    210         size_t result = 0;
    211        
    212         /*
    213          * We are holding some spinlocks here and therefore are not allowed to
    214          * block. Only attempt to lock the address space and address space area
    215          * mutexes conditionally. If it is not possible to lock either object,
    216          * allow the statistics to be inexact by skipping the respective object.
    217          *
    218          * Note that it may be infinitely better to let the address space
    219          * management code compute these statistics as it proceeds instead of
    220          * having them calculated over and over again here.
    221          */
    222        
    223         if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    224                 return result * PAGE_SIZE;
    225        
    226         /* Walk the B+ tree of AS areas */
    227175        link_t *cur;
    228176        for (cur = as->as_area_btree.leaf_head.next;
     
    238186                                continue;
    239187                       
    240                         /* Walk the B+ tree of resident pages */
    241                         link_t *rcur;
    242                         for (rcur = area->used_space.leaf_head.next;
    243                             rcur != &area->used_space.leaf_head; rcur = rcur->next) {
    244                                 btree_node_t *rnode =
    245                                     list_get_instance(rcur, btree_node_t, leaf_link);
    246                                
    247                                 unsigned int j;
    248                                 for (j = 0; j < rnode->keys; j++)
    249                                         result += (size_t) rnode->value[i];
    250                         }
    251                        
     188                        pages += area->pages;
    252189                        mutex_unlock(&area->lock);
    253190                }
     
    256193        mutex_unlock(&as->lock);
    257194       
    258         return result * PAGE_SIZE;
     195        return (pages << PAGE_WIDTH);
     196}
     197
     198/** Get the resident (used) size of a virtual address space
     199 *
     200 * @param as Address space.
     201 *
     202 * @return Size of the resident (used) virtual address space (bytes).
     203 *
     204 */
     205static size_t get_task_resmem(as_t *as)
     206{
     207        /*
     208         * We are holding spinlocks here and therefore are not allowed to
     209         * block. Only attempt to lock the address space and address space
     210         * area mutexes conditionally. If it is not possible to lock either
     211         * object, return inexact statistics by skipping the respective object.
     212         */
     213       
     214        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
     215                return 0;
     216       
     217        size_t pages = 0;
     218       
     219        /* Walk the B+ tree and count pages */
     220        link_t *cur;
     221        for (cur = as->as_area_btree.leaf_head.next;
     222            cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     223                btree_node_t *node =
     224                    list_get_instance(cur, btree_node_t, leaf_link);
     225               
     226                unsigned int i;
     227                for (i = 0; i < node->keys; i++) {
     228                        as_area_t *area = node->value[i];
     229                       
     230                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
     231                                continue;
     232                       
     233                        pages += area->resident;
     234                        mutex_unlock(&area->lock);
     235                }
     236        }
     237       
     238        mutex_unlock(&as->lock);
     239       
     240        return (pages << PAGE_WIDTH);
    259241}
    260242
Note: See TracChangeset for help on using the changeset viewer.