Thread: SHM_LOCK under Linux ... do we use this?

SHM_LOCK under Linux ... do we use this?

From
"Marc G. Fournier"
Date:
Under FreeBSD, we have an option (kern.ipc.shm_use_phys=1) that doesn't 
allow shared memory to be swap'd ... under Linux, there is apparently an 
application level option that can be used for this purpose:
    A privileged user can prevent or allow swapping of a shared memory    segment with the following cmds:
       SHM_LOCK    prevents swapping of a shared memory segment. The user                   must fault in any pages
thatare required to be present                   after ...
 

I've done a grep through the code, to see if its something that we do use, and
it doesn't seem to come back with anything ... I believe its considered 
common knowledge that 'swapping' for a database is evil, so am wondering 
if there is some way that we can make use of this to help reduce/eliminate 
that from happening?

The "A privileged user can..." part makes me think no, but figured I'd ask 
...

 ----
Marc G. Fournier           Hub.Org Networking Services (http://www.hub.org)
Email: scrappy@hub.org           Yahoo!: yscrappy              ICQ: 7615664


Re: SHM_LOCK under Linux ... do we use this?

From
Tom Lane
Date:
"Marc G. Fournier" <scrappy@postgresql.org> writes:
>      A privileged user can prevent or allow swapping of a shared memory
>      segment with the following cmds:
>         SHM_LOCK    prevents swapping of a shared memory segment. The user
>                     must fault in any pages that are required to be present
>                     after ...

> I've done a grep through the code, to see if its something that we do use, and
> it doesn't seem to come back with anything ...

No, we don't.  "privileged user" means root, so it's not possible for us
to set that.
        regards, tom lane


Re: SHM_LOCK under Linux ... do we use this?

From
"Marc G. Fournier"
Date:
On Wed, 17 Aug 2005, Tom Lane wrote:

> "Marc G. Fournier" <scrappy@postgresql.org> writes:
>>      A privileged user can prevent or allow swapping of a shared memory
>>      segment with the following cmds:
>>         SHM_LOCK    prevents swapping of a shared memory segment. The user
>>                     must fault in any pages that are required to be present
>>                     after ...
>
>> I've done a grep through the code, to see if its something that we do use, and
>> it doesn't seem to come back with anything ...
>
> No, we don't.  "privileged user" means root, so it's not possible for us
> to set that.

Ya, that's what I was figuring, but figured someone with more Linux 
knowledge might know a 'loophole' we could exploit :)

----
Marc G. Fournier           Hub.Org Networking Services (http://www.hub.org)
Email: scrappy@hub.org           Yahoo!: yscrappy              ICQ: 7615664


Re: SHM_LOCK under Linux ... do we use this?

From
"Qingqing Zhou"
Date:
""Marc G. Fournier"" <scrappy@postgresql.org> writes
>
> I've done a grep through the code, to see if its something that we do use,
and
> it doesn't seem to come back with anything ... I believe its considered
> common knowledge that 'swapping' for a database is evil, so am wondering
> if there is some way that we can make use of this to help reduce/eliminate
> that from happening?
>

There are some similar flags in other OS could help us to keep the memory
resident in. However, it is not always a net win if we force it. This is
because other parts of the system (like fork a process) may need memory, so
the OS will pick up the "coldest" memory to be swapped. If we have already
use our memory intensively, I don't think we will be swapped. On the
contrary, if we force OS not to swap some memory, we may get other penalties
like our processes have to be sarcrificed.

Regards,
Qingqing




Re: SHM_LOCK under Linux ... do we use this?

From
Jan Wieck
Date:
On 8/18/2005 5:14 AM, Qingqing Zhou wrote:
> ""Marc G. Fournier"" <scrappy@postgresql.org> writes
>>
>> I've done a grep through the code, to see if its something that we do use,
> and
>> it doesn't seem to come back with anything ... I believe its considered
>> common knowledge that 'swapping' for a database is evil, so am wondering
>> if there is some way that we can make use of this to help reduce/eliminate
>> that from happening?
>>
> 
> There are some similar flags in other OS could help us to keep the memory
> resident in. However, it is not always a net win if we force it. This is
> because other parts of the system (like fork a process) may need memory, so
> the OS will pick up the "coldest" memory to be swapped. If we have already
> use our memory intensively, I don't think we will be swapped. On the
> contrary, if we force OS not to swap some memory, we may get other penalties
> like our processes have to be sarcrificed.

If this happens often to be PostgreSQL's shared buffers, then you have 
configured too many of them.


Jan

-- 
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #