Volatile ranges with fallocate()
Posted Jun 9, 2012 2:38 UTC (Sat) by
foom (subscriber, #14868)
In reply to:
Volatile ranges with fallocate() by ncm
Parent article:
Volatile ranges with fallocate()
Sure, but this API is a really convoluted and irritating way to make users go about things..
Consider the two options (note: code written in comment editor, may not actually work; error handling omitted):
Option 1:
volatile_storage = mmap(0, 163840, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, 0, 0);
API option 2, retardedly difficult for no good reason:
int fd = -1;
char *name;
while (fd == -1) {
name = tmpnam(NULL);
fd = shm_open(name, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
}
shm_unlink(name);
ftruncate(fd, 163840);
volatile_storage = mmap(NULL, 163840, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
Then, the usage is ridiculous too:
Sane API:
madvise(object_addr, 4096, MADV_VOLATILE);
Insane API:
// First implement a function "find_mapping_info_for" which does e.g. a binary
// search through a list of shm_open'd regions, to find one that contains the
// address in question. Then...
mapping_info = find_mapping_info_for(object_addr);
fallocate(mapping_info.fd, FALLOCATE_FL_MARK_VOLATILE, object_addr - mapping_info.base_addr, 4096);
Why would anyone want the second API?...it basically requires users to go through an extra song-and-dance at mmap time, to keep extra file descriptors open, and to track which file descriptors belong to which memory regions, for seemingly no reason.
(
Log in to post comments)