ericzma
ericzma

Reputation: 763

Exchange the mapping to two physical pages of two pages in virtual memory

Here is the situation:

A process has two pages vp1 and vp2. These two pages are mapped to 2 physical pages or 2 pages in the swap. Let's call these physical (or in swap) pages pp1 and pp2. The mapping is:

vp1->pp1

vp2->pp2

Now, if I want to change the mapping to:

vp1->pp2

vp2->pp1

That means, reading from vp2 by the process will get the content originally in vp1. Is there a method to do this without changing the kernel on Linux?

Upvotes: 1

Views: 98

Answers (2)

Eric Postpischil
Eric Postpischil

Reputation: 222591

Yes, but you have to do some work first. One way to accomplish this is to create two shared memory objects. Then you can map and unmap the shared memory objects in the process address space. See the system calls shmat, shmdt, shmget, and shmctl for details.

Mapping and unmapping is likely to take considerable time, so it may not save time over using some pointer scheme to choose which addresses a process uses to access data.

Upvotes: 2

Art
Art

Reputation: 20392

No. Not in the general case if you want to keep your system working. But if you control how the mappings are created you can create them with mmap of a file or an object from shm_open and when you need to swap them just overwrite them with mmap(... MAP_FIXED ...).

Upvotes: 0

Related Questions