How would that work at the operating system level, which is where page in and outs occur? You might be able to tell some OS's not to page out a specific page, but with variable length data that becomes impossible
For instance if you're running in a VM, all bets are off, beacuse the host can and will page you out guest phys memory.
As you note, you can't just mlock memory handed out by the ordinary allocator, as you never know when it will be free to munlock.