# swapping when there is no swap?

## mathfeel

Sometimes, especially when I have browser with ~20 tabs open and running a large emerge in the background (e.g. icedtea, chromium), the system starts to hit the hard drive hard. Cursor can still move, but the system is otherwise non-responsive. I though this maybe due to the system swapping. But in a recent boot, I commented out the line in /etc/fstab that points to the swap. Why is the system still hitting the hard drive?

Basically, I would like certain running user process (in particular, emerge or ebuild) to crash when physical memory limit is reached. Is this possible?

----------

## Hu

If you have insufficient memory to keep everything resident at once, and there is no swap, then the only remaining option is to begin discarding pages that can be reread from the hard disk.  The executable and readonly data portions of programs and libraries can be reread from the disk at need, so they are never written to swap.  It is likely that the kernel started discarding such pages, then was reading them back soon after because you had accessed them again.

You may be able to constrain some processes by using resource limits and/or cgroups.  However, this would only control their growth.  It would not ensure that the OOM killer was invoked prematurely and directed to kill those specific processes.

----------

## wcg

Try leaving swap enabled and setting

```

PORTAGE_NICENESS="15"

```

in /etc/make.conf. (I do not know if it is necessary to quote this value.

I was simply being consistent with other variables defined in /etc/make.conf.)

Someone mentioned this in another thread recently, and it works

pretty well for emerges concurrent with interactive use. The running emerge

will normally be lower priority than anything else running, and the kernel

will set an ionice value for it calculated from its priority. Even if it is doing a

lot of disk i/o and using a lot of cpu when gcc or g++ are running,

anything else that wants to run (like X event handling) gets scheduled

ahead of it.

----------

## cach0rr0

 *mathfeel wrote:*   

> Sometimes, especially when I have browser with ~20 tabs open and running a large emerge in the background (e.g. icedtea, chromium), the system starts to hit the hard drive hard. Cursor can still move, but the system is otherwise non-responsive. I though this maybe due to the system swapping. But in a recent boot, I commented out the line in /etc/fstab that points to the swap. Why is the system still hitting the hard drive?
> 
> Basically, I would like certain running user process (in particular, emerge or ebuild) to crash when physical memory limit is reached. Is this possible?

 

on the browser side at least, most of them will have some kind of local storage (e.g. sqlite) for various bits and pieces

i would wager this is a non-trivial chunk of it.

----------

## mathfeel

The problem is when this happens, I can't really run top or ps because the system is unresponsive. The best I can do is SysRq+RE out. So it is not completely clear to me if it is a memory issue. I assumed that it is because it happens only when multitab-browser + heavy emerge occurs.

Information I left out is that I have 6GB of RAM, and /var/tmp/ is a 3GB maximum tmpfs (the other tmpfs mount is /dev/shm, but that's usually near empty). I was under the impression that tmpfs do not actually use physical memory until it is needed. Either way, seems to me even with 3GB of physical memory available should be plentiful.

I will try to adjust PORTAGE_NICENESS. My current setting is 10. As for cgroups, I need research more information on that.

----------

## PaulBredbury

 *mathfeel wrote:*   

> Sometimes, especially when I have browser with ~20 tabs open and running a large emerge in the background (e.g. icedtea, chromium), the system starts to hit the hard drive hard.

 

Probably 2 things you need:

1.  sqlite trick to avoid calling sync.

2.  ionice, as well as nice, your emerge, to stop it from hogging the drive. Example I use (different distro):  In /root/.bashrc

```
alias lin="ionice -c3 schedtool -D -e /sbin/lin"
```

Just change "lin" to "emerge", and that should be OK. I'm using BFS. Also see other tweaks.

----------

## eccerr0r

I don't think anyone should rely on OOMkiller to kill any process that uses more RAM than available.  Fortunately for the most part, an emerge, when out of RAM, will tend to be the program that will get killed when out of RAM.  However there is a remote chance that a sleeping process gets awakened and gets zapped as it tries to allocate more RAM.  Not that it happens often but this can happen and this is not behavior that's predictable.

You should have swap...and prepare for the times when you think you'll be out of RAM.  And keep less stuff in RAM!

Swap unfortunately tends to be highest priority.  This is because the computer cannot have forward progress executing code while something is in swap - it has to fetch from disk else it's starved of code to run.  The only time it may be OK to have code stuck indefinitely in swap is if it's marked as a "idle" process in terms of real-time scheduling priority.

----------

