VirtualBox

Ignore:
Timestamp:
Apr 20, 2010 1:36:22 PM (15 years ago)
Author:
vboxsync
Message:

NAT: destructor and fini hooks are called from slirp_uma_free.
zone_drain and uma_zone_exhausted_nolock are implemented to migrate items from second zone to master one on demand.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/misc.c

    r28502 r28520  
    208208    struct item *it;
    209209    uma_zone_t zone;
     210    uma_zone_t master_zone;
    210211    Assert(item);
    211212    it = &((struct item *)item)[-1];
     
    217218    Assert(zone->magic == ZONE_MAGIC);
    218219    LIST_REMOVE(it, list);
     220    if (zone->pfFini)
     221    {
     222        zone->pfFini(zone->pData, item, zone->size);
     223    }
     224    if (zone->pfDtor)
     225    {
     226        zone->pfDtor(zone->pData, item, zone->size, NULL);
     227    }
    219228    LIST_INSERT_HEAD(&zone->free_items, it, list);
    220229    zone->cur_items--;
     
    245254{
    246255    uma_zone_t zone;
    247 #if 0
    248     if (master->pfAlloc != NULL)
    249         zone = (uma_zone_t)master->pfAlloc(master, sizeof(struct uma_zone), NULL, 0);
    250 #endif
    251256    Assert(master);
    252257    zone = RTMemAllocZ(sizeof(struct uma_zone));
     
    335340    struct item *it;
    336341    Assert(zone->magic == ZONE_MAGIC);
    337     if (zone->pfFree == NULL)
    338         return;
    339 
     342    Assert((zone->pfFree));
    340343    Assert((mem));
     344
    341345    RTCritSectEnter(&zone->csZone);
    342346    it = &((struct item *)mem)[-1];
    343     if (it->magic != ITEM_MAGIC)
    344     {
    345         Log(("NAT:UMA: %p seems to be allocated on heap ... freeing\n", mem));
    346         RTMemFree(mem);
     347    Assert((it->magic == ITEM_MAGIC));
     348    Assert((zone->magic == ZONE_MAGIC && zone == it->zone));
     349
     350    zone->pfFree(mem,  0, 0);
     351    RTCritSectLeave(&zone->csZone);
     352}
     353
     354int uma_zone_exhausted_nolock(uma_zone_t zone)
     355{
     356    int fExhausted;
     357    RTCritSectEnter(&zone->csZone);
     358    fExhausted = (zone->cur_items == zone->max_items);
     359    RTCritSectLeave(&zone->csZone);
     360    return fExhausted;
     361}
     362
     363void zone_drain(uma_zone_t zone)
     364{
     365    struct item *it;
     366    uma_zone_t master_zone;
     367    /* vvl: Huh? What to do with zone which hasn't got backstore ? */
     368    Assert((zone->master_zone));
     369    master_zone = zone->master_zone;
     370    while(!LIST_EMPTY(&zone->free_items))
     371    {
     372        it = LIST_FIRST(&zone->free_items);
     373        RTCritSectEnter(&zone->csZone);
     374        LIST_REMOVE(it, list);
     375        zone->max_items--;
    347376        RTCritSectLeave(&zone->csZone);
    348         return;
    349     }
    350     Assert((zone->magic == ZONE_MAGIC && zone == it->zone));
    351 
    352     if (zone->pfDtor)
    353         zone->pfDtor(zone->pData, mem, zone->size, flags);
    354     zone->pfFree(mem,  0, 0);
    355     RTCritSectLeave(&zone->csZone);
    356 }
    357 
    358 int uma_zone_exhausted_nolock(uma_zone_t zone)
    359 {
    360     return 0;
    361 }
    362 
    363 void zone_drain(uma_zone_t zone)
    364 {
     377        it->zone = master_zone;
     378        RTCritSectEnter(&master_zone->csZone);
     379        LIST_INSERT_HEAD(&master_zone->free_items, it, list);
     380        master_zone->cur_items--;
     381        RTCritSectLeave(&master_zone->csZone);
     382    }
    365383}
    366384
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette