How to assign a "memory priority" to the linux process?

I work on a small OpenWRT router, where exchange cannot be avoided, due to the limited amount of available bar (32 MB).

In most cases, the router does nothing else, however, from time to time, the postgresql database, which also runs on the router, is accessed. Due to the constant work, postgresql is completely unloaded, and the first few queries have a very high delay, which is bad because it is an interactively used system.

I already assigned a good value of -15 for postgres and +15 for tor, but this does not seem to have much effect on memory management. Setting swappiness = 1 globally also does not change the situation, because workarounds cannot be avoided, and since postgresql does not work most of the time, it will change anyway.

Is there any way for something like memory priority for a Linux process? I looked at cgroup-specific swappiness, however the only description I found was that it affects vs cache file-solution vs swap.

What I'm looking for is a parameter indicating that the linux kernel does not replace postgresql as aggressively as other processes (but I do not want mlock the whole process). Or would I assign swappiness = 80 as a system-wide and swapiness = 1 for postgresql to save postgresql in memory, and replace everything else if necessary?

+4
source share
3 answers

Strictly speaking, on Linux, you cannot prevent a process from transitioning. You may not switch completely using swapoff -a(and adding some RAM), but this can lead to system instability.

But in this case, Linux does a good job: the process used "from time to time" must be replaced, regardless of how much free memory you have. You may be using the wrong configuration. Can you host postgres on a different host, possibly with a faster hard drive?

BTW: postgres , , - : ( bash script) , , .

.. - :

#!/bin/bash
DBHOST=localhost
DBPORT=5432
DBNAME=theDBname
DBUSER=theUserName
THEQUERY="SELECT 1"

psql -h $DBHOST -p $DBPORT -d $DBNAME -U $DBUSER  -c "$THEQUERY"

cron .

- , "" , postgres , .

+3

, PostgreSQL, . , . OpenWRT PostgreSQL, -, - , , .

PostgreSQL , .

StefanoF Basile Starynkevitch PostgreSQL , , ​​ sqlite, , .

+2

mlock (2) , , madvise (2 ) (, Postgresql).

, , Postgresql ( Mysql) 32- . sqlite? ( ), , SQL- sqlite ( ). , (, FASTCGI HTTP-, libonion).

, ionice (1) (, , ).

+1

All Articles