0

I'm debugging NUMACTL on MIPS machine. In numa_police_memory() API, we have:

void numa_police_memory(void *mem, size_t size)
{
        int pagesize = numa_pagesize_int();
        unsigned long i;
        for (i = 0; i < size; i += pagesize)
                asm volatile("" :: "r" (((volatile unsigned char *)mem)[i]));
}

It seems "asm volatile("" :: "r" (((volatile unsigned char *)mem)[i]));" is used for reading a VM so that all the memory applied by previous mmap will be allocated onto some specific physical memory. But how does this asm code work? I can't read assembly language! Why is the first double quote empty???

Thanks

Greg Inozemtsev
  • 4,516
  • 23
  • 26

1 Answers1

0

Interestingly, there is no assembly code in this snippet at all, though the asm statement is used. It contains a blank assembly "program", an empty list of outputs, and a list of inputs. The input specification forces ((volatile unsigned char *)mem)[i] to be in a register. So all this bit of magic will do is generate a load of the first byte of each page (pre-fault the pages).

Greg Inozemtsev
  • 4,516
  • 23
  • 26
  • Register. See the [GCC manual](http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Simple-Constraints.html) for more info. What's happening here is the `asm` statement is telling GCC that the value needs to be in a register before the inline assembly is executed. GCC doesn't care that the assembly code is actually blank, and still produces a load. – Greg Inozemtsev Jun 29 '12 at 23:31