Using volatile ranges

Now that we have a kernel which can do volatile ranges, the next question is how to actually use this feature.

WARNING: THE INTERFACE HERE IS STILL BEING DESIGNED, SO THINGS MIGHT CHANGE IN THE FUTURE

The patchset provides a system call interface. So one could probably make vrange.h

#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>

#define SYS_vrange 314
#define VRANGE_VOLATILE 0
#define VRANGE_NOVOLATILE 1

static int vrange(unsigned long start, size_t length, int mode, int *purged)
{
return syscall(SYS_vrange, start, length, mode, purged);
}

int mvolatile(void *addr, size_t length)
{
return vrange((long) addr, length, VRANGE_VOLATILE, 0);
}

int mnovolatile(void *addr, size_t length, int *purged)
{
return vrange((long)addr, length, VRANGE_NOVOLATILE, purged);
}

Now that we have some code which can be used, let’s dissect this code fragment. Since we don’t have a vrange syscall in glibc yet, we have to make a vrange function which will call the syscall in a vrange enabled kernel. This system call takes 4 arguments. The first argument is the address where the volatile range starts. The next argument is the length that should be marked. The third argument is the key. It lets the kernel know whether to mark that range as VOLATILE or NOVOLATILE. The final argument is relevant only when we try to mark a range as NOVOLATILE. It lets the user know if a range had been purged while it was marked volatile.

When a range is marked a volatile, it enters what I like calling the schrodinger state. A user doesn’t know whether it is there or not, till it either marks it as non volatile or tries to access it. This leads to two ways of using this feature. One as we discussed the last time was to mark it as non volatile before use, and fixing up data if it had been purged. The second approach, which was suggested by Taras talks about sending a signal when accessing data which has been purged. Within the signal handler then one would mark it as non volatile, fix it up and let the application continue.

In order to get an idea about how to use these methods, take a look at the test cases in the git tree.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s