Skip to contentSkip to conversation

memmove syscall

DISCUSSION Nikolay Igotti 3 participants 4 messages Feb 4, 2004 – Feb 7, 2004

lore
Share & tools
lore
#0 lore raw

Maybe this is kinda crazy (or known) idea, but why don't we create
syscall
allowing large copies by just manipulating MMU page table, i.e.

asmlinkage long sys_memmove(void* dst, void* src, int size) {
if ((dst & ~PAGE_SIZE) ||(src & ~PAGE_SIZE) || (size & ~PAGE_SIZE))

               return -EINVAL;

return mmu_remap_pages(src, dst, size / PAGE_SIZE);
}

This could be useful for copying of large amounts of data when we know that source not gonna be used anymore (typical example is garbage collector).

Please reply directly, as I'm not on the list.

Nikolay.

#1 lore raw
Quoted 4 lines · Nikolay Igotti

Maybe this is kinda crazy (or known) idea, but why don't we create
syscall allowing large copies by just manipulating MMU page table, i.e.

   return mmu_remap_pages(src,  dst, size / PAGE_SIZE);

Did you look at mremap(2) ?

Linux has had mremap for a very very long time...

Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
#2 lore raw
Quoted 11 lines · Rik van Riel
Quoted 4 lines · Nikolay Igotti

Maybe this is kinda crazy (or known) idea, but why don't we create
syscall allowing large copies by just manipulating MMU page table, i.e.

Quoted 7 lines
Quoted 3 lines
  return mmu_remap_pages(src,  dst, size / PAGE_SIZE);

Did you look at mremap(2) ?

If I get it correctly:

mremap expands (or shrinks) an existing memory mapping,
potentially
moving it at the same time (controlled by the flags argument
and the
available virtual address space).

And this syscall can be only used for realloc() kind of stuff, as you're not allowed to change virtual address of some page to desired value, but whole point is to allow very fast page-aligned memory moving (or to be exact - swapping, as I guess dst pages should be mapped where src ones was mapped before, to keep things sane).

Obvious applications for this syscall - Large Object Spaces in different memory management systems
- if space is allocated in pages, defragmentation becomes very cheap.

Also there could be other applications, like execution-time program obfuscators, just shuffling program stack and data in fancy way :), or tools for improvment of interactive behavior of KDE/Gnome by putting images (or other location-neutral(pointerless) data) into nearby virtual memory locations (so they'll be swapped in and out together, as they should).

If it can be achieved with existing syscalls, I'd be happy to know how
to do that :).

Thanks,
Nikolay

#3 lore raw
Quoted 10 lines · Nikolay Igotti

mremap expands (or shrinks) an existing memory mapping,
potentially
moving it at the same time (controlled by the flags argument
and the
available virtual address space).

And this syscall can be only used for realloc() kind of stuff, as you're not allowed to change
virtual address of some page to desired value,

Have you looked at the MREMAP_FIXED flag?

-- Jamie