OpenSUSE Proposal: RAM memory limiter management for Badoo file indexing service

Baloo file indexing service can flood system resources with large file operations that requires processing large amount of indexing meta data to an extend that the system stops responding. It can cause a memory flooding leak. Although there is an option to turn baloo fis off using the terminal, I would like to propose a middle ground solution.

**Include a ram memory limiter to the baloo fis graphically in settings (KDE) or burned into the inmutable system. Something like a selector of different behaviours that can be operated via terminal. **

In the meantime I have written a manual with the help of AI to run a temporary script prior to operating large file-operations: transferring large amounts of files that requires processing and indexing large amounts of meta data.

So far the scripts run. But I am still testing its behaviour.

Here is the final manual with all updates and improvements:


Baloo Memory Limiter Script (Universal)

:memo: Purpose

Prevent Baloo from consuming excessive RAM during large file operations (e.g. moving 13k emails). Uses memory.high to throttle Baloo at 16 GB instead of killing it.
:white_check_mark: Works on cgroup v1 and v2 (openSUSE MicroOS).

:warning: Important: If the script fails, hidden Windows line endings may be present. Fix with the tr command below.


:white_check_mark: Fix Hidden Line Endings (Critical Step)

tr -d '\r' < ~/baloo-limit.sh > ~/temp.sh && mv ~/temp.sh ~/baloo-limit.sh

:white_check_mark: Limit Script (baloo-limit.sh)

#!/bin/bash
# Baloo RAM Limiter - Universal (cgroup v1 & v2)
# Sets memory.high to 16384M (16 GB)
# Baloo is throttled, not killed

MEMLIMIT=16384M

# Detect cgroup version: cgroup2fs = v2, tmpfs = v1
if [ "$(stat -fc %T /sys/fs/cgroup/ 2>/dev/null)" = "cgroup2fs" ]; then
  # cgroup v2: Use unified hierarchy
  CGROUP=/sys/fs/cgroup/baloo
  [ ! -d "$CGROUP" ] && sudo mkdir "$CGROUP"
  # Enable memory controller
  echo "+memory" | sudo tee /sys/fs/cgroup/cgroup.subtree_control 2>/dev/null || true
  # Set soft memory limit
  echo $MEMLIMIT | sudo tee "$CGROUP/memory.high" > /dev/null
  # Add Baloo processes
  for pid in $(pgrep baloo); do
    echo $pid | sudo tee "$CGROUP/cgroup.procs" > /dev/null
  done
else
  # cgroup v1: Use legacy memory cgroup
  CGROUP=/sys/fs/cgroup/memory/baloo
  [ ! -d "$CGROUP" ] && sudo mkdir -p "$CGROUP"
  # Set soft memory limit
  echo $MEMLIMIT | sudo tee "$CGROUP/memory.high" > /dev/null
  # Add Baloo processes
  for pid in $(pgrep baloo); do
    echo $pid | sudo tee "$CGROUP/cgroup.procs" > /dev/null
  done
fi

echo "Baloo limited to $MEMLIMIT RAM"

:stop_sign: Reverse Script (baloo-reverse-limit.sh)

#!/bin/bash
# Baloo Reverse Limiter - Universal (cgroup v1 & v2)
# Removes the memory limit safely

# Detect cgroup version
if [ "$(stat -fc %T /sys/fs/cgroup/ 2>/dev/null)" = "cgroup2fs" ]; then
  # cgroup v2
  CGROUP=/sys/fs/cgroup/baloo
  [ -d "$CGROUP" ] && sudo rmdir "$CGROUP"
else
  # cgroup v1
  CGROUP=/sys/fs/cgroup/memory/baloo
  [ -d "$CGROUP" ] && sudo rmdir "$CGROUP"
fi

echo "Baloo memory limit removed (if active)"

:gear: Usage

  1. Save both scripts in home folder.
  2. Fix line endings:
    tr -d '\r' < ~/baloo-limit.sh > ~/temp.sh && mv ~/temp.sh ~/baloo-limit.sh
    
  3. Make executable:
    chmod +x ~/baloo-limit.sh ~/baloo-reverse-limit.sh
    
  4. Apply limit:
    bash ~/baloo-limit.sh
    
  5. Remove limit:
    bash ~/baloo-reverse-limit.sh
    

:mag: Monitor Status

  • Check cgroup version:
    stat -fc %T /sys/fs/cgroup/
    
  • View limit:
    cat /sys/fs/cgroup/*/baloo/memory.high
    
  • Current usage:
    cat /sys/fs/cgroup/*/baloo/memory.current
    
  • Baloo status:
    balooctl status
    

:pushpin: Notes

  • Works on openSUSE MicroOS Kalpa.
  • Use bash script.sh if ./script.sh fails.
  • The tr command fixes line endings from GUI editors.
  • The memory amount is exemplary for my situation. I use a laptop with 8gb + 16gb ram memory. I want the script to keep 8gb for normal operation while letting the system run baloo. The memory limit can be set to you own desired situation.
  • Safe: Baloo continues indexing, just slower under memory pressure.

To avoid multiple root password prompts, run the script with sudo once:

sudo bash ~/baloo-limit.sh

This gives the entire script root access, so individual sudo commands inside it won’t prompt again.

Updated Notes:

  • Use sudo bash ~/baloo-limit.sh to avoid repeated password prompts.
  • The script runs fully as root, eliminating interactive sudo calls.

Also :

I wrote the script in KATE, so it has hidden Windows carriage returns and line endings in the script. Even when KATE is set to “unix”.
Don’t forget to fix the carriage return and line ending in the baloo-reverse-limit.sh as well…

In the manual, the command to fix this is already included for baloo-limit.sh:

tr -d '\r' < ~/baloo-limit.sh > ~/temp.sh && mv ~/temp.sh ~/baloo-limit.sh

You should add the same fix for baloo-reverse-limit.sh:

tr -d '\r' < ~/baloo-reverse-limit.sh > ~/temp.sh && mv ~/temp.sh ~/baloo-reverse-limit.sh

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.