Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
From: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
To: Sumit Kumar <sumit686215@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: transfer physical memory page to swap disk
Date: Sun, 19 Jan 2020 17:59:15 +0100
Message-ID: <b78b892cfdf3642ac52aca75c2ee92d4dd546ade.camel@petrovitsch.priv.at> (raw)
In-Reply-To: <CACFOd6VGhvQ=EfDZyNwP_j-+u51MtwXrvsKnTgXQ0oYXKzKZtQ@mail.gmail.com>

Hi all!

To answer it from a somewhat different angle:

On Wed, 2020-01-15 at 18:01 +0530, Sumit Kumar wrote:
> Hi,
> 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
place).

Longer answer: I don't think any normal application would force
some memory pages to the swap space (as it slows down) - quite
the contrary.
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
that way.
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
benefit/...?

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.

MfG,
	Bernd
-- 
Bernd Petrovitsch                  Email : bernd@petrovitsch.priv.at
                     LUGA : http://www.luga.at


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      parent reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15 12:31 Sumit Kumar
2020-01-15 12:42 ` aleix sanchis ramírez
2020-01-15 12:53 ` Anupam Kapoor
2020-01-18 15:10   ` Valdis Klētnieks
2020-01-19 10:01     ` Sumit Kumar
2020-01-19 10:55     ` Anupam Kapoor
2020-01-19 11:14       ` Valdis Klētnieks
2020-01-19 12:45         ` Anupam Kapoor
2020-01-19 13:18           ` Valdis Klētnieks
2020-01-19 16:01             ` Anupam Kapoor
2020-01-19 16:59 ` Bernd Petrovitsch [this message]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b78b892cfdf3642ac52aca75c2ee92d4dd546ade.camel@petrovitsch.priv.at \
    --to=bernd@petrovitsch.priv.at \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=sumit686215@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git