On Tue, Aug 23, 2016 at 8:41 AM, Robert Haas <robertmh...@gmail.com> wrote: > We could test to see how much it slows things down. But it > may be worth paying the cost even if it ends up being kinda expensive.
Here are some numbers from a Xeon E7-8830 @ 2.13GHz running Linux 3.10 running the attached program. It's fairly noisy and I didn't run super long tests with many repeats, but the general theme is visible. If you're actually going to USE the memory, it's only a small extra cost to have reserved seats. But if there's a strong chance you'll never access most of the memory, you might call it expensive. Segment size 1MB: base = shm_open + ftruncate + mmap + munmap + close = 5us base + fallocate = 38us base + memset = 332us base + fallocate + memset = 346us Segment size 1GB: base = shm_open + ftruncate + mmap + munmap + close = 10032us base + fallocate = 30774us base + memset = 602925us base + fallocate + memset = 655433us -- Thomas Munro http://www.enterprisedb.com
#include <fcntl.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <unistd.h> #define SEGMENT_NAME "/my_test_segment" int main(int argc, char *argv[]) { int loops, i; off_t size; bool fallocatep; bool memsetp; bool hugep; void *mem; if (argc != 6) { fprintf(stderr, "Usage: %s <loops> <size_in_mb> <fallocate?> <memset?> <huge?>\n", argv[0]); return EXIT_FAILURE; } loops = atoi(argv[1]); size = atoi(argv[2]) * 1024 * 1024; fallocatep = atoi(argv[3]) != 0; memsetp = atoi(argv[4]) != 0; hugep = atoi(argv[5]) != 0; for (i = 0; i < loops; ++i) { int fd; fd = shm_open(SEGMENT_NAME, O_CREAT | O_RDWR, S_IWUSR | S_IRUSR); if (fd < 0) { perror("shm_open"); goto cleanup; } if (ftruncate(fd, size)) { perror("ftruncate"); goto cleanup; } if (fallocatep && fallocate(fd, 0, 0, size)) { perror("fallocate"); goto cleanup; } mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED | (hugep ? MAP_HUGETLB : 0), fd, 0); if (mem == NULL) { fprintf(stderr, "mmap failed"); goto cleanup; } if (memsetp) memset(mem, 0, size); munmap(mem, size); close(fd); } shm_unlink(SEGMENT_NAME); return EXIT_SUCCESS; cleanup: shm_unlink(SEGMENT_NAME); return EXIT_FAILURE; }
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers