netmap_mem2.c (685dc743dc3b5645e34836464128e1c0558b404b) | netmap_mem2.c (d1bdc2821fcd416ab9b238580386eb605a6128d0) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (C) 2012-2014 Matteo Landi 5 * Copyright (C) 2012-2016 Luigi Rizzo 6 * Copyright (C) 2012-2016 Giuseppe Lettieri 7 * All rights reserved. 8 * --- 1270 unchanged lines hidden (view full) --- 1279 1280 /* 1281 * Free each cluster allocated in 1282 * netmap_finalize_obj_allocator(). The cluster start 1283 * addresses are stored at multiples of p->_clusterentries 1284 * in the lut. 1285 */ 1286 for (i = 0; i < p->objtotal; i += p->_clustentries) { | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (C) 2012-2014 Matteo Landi 5 * Copyright (C) 2012-2016 Luigi Rizzo 6 * Copyright (C) 2012-2016 Giuseppe Lettieri 7 * All rights reserved. 8 * --- 1270 unchanged lines hidden (view full) --- 1279 1280 /* 1281 * Free each cluster allocated in 1282 * netmap_finalize_obj_allocator(). The cluster start 1283 * addresses are stored at multiples of p->_clusterentries 1284 * in the lut. 1285 */ 1286 for (i = 0; i < p->objtotal; i += p->_clustentries) { |
1287 contigfree(p->lut[i].vaddr, p->_clustsize, M_NETMAP); | 1287 free(p->lut[i].vaddr, M_NETMAP); |
1288 } 1289 nm_free_lut(p->lut, p->objtotal); 1290 } 1291 p->lut = NULL; 1292 p->objtotal = 0; 1293 p->memtotal = 0; 1294 p->numclusters = 0; 1295 p->objfree = 0; --- 101 unchanged lines hidden (view full) --- 1397 return 0; 1398} 1399 1400/* call with NMA_LOCK held */ 1401static int 1402netmap_finalize_obj_allocator(struct netmap_obj_pool *p) 1403{ 1404 int i; /* must be signed */ | 1288 } 1289 nm_free_lut(p->lut, p->objtotal); 1290 } 1291 p->lut = NULL; 1292 p->objtotal = 0; 1293 p->memtotal = 0; 1294 p->numclusters = 0; 1295 p->objfree = 0; --- 101 unchanged lines hidden (view full) --- 1397 return 0; 1398} 1399 1400/* call with NMA_LOCK held */ 1401static int 1402netmap_finalize_obj_allocator(struct netmap_obj_pool *p) 1403{ 1404 int i; /* must be signed */ |
1405 size_t n; | |
1406 1407 if (p->lut) { 1408 /* if the lut is already there we assume that also all the 1409 * clusters have already been allocated, possibly by somebody 1410 * else (e.g., extmem). In the latter case, the alloc_done flag 1411 * will remain at zero, so that we will not attempt to 1412 * deallocate the clusters by ourselves in 1413 * netmap_reset_obj_allocator. --- 11 unchanged lines hidden (view full) --- 1425 nm_prerr("Unable to create lookup table for '%s'", p->name); 1426 goto clean; 1427 } 1428 1429 /* 1430 * Allocate clusters, init pointers 1431 */ 1432 | 1405 1406 if (p->lut) { 1407 /* if the lut is already there we assume that also all the 1408 * clusters have already been allocated, possibly by somebody 1409 * else (e.g., extmem). In the latter case, the alloc_done flag 1410 * will remain at zero, so that we will not attempt to 1411 * deallocate the clusters by ourselves in 1412 * netmap_reset_obj_allocator. --- 11 unchanged lines hidden (view full) --- 1424 nm_prerr("Unable to create lookup table for '%s'", p->name); 1425 goto clean; 1426 } 1427 1428 /* 1429 * Allocate clusters, init pointers 1430 */ 1431 |
1433 n = p->_clustsize; | |
1434 for (i = 0; i < (int)p->objtotal;) { 1435 int lim = i + p->_clustentries; 1436 char *clust; 1437 1438 /* 1439 * XXX Note, we only need contigmalloc() for buffers attached 1440 * to native interfaces. In all other cases (nifp, netmap rings 1441 * and even buffers for VALE ports or emulated interfaces) we 1442 * can live with standard malloc, because the hardware will not 1443 * access the pages directly. 1444 */ | 1432 for (i = 0; i < (int)p->objtotal;) { 1433 int lim = i + p->_clustentries; 1434 char *clust; 1435 1436 /* 1437 * XXX Note, we only need contigmalloc() for buffers attached 1438 * to native interfaces. In all other cases (nifp, netmap rings 1439 * and even buffers for VALE ports or emulated interfaces) we 1440 * can live with standard malloc, because the hardware will not 1441 * access the pages directly. 1442 */ |
1445 clust = contigmalloc(n, M_NETMAP, M_NOWAIT | M_ZERO, | 1443 clust = contigmalloc(p->_clustsize, M_NETMAP, M_NOWAIT | M_ZERO, |
1446 (size_t)0, -1UL, PAGE_SIZE, 0); 1447 if (clust == NULL) { 1448 /* 1449 * If we get here, there is a severe memory shortage, 1450 * so halve the allocated memory to reclaim some. 1451 */ 1452 nm_prerr("Unable to create cluster at %d for '%s' allocator", 1453 i, p->name); 1454 if (i < 2) /* nothing to halve */ 1455 goto out; 1456 lim = i / 2; 1457 for (i--; i >= lim; i--) { 1458 if (i % p->_clustentries == 0 && p->lut[i].vaddr) | 1444 (size_t)0, -1UL, PAGE_SIZE, 0); 1445 if (clust == NULL) { 1446 /* 1447 * If we get here, there is a severe memory shortage, 1448 * so halve the allocated memory to reclaim some. 1449 */ 1450 nm_prerr("Unable to create cluster at %d for '%s' allocator", 1451 i, p->name); 1452 if (i < 2) /* nothing to halve */ 1453 goto out; 1454 lim = i / 2; 1455 for (i--; i >= lim; i--) { 1456 if (i % p->_clustentries == 0 && p->lut[i].vaddr) |
1459 contigfree(p->lut[i].vaddr, 1460 n, M_NETMAP); | 1457 free(p->lut[i].vaddr, M_NETMAP); |
1461 p->lut[i].vaddr = NULL; 1462 } 1463 out: 1464 p->objtotal = i; 1465 /* we may have stopped in the middle of a cluster */ 1466 p->numclusters = (i + p->_clustentries - 1) / p->_clustentries; 1467 break; 1468 } --- 1501 unchanged lines hidden --- | 1458 p->lut[i].vaddr = NULL; 1459 } 1460 out: 1461 p->objtotal = i; 1462 /* we may have stopped in the middle of a cluster */ 1463 p->numclusters = (i + p->_clustentries - 1) / p->_clustentries; 1464 break; 1465 } --- 1501 unchanged lines hidden --- |