[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Isolated Web Co Session crash Firefox-ESR



On Wed, Dec 06, 2023 at 06:04:36AM +0100, tomas@tuxteam.de wrote:
> On Wed, Dec 06, 2023 at 02:42:32AM +0800, jeremy ardley wrote:
> 
> > I have discovered a magic bullet for solving running out of memory
> >   sudo sync; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
> > Sadly it looks like I'll need to do this daily,
> 
> It's the browsers eating your memory. That's what they do.

  I've had problems with Firefox eating my swap on both Linux and FreeBSD.
  My fix has been to run the swap2ram script below hourly.

-- 
Karl Vogel                      I don't speak for anyone but myself

Constipational carry.
  --NY Post 28 Nov "Suspect found hiding handgun in his rectum" comment #4

# ----------------------------------------------------------------------
#!/bin/ksh
#<swap2ram: get swap manually back into RAM.
#           Send results to stdout unless running from cron.

export PATH=/bin:/usr/bin:/sbin
export LC_ALL=C
tag=${0##*/}

# I set the environment variable "CRON" to yes in all crontabs.
case "$CRON" in
    yes)
        logmsg ()  { logger -t "$tag" "$@" ; }
        logfile () { fn="$1"; logger -t $tag -f "$fn" ; }
        ;;

    *)
        logmsg ()  { echo "$(date '+%F %T') $tag: $@"; }
        logfile () { fn="$1"; cat "$fn" ; }
        ;;
esac

die () { logmsg "FATAL: $@"; exit 1; }

# Do we need root to run this?
needroot () {
    case "$1" in
        "") action='do' ;;
        *)  action="$1" ;;
    esac

    id | grep 'uid=0(root)' > /dev/null
    case "$?" in
        0) ;;
        *) die "You must be root to $action this." ;;
    esac
}

# Make sure we have permission and a safe tempfile.
needroot
systype=$(uname -s | tr A-Z a-z)

tmp=$(mktemp -q "/tmp/$tag.XXXXXX")
case "$?" in
    0)  test -f "$tmp" || die "$tmp: tempfile not created" ;;
    *)  die "$tmp: mktemp failed" ;;
esac

# Real work starts here.  Check for OS-specific instructions.
case "$systype" in
    freebsd)
        ( swapoff -a && swapon -a ) >> $tmp 2>&1
        ;;

    linux)
        mem=$(free  | awk '/Mem:/ {print $4}')
        swap=$(free | awk '/Swap:/ {print $3}')

        if test "$mem" -lt "$swap"; then
            logmsg "not enough RAM to recover swap, nothing done"
        else
            ( swapoff -a && swapon -a ) >> $tmp 2>&1
        fi
        ;;
esac

# Cleanup.
test -s "$tmp" && logfile $tmp
rm $tmp
exit 0


Reply to: