Ignore:
Timestamp:
2012-11-06T22:51:56Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1107050
Parents:
338810f
Message:

Define AS_AREA_NORESERVE and allow its use in the anonymous backend.

  • NORESERVE areas do not reserve physical memory in advance.
  • NORESERVE areas do not block while waiting for physical memory.
  • if a NORESERVE area cannot allocate a page of physical memory, it kills the task instantly
File:
1 edited

Legend:

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

    r338810f r692bd3f2  
    7474bool anon_create(as_area_t *area)
    7575{
     76        if (area->flags & AS_AREA_NORESERVE)
     77                return true;
     78
    7679        return reserve_try_alloc(area->pages);
    7780}
     
    7982bool anon_resize(as_area_t *area, size_t new_pages)
    8083{
     84        if (area->flags & AS_AREA_NORESERVE)
     85                return true;
     86
    8187        if (new_pages > area->pages)
    8288                return reserve_try_alloc(new_pages - area->pages);
     
    100106        ASSERT(mutex_locked(&area->as->lock));
    101107        ASSERT(mutex_locked(&area->lock));
     108        ASSERT(!(area->flags & AS_AREA_NORESERVE));
    102109
    103110        /*
     
    139146void anon_destroy(as_area_t *area)
    140147{
     148        if (area->flags & AS_AREA_NORESERVE)
     149                return;
     150
    141151        reserve_free(area->pages);
    142152}
     
    225235                 *   the different causes
    226236                 */
    227                 kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
     237
     238                unsigned int flags;
     239
     240                if (area->flags & AS_AREA_NORESERVE) {
     241                        /*
     242                         * This is a NORESERVE area, which means that no
     243                         * physical memory has been reserved beforehands.
     244                         * We therefore need to make an atomic and reserving
     245                         * allocation.
     246                         */
     247                        flags = FRAME_ATOMIC;
     248                } else {
     249                        /*
     250                         * The physical memory has already been reserved
     251                         * when this part of the area was created. Avoid
     252                         * double reservation by using the appropriate flag.
     253                         */
     254                        flags = FRAME_NO_RESERVE;
     255                }
     256
     257                kpage = km_temporary_page_get(&frame, flags);
     258                if (!kpage)
     259                        return AS_PF_FAULT;
    228260                memsetb((void *) kpage, PAGE_SIZE, 0);
    229261                km_temporary_page_put(kpage);
     
    255287        ASSERT(mutex_locked(&area->lock));
    256288
    257         frame_free_noreserve(frame);
     289        if (area->flags & AS_AREA_NORESERVE) {
     290                /*
     291                 * In case of the NORESERVE areas, physical memory will not be
     292                 * unreserved when the area is destroyed so we need to use the
     293                 * normal unreserving frame_free().
     294                 */
     295                frame_free(frame);
     296        } else {
     297                /*
     298                 * The reserve will be given back when the area is destroyed or
     299                 * resized, so use the frame_free_noreserve() which does not
     300                 * manipulate the reserve or it would be given back twice.
     301                 */
     302                frame_free_noreserve(frame);
     303        }
    258304}
    259305
Note: See TracChangeset for help on using the changeset viewer.