VirtualBox

Changeset 28034 in vbox


Ignore:
Timestamp:
Apr 7, 2010 8:38:00 AM (15 years ago)
Author:
vboxsync
Message:

NAT: BSD mbufs zones allocated at the moment when the number of elements is known.
sub-zones don't allocate but borrow slices from master zones.

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/bsd/kern/kern_mbuf.c

    r27869 r28034  
    313313            NULL, NULL,
    314314            MSIZE - 1, UMA_ZONE_MAXBUCKET);
     315        if (nmbclusters > 0)
     316                uma_zone_set_max(zone_mbuf, nmbclusters);
    315317
    316318        zone_clust = uma_zcreate(MBUF_CLUSTER_MEM_NAME, MCLBYTES,
  • trunk/src/VBox/Devices/Network/slirp/misc.c

    r27571 r28034  
    144144    LIST_HEAD(RT_NOTHING, item) free_items;
    145145    uma_zone_t master_zone;
     146    void *area;
    146147};
    147148
     
    151152{
    152153    struct item *it;
     154    uint8_t *sub_area;
     155    int cChunk;
     156    int i;
    153157    RTCritSectEnter(&zone->csZone);
     158free_list_check:
    154159    if (!LIST_EMPTY(&zone->free_items))
    155160    {
    156         /*
    157          * @todo (r=vvl) here should be some
    158          * accounting of extra items in case
    159          * breakthrough barrier
    160          */
    161         if (LIST_EMPTY(&zone->free_items))
    162         {
    163             RTCritSectLeave(&zone->csZone);
    164             return NULL;
    165         }
     161        zone->cur_items++;
    166162        it = LIST_FIRST(&zone->free_items);
    167163        LIST_REMOVE(it, list);
    168164        LIST_INSERT_HEAD(&zone->used_items, it, list);
    169         goto allocated;
    170     }
    171 
    172     /*@todo 'Z' should be depend on flag */
    173     it = RTMemAllocZ(sizeof(struct item) + zone->size);
    174     if (it == NULL)
    175     {
    176         Log(("NAT: uma no memory"));
     165        if (zone->pfInit)
     166            zone->pfInit(zone->pData, (void *)&it[1], zone->size, M_DONTWAIT);
     167        RTCritSectLeave(&zone->csZone);
     168        return (void *)&it[1];
     169    }
     170
     171    if (zone->master_zone == NULL)
     172    {
     173        /* We're on master zone and we cant allocate more */
     174        Log2(("NAT: no room on %s zone\n", zone->name));
    177175        RTCritSectLeave(&zone->csZone);
    178176        return NULL;
    179177    }
     178
     179    /* we're on sub-zone we need get chunk of master zone and split
     180     * it for sub-zone conforming chunks.
     181     */
     182    sub_area = slirp_uma_alloc(zone->master_zone, zone->master_zone->size, NULL, 0);
     183    if (sub_area == NULL)
     184    {
     185        /*No room on master*/
     186        Log2(("NAT: no room on %s zone for %s zone\n", zone->master_zone->name, zone->name));
     187        RTCritSectLeave(&zone->csZone);
     188        return NULL;
     189    }
     190    zone->max_items ++;
     191    it = &((struct item *)sub_area)[-1];
     192    /*@todo '+ zone->size' should be depend on flag */
     193    memset(it, 0, sizeof(struct item));
     194    it->zone = zone;
    180195    it->magic = ITEM_MAGIC;
    181     LIST_INSERT_HEAD(&zone->used_items, it, list);
    182     zone->cur_items++;
    183     it->zone = zone;
     196    LIST_INSERT_HEAD(&zone->free_items, it, list);
    184197    if (zone->cur_items >= zone->max_items)
    185198        LogRel(("NAT: zone(%s) has reached it maximum\n", zone->name));
    186 
    187 allocated:
    188     if (zone->pfInit)
    189         zone->pfInit(zone->pData, (void *)&it[1], zone->size, M_DONTWAIT);
    190     RTCritSectLeave(&zone->csZone);
    191     return (void *)&it[1];
     199    goto free_list_check;
     200
    192201}
    193202
     
    211220                       ctor_t ctor, dtor_t dtor, zinit_t init, zfini_t fini, int flags1, int flags2)
    212221{
    213     uma_zone_t zone = RTMemAllocZ(sizeof(struct uma_zone) + size);
     222    uma_zone_t zone = RTMemAllocZ(sizeof(struct uma_zone));
    214223    Assert((pData));
    215224    zone->magic = ZONE_MAGIC;
     
    235244        zone = (uma_zone_t)master->pfAlloc(master, sizeof(struct uma_zone), NULL, 0);
    236245#endif
     246    Assert(master);
    237247    zone = RTMemAllocZ(sizeof(struct uma_zone));
    238248    if (zone == NULL)
     
    250260    zone->pfFree = slirp_uma_free;
    251261    zone->size = master->size;
     262    zone->master_zone = master;
    252263    RTCritSectInit(&zone->csZone);
    253264    return zone;
     
    256267void uma_zone_set_max(uma_zone_t zone, int max)
    257268{
     269    int i = 0;
     270    struct item *it;
    258271    zone->max_items = max;
     272    zone->area = RTMemAllocZ(max * (sizeof(struct item) + zone->size));
     273    for (; i < max; ++i)
     274    {
     275        it = (struct item *)(((uint8_t *)zone->area) + i*(sizeof(struct item) + zone->size));
     276        it->magic = ITEM_MAGIC;
     277        it->zone = zone;
     278        LIST_INSERT_HEAD(&zone->free_items, it, list);
     279    }
     280   
    259281}
    260282
     
    378400    RTCritSectEnter(&zone->csZone);
    379401    LogRel(("NAT: zone(nm:%s, used:%d)\n", zone->name, zone->cur_items));
    380     /* freeing */
    381     while (!LIST_EMPTY(&zone->free_items))
    382     {
    383         it = LIST_FIRST(&zone->free_items);
    384         LIST_REMOVE(it, list);
    385         RTMemFree(it);
    386     }
    387     while (zone->master_zone != NULL && !LIST_EMPTY(&zone->used_items))
    388     {
    389         it = LIST_FIRST(&zone->used_items);
    390         LIST_REMOVE(it, list);
    391         RTMemFree(it);
    392     }
     402    if (zone->master_zone)
     403        RTMemFree(zone->area);
    393404    RTCritSectLeave(&zone->csZone);
    394405    RTCritSectDelete(&zone->csZone);
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r27976 r28034  
    199199    DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
    200200#else
    201     nn = recv(so->s, iov[0].iov_base, iov[0].iov_len, 0);
     201    nn = recv(so->s, iov[0].iov_base, iov[0].iov_len, (so->so_tcpcb->t_force? MSG_OOB:0));
    202202#endif
    203203    if (nn <= 0)
    204204    {
    205 #ifdef RT_OS_WINDOWS
    206205        /*
    207206         * Special case for WSAEnumNetworkEvents: If we receive 0 bytes that
     
    213212        int status, ignored;
    214213        unsigned long pending = 0;
    215         status = WSAIoctl(so->s, FIONREAD, NULL, 0, &pending, sizeof(unsigned long), &ignored, NULL, NULL);
     214        status = ioctl(so->s, FIONREAD, &pending);
    216215        if (status < 0)
    217             LogRel(("NAT:error in WSAIoctl: %d\n", WSAGetLastError()));
     216            LogRel(("NAT:error in WSAIoctl: %d\n", errno));
    218217        if (nn == 0 && (pending != 0))
    219218        {
     
    222221            return 0;
    223222        }
    224 #endif
    225223        if (   nn < 0
    226224            && (   errno == EINTR
     
    306304{
    307305    struct tcpcb *tp = sototcpcb(so);
     306    ssize_t ret;
    308307
    309308    DEBUG_CALL("sorecvoob");
     
    318317     * urgent data.
    319318     */
    320     soread(pData, so);
     319    ret = soread(pData, so);
    321320    tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
    322321    tp->t_force = 1;
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