transfer physical memory page to swap disk
bernd at petrovitsch.priv.at
Sun Jan 19 11:59:15 EST 2020
To answer it from a somewhat different angle:
On Wed, 2020-01-15 at 18:01 +0530, Sumit Kumar wrote:
> Does C/C++ provide any API / system call that enables user to force the
> application to transfer some its physical pages to swap disk ? If so, is it
Short answer: No (and you do not want such a thing in the first
Longer answer: I don't think any normal application would force
some memory pages to the swap space (as it slows down) - quite
You can use open(..., O_DIRECT) to minimize cache effects
if that may help). WRF, you can implement pseudo-swapping
with that within your application.
madvise() has been mentioned in other mails.
One application has (usually) no knowledge about the rest of
the system - neither the amount of RAM nor the workload
(which may change over time) - or is at least written
So it's IMHO better to leave the kernels heuristics work
system-wide instead of "micro-optimizing" in some
application which will sooner or later interfere with
the kernels heuristics.
And - always - the next question is: how could
this API be abused/creatively used for the own
BTW: what's a real intended real-world application?
> also possible to obtain the least used page using some API ?
> AFAIK, linux kernel is supposed to do this as part of memory management. I
Yes - if there actually is swap space available (und don't
underestimate the number of systems running without a swap
space and CONFIG_SWAP=n in /boot/*config* - desktop and
servers are not everything in the world, more like a
small part ....).
> want to know if the kernel also exposes some API to enable users to control
> their application's memory management. I have many applications running at
> a time that cause too much memory consumption. I believe that experimenting
> with memory management can help.
The application can (and should) control it's memory management
anyways - just allocate as much as the application needs and
free it when it's no longer used.
For larger memeory areas (possibly with a self-build
malloc/free-equivalent or memory pools), the application
can mmap() it and munmap() it simply when it's done.
You can experiment with setting the process limits via
setrlimit() to smaller or larger values.
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
More information about the Kernelnewbies