Skip to content

fix(docker): account for container memory limits in frontend-mem-nag.sh - #46373

Merged
hainenber merged 2 commits into
apache:masterfrom
Raman-Katiyar:fix/46368-frontend-mem-nag-cgroup-limit
Nov 22, 2026
Merged

hainenber merged 2 commits into
apache:masterfrom
Raman-Katiyar:fix/46368-frontend-mem-nag-cgroup-limit

Conversation

@Raman-Katiyar

Copy link
Copy Markdown
Contributor

SUMMARY

docker/frontend-mem-nag.sh (run at image build time, Dockerfile:77) reads only /proc/meminfo, which reports host memory inside a container. When the host has more than 3 GB available but the container is limited below 3 GB, the script reports sufficient memory and omits the warning, leaving developers unaware the frontend build is running with less memory than the stated minimum.

This change makes the script account for the container memory limit: it reads the cgroup limit and usage (cgroups v2 memory.max/memory.current, cgroups v1 memory.limit_in_bytes/memory.usage_in_bytes) and warns on the lower of the host's available memory and the container's remaining memory. A "max" (v2) or 2^63 (v1) limit is treated as unlimited, and when no finite limit applies the script falls back to host memory, so behaviour outside containers is unchanged.

Also included:

  • MEMINFO_PATH / CGROUP_PATH overrides (defaulting to the live paths) so the script can be tested without a container.
  • A regression test, docker/frontend-mem-nag.test.sh, covering v1/v2 limits, unlimited limits, no cgroup files, and the MemFree fallback.
  • A one-word fix in the same warning text: the message referenced an undefined ${MEM_TYPE} variable (it rendered as nothing).

Fixes #46368

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable (shell script, no UI). Before/after output, reproduced in a mount namespace with fake MemAvailable 8 GiB and a cgroup v2 limit of 1 GiB (0.2 GiB used):

Before:

Memory available: 7.62939  GB

After:

===============================================
========  Memory Insufficient Warning =========
===============================================

It looks like you only have 0.804688 GB of
memory. Please increase your Docker
resources to at least 3GB

Note: During builds, available memory may be
temporarily low due to caching and compilation.

===============================================
========  Memory Insufficient Warning =========
===============================================

TESTING INSTRUCTIONS

  1. bash docker/frontend-mem-nag.test.sh — all 7 regression cases pass.
  2. To reproduce the reported scenario without Docker: in a mount namespace, bind-mount a meminfo with MemAvailable: 8000000 kB over /proc/meminfo and a cgroup dir with memory.max = 1073741824 and memory.current = 209715200 over /sys/fs/cgroup, then run docker/frontend-mem-nag.sh. Before this change it prints Memory available: 7.62939 GB; after, it shows the warning with 0.804688 GB.
  3. On a host without a container limit, the script behaves as before (warns on the host's available memory when below 3 GB).
  4. pre-commit run on the changed files passes; bash -n is clean on both files.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

cc @shubhamjrd4559-sudo

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: ab4b4685c7d6

Comment thread docker/frontend-mem-nag.sh Outdated
usage_bytes="${current_value}"
fi
fi
elif [[ -f "${CGROUP_PATH}/memory.limit_in_bytes" ]]; then

@hainenber hainenber Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to continue supporting cgroup v1, you can simplify the implementation code and below test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion — done. I removed the cgroup v1 branch from container_mem_avail_kb so it only reads memory.max / memory.current, and simplified the test: the two v1 cases are gone, replaced by one case proving a v1-only container now falls back to the host value. The test suite passes (6/6), including the new case failing on the previous version.

Per review feedback on apache#46373, only cgroups v2 is supported now: the
memory.limit_in_bytes / memory.usage_in_bytes branch is removed and
container_mem_avail_kb reads memory.max / memory.current only. The
regression test drops the two v1 cases and gains one proving a v1-only
container now falls back to the host value.

@hainenber hainenber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Thank you for your contribution 👍

@hainenber
hainenber merged commit d5966f4 into apache:master Nov 22, 2026
65 checks passed
jprinet added a commit to jprinet/superset that referenced this pull request Nov 23, 2026
* origin/master: (393 commits)
  fix(a11y): name the semantic view description input (apache#46458)
  docs(semantic): explain datasource list modification eligibility (apache#46462)
  docs(semantic-layer): document NULL-preserving exclusion filters (apache#46447)
  fix(uploads): skip folder and system entries in columnar ZIP uploads (apache#45617)
  fix(i18n-es): promote 47 of the zero-context backfill entries (apache#45847)
  fix(mcp): return structured ChartError on SQLAlchemyError in get_chart_sql (apache#44351)
  fix(datasets): follow semantic view modification permissions (apache#46448)
  fix(docker): account for container memory limits in frontend-mem-nag.sh (apache#46373)
  fix(reports): carry the report's native filters in the email and Slack link (apache#46062)
  fix(explore): apply the dataset timezone to grained temporal filter values (apache#46175)
  fix(i18n): enforce the do-not-translate registry across the catalogs (apache#45974)
  chore(logging): log unparseable virtual dataset SQL at debug in the RLS lookup (apache#46139)
  fix(i18n): split parameter-suggestion plural into two messages (apache#46049)
  test(partition-mapping): cover Hive/Impala mirrored SQL, cache outage and migration (apache#46319)
  perf(dashboard): look up the dashboard once per filter_state read (apache#46314)
  fix(i18n): load the dayjs locale for every language with a catalog (apache#45982)
  test(semantic-layer): make date export parametrization deterministic (apache#46449)
  fix(oauth2): idempotent OAuth2 completion and resilient listener (apache#40292)
  fix(explore): prevent full table scan when SQL expression is used as x-axis (apache#41339)
  feat(mcp): radar chart type plugin (apache#43571)
  ...

# Conflicts:
#	.github/workflows/docker.yml
#	.github/workflows/superset-frontend.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

frontend-mem-nag.sh does not account for Docker container memory limits

2 participants