2002-07-15 15:59:50

by Weber, Frank

[permalink] [raw]
Subject: Process-wise swap-on/off option

Hello:

Is it possible to arrange that a Linux application
(or one of its threads) has the ability to

"... lock (a certain) stack and data segment ...
into memory so that it can't be swapped out"?

[This has been formulated as a requirement by one of
our analysts.]

I have been told that this is unlikely (except by
disabling swapout altogether (for all processes).

Any hints as to where to look for a solution (i.e.,
pointers to documentation or manuals where the ifs
and hows are explained) would be greatly appreciated.

Many thanks in advance,
F.P.Weber


P.S. Due to security on our mail-server i am unable to
enrol or subscribe to the news-group. Please cc me into
any replies. Thanks again.


2002-07-15 16:11:20

by Rik van Riel

[permalink] [raw]
Subject: Re: Process-wise swap-on/off option

On Mon, 15 Jul 2002, Weber, Frank wrote:

> "... lock (a certain) stack and data segment ...
> into memory so that it can't be swapped out"?

> Any hints as to where to look for a solution (i.e.,
> pointers to documentation or manuals where the ifs
> and hows are explained) would be greatly appreciated.

man mlock

Rik
--
Bravely reimplemented by the knights who say "NIH".

http://www.surriel.com/ http://distro.conectiva.com/

2002-07-15 16:13:40

by Hugh Dickins

[permalink] [raw]
Subject: Re: Process-wise swap-on/off option

On Mon, 15 Jul 2002, Weber, Frank wrote:
>
> Is it possible to arrange that a Linux application
> (or one of its threads) has the ability to
>
> "... lock (a certain) stack and data segment ...
> into memory so that it can't be swapped out"?

man 2 mlock
man 2 mlockall

Hugh

2002-07-15 16:37:20

by Richard B. Johnson

[permalink] [raw]
Subject: Re: Process-wise swap-on/off option

On Mon, 15 Jul 2002, Weber, Frank wrote:

> Hello:
>
> Is it possible to arrange that a Linux application
> (or one of its threads) has the ability to
>
> "... lock (a certain) stack and data segment ...
> into memory so that it can't be swapped out"?
>
> [This has been formulated as a requirement by one of
> our analysts.]
>
> I have been told that this is unlikely (except by
> disabling swapout altogether (for all processes).
>
> Any hints as to where to look for a solution (i.e.,
> pointers to documentation or manuals where the ifs
> and hows are explained) would be greatly appreciated.
>
> Many thanks in advance,
> F.P.Weber

Sure. mlock() and mlockall().

Cheers,
Dick Johnson

Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).

Windows-2000/Professional isn't.

2002-07-15 18:15:20

by Jesse Pollard

[permalink] [raw]
Subject: Re: Process-wise swap-on/off option

"Weber, Frank" <[email protected]>:
>
> Hello:
>
> Is it possible to arrange that a Linux application
> (or one of its threads) has the ability to
>
> "... lock (a certain) stack and data segment ...
> into memory so that it can't be swapped out"?
>
> [This has been formulated as a requirement by one of
> our analysts.]
>
> I have been told that this is unlikely (except by
> disabling swapout altogether (for all processes).
>
> Any hints as to where to look for a solution (i.e.,
> pointers to documentation or manuals where the ifs
> and hows are explained) would be greatly appreciated.
>
> Many thanks in advance,
> F.P.Weber
>
>
> P.S. Due to security on our mail-server i am unable to
> enrol or subscribe to the news-group. Please cc me into
> any replies. Thanks again.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

See manpage on "mlockall" system call. Also refer to the "mlock" system call.

I have a tendency to be suspicious of requirements to lock pages
in memory. If this is a dedicated, real-time task, then it is likely
to be "not really real-time" and does not really need to be locking
pages. I would suggest trying the application out without locking pages
first, since the fix for such paging is better handled by adding more
memory to the system instead. Locking pages means that you may get
failures due to the inability to handle short term memory pressure.

Another (cheap) way to prevent paging is to just not mount a swap file.

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: [email protected]

Any opinions expressed are solely my own.