From 42b30da814c1aa8e30963c55f2aa16983ec74aef Mon Sep 17 00:00:00 2001 From: Alex Sarkesian Date: Fri, 15 May 2026 18:28:25 -0400 Subject: [PATCH] SERVER-126898: Make clangd configuration user-controllable (#53884) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> GitOrigin-RevId: ddc00ad74e0ed090a7cce95812015a570edf0547 --- .../linux-virtual-workstation.code-workspace | 3 ++- buildscripts/clangd_vscode.sh | 26 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.vscode_defaults/linux-virtual-workstation.code-workspace b/.vscode_defaults/linux-virtual-workstation.code-workspace index 250f4080642..be54d79a1be 100644 --- a/.vscode_defaults/linux-virtual-workstation.code-workspace +++ b/.vscode_defaults/linux-virtual-workstation.code-workspace @@ -99,8 +99,9 @@ } }, ], + // Set CLANGD_NO_LIMITS=1 in .vscode/clangd.env to disable systemd resource limits on clangd. + // Set CLANGD_JOBS= in .vscode/clangd.env to control clangd parallelism (default: 4). "clangd.arguments": [ - "-j=4", "--background-index-priority=low", "--pch-storage=disk", "--malloc-trim", diff --git a/buildscripts/clangd_vscode.sh b/buildscripts/clangd_vscode.sh index ad1fdf1a41d..af2744e6395 100755 --- a/buildscripts/clangd_vscode.sh +++ b/buildscripts/clangd_vscode.sh @@ -4,6 +4,12 @@ set -euo pipefail # Collect all passed arguments ARGS=("$@") +# Source user-defined clangd environment variables +CLANGD_ENV="$PWD/.vscode/clangd.env" +if [[ -f $CLANGD_ENV ]]; then + source "$CLANGD_ENV" +fi + # Ordered list of possible clangd locations (each candidate must be a single path) CANDIDATES=( "$(command -v custom-clangd || true)" @@ -23,6 +29,7 @@ for CANDIDATE in "${CANDIDATES[@]}"; do done SKIP_SWAP="${SKIP_SWAP:-0}" +SKIP_LIMITS="${CLANGD_NO_LIMITS:-0}" # Fail if no clangd was found if [[ -z "$CLANGD" ]]; then @@ -42,6 +49,7 @@ fi FINAL_ARGS=( "${ARGS[@]}" + "-j=${CLANGD_JOBS:-4}" "--query-driver=./**/*{clang,gcc,g++}*" # allow any clang or gcc binary in the repo "--header-insertion=never" ) @@ -136,25 +144,27 @@ can_use_systemd_user() { timeout 1s systemd-run --user --quiet --scope true >/dev/null 2>&1 } -if can_use_systemd_user; then +if [[ "$SKIP_LIMITS" != "1" ]] && can_use_systemd_user; then if systemd-run --user --quiet --collect --pipe \ --unit="$UNIT" \ - -p MemoryHigh=4G \ - -p MemoryMax=8G \ - -p MemorySwapMax=16G \ - -p IOWeight=10 \ - -p IOSchedulingClass=idle \ - -p IOSchedulingPriority=7 \ + -p "MemoryHigh=${CLANGD_MEMORY_HIGH:-4G}" \ + -p "MemoryMax=${CLANGD_MEMORY_MAX:-8G}" \ + -p "MemorySwapMax=${CLANGD_MEMORY_SWAP_MAX:-16G}" \ + -p "IOWeight=${CLANGD_IO_WEIGHT:-10}" \ + -p "IOSchedulingClass=${CLANGD_IO_SCHEDULING_CLASS:-idle}" \ + -p "IOSchedulingPriority=${CLANGD_IO_SCHEDULING_PRIORITY:-7}" \ -- "$CLANGD" "${FINAL_ARGS[@]}"; then exit 0 else echo "[WARN] systemd-run --user failed; falling back to direct clangd." >&2 fi +elif [[ "$SKIP_LIMITS" == "1" ]]; then + echo "[INFO] Resource limits disabled (CLANGD_NO_LIMITS=1). Running clangd without systemd limits." >&2 else echo "[WARN] systemd-run not available (common in containers). Running clangd without systemd limits." >&2 fi -# Fallback: run clangd directly (used when systemd-run is unavailable or fails at runtime) +# Fallback: run clangd directly (used when systemd-run is unavailable, limits are disabled, or systemd-run fails) if command -v ionice >/dev/null 2>&1; then exec ionice -c3 nice -n 19 "$CLANGD" "${FINAL_ARGS[@]}" else