I'd like to make sure that the memory allocated for a RAM disk never gets paged to a HDD. How can it be done in Ubuntu?
There are two types of filesystem commonly used for RAM-disks in Linux, ramfs and tmpfs.
tmpfs is the more modern on the two, and will put unneeded files in swap. As far as I am aware, there is no option to disable this.
ramfs is older and more primitive, and cannot use swap. Be warned, however, that unlike tmpfs a ramfs filesystem will continue to grow until you are out of RAM, at which point your system will hard-freeze. Therefore, if you use ramfs, you must be vigilant of its size at all times.