forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit439f617
committed
Add palloc_aligned() to allow aligned memory allocations
This introduces palloc_aligned() and MemoryContextAllocAligned() whichallow callers to obtain memory which is allocated to the given size andalso aligned to the specified alignment boundary. The alignmentboundaries may be any power-of-2 value. Currently, the alignment iscapped at 2^26, however, we don't expect values anything like that large.The primary expected use case is to align allocations to perhaps CPUcache line size or to maybe I/O page size. Certain use cases can benefitfrom having aligned memory by either having better performance or morepredictable performance.The alignment is achieved by requesting 'alignto' additional bytes fromthe underlying allocator function and then aligning the address that isreturned to the requested alignment. This obviously does waste somememory, so alignments should be kept as small as what is required.It's also important to note that these alignment bytes eat into themaximum allocation size. So something like:palloc_aligned(MaxAllocSize, 64, 0);will not work as we cannot request MaxAllocSize + 64 bytes.Additionally, because we're just requesting the requested size plus thealignment requirements from the given MemoryContext, if that context isthe Slab allocator, then since slab can only provide chunks of the sizethat's specified when the slab context is created, then this is not goingto work. Slab will generate an error to indicate that the requested sizeis not supported.The alignment that is requested in palloc_aligned() is stored along withthe allocated memory. This allows the alignment to remain intact throughrepalloc() calls.Author: Andres Freund, David RowleyReviewed-by: Maxim Orlov, Andres Freund, John NaylorDiscussion:https://postgr.es/m/CAApHDvpxLPUMV1mhxs6g7GNwCP6Cs6hfnYQL5ffJQTuFAuxt8A%40mail.gmail.com1 parent701c881 commit439f617
File tree
8 files changed
+308
-13
lines changed- src
- backend/utils
- cache
- mmgr
- include/utils
8 files changed
+308
-13
lines changedLines changed: 2 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
763 | 763 |
| |
764 | 764 |
| |
765 | 765 |
| |
766 |
| - | |
767 | 766 |
| |
768 | 767 |
| |
769 | 768 |
| |
| |||
807 | 806 |
| |
808 | 807 |
| |
809 | 808 |
| |
810 |
| - | |
811 |
| - | |
| 809 | + | |
| 810 | + | |
812 | 811 |
| |
813 | 812 |
| |
814 | 813 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
| 16 | + | |
16 | 17 |
| |
17 | 18 |
| |
18 | 19 |
| |
|
Lines changed: 132 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + |
Lines changed: 148 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
30 | 30 |
| |
31 | 31 |
| |
32 | 32 |
| |
| 33 | + | |
33 | 34 |
| |
34 | 35 |
| |
35 | 36 |
| |
| |||
84 | 85 |
| |
85 | 86 |
| |
86 | 87 |
| |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
87 | 103 |
| |
88 | 104 |
| |
89 | 105 |
| |
| |||
110 | 126 |
| |
111 | 127 |
| |
112 | 128 |
| |
113 |
| - | |
114 |
| - | |
115 |
| - | |
116 |
| - | |
117 |
| - | |
118 | 129 |
| |
119 | 130 |
| |
120 | 131 |
| |
| |||
1298 | 1309 |
| |
1299 | 1310 |
| |
1300 | 1311 |
| |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
1301 | 1431 |
| |
1302 | 1432 |
| |
1303 | 1433 |
| |
| |||
1306 | 1436 |
| |
1307 | 1437 |
| |
1308 | 1438 |
| |
| 1439 | + | |
1309 | 1440 |
| |
1310 | 1441 |
| |
1311 | 1442 |
| |
1312 | 1443 |
| |
1313 |
| - | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
1314 | 1449 |
| |
1315 | 1450 |
| |
1316 | 1451 |
| |
| |||
1320 | 1455 |
| |
1321 | 1456 |
| |
1322 | 1457 |
| |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
1323 | 1461 |
| |
1324 | 1462 |
| |
1325 | 1463 |
| |
| |||
1346 | 1484 |
| |
1347 | 1485 |
| |
1348 | 1486 |
| |
1349 |
| - | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
1350 | 1491 |
| |
1351 | 1492 |
| |
1352 | 1493 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 | 3 |
| |
| 4 | + | |
4 | 5 |
| |
5 | 6 |
| |
6 | 7 |
| |
|
0 commit comments
Comments
(0)