Bill Randerson
Bill Randerson

Reputation: 1088

Is there any trick to deliberately swap out a page in linux kernel?

I was trying to debug some issues and I want to conjure up a scenario when physical memory page is swapped out. Is there any trick to do this?

Linux kernel: 3.10.x

Platform: arm

Thank a lot.

Upvotes: 2

Views: 278

Answers (1)

Gil Hamilton
Gil Hamilton

Reputation: 12357

If you really mean "in the linux kernel" then yes. There are functions that cause a page to be swapped that you could invoke directly. See pageout() as a starting point. I suspect it would be non-trivial to get this all setup just right.

If you mean "is there a way to do it from user-space", the answer is no. Well, not directly (AFAIK anyway). Your best bet would be to not touch the page in question further, meanwhile allocate lots of other memory (this could be done in a separate process) and touch all those other pages so that the one you care about becomes least recently used and hence a candidate for paging.

Not sure how -- from user space -- you would detect that it actually had been paged though. The point of virtual memory is to hide that from you. I suppose you could have a high likelihood of knowing it had been paged after the fact by timing how long it takes to access the memory once you finally do so.

Upvotes: 1

Related Questions