-
Notifications
You must be signed in to change notification settings - Fork 271
Add shm size check #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add shm size check #978
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||||||||||||||||||||||
import uuid | ||||||||||||||||||||||||||||||||||||||||||
import subprocess | ||||||||||||||||||||||||||||||||||||||||||
import signal | ||||||||||||||||||||||||||||||||||||||||||
import shutil | ||||||||||||||||||||||||||||||||||||||||||
from lightllm.utils.net_utils import alloc_can_use_network_port, PortLocker | ||||||||||||||||||||||||||||||||||||||||||
from lightllm.utils.start_utils import process_manager, kill_recursive | ||||||||||||||||||||||||||||||||||||||||||
from .metrics.manager import start_metric_manager | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -19,6 +20,37 @@ | |||||||||||||||||||||||||||||||||||||||||
logger = init_logger(__name__) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
def get_shm_size_gb(): | ||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||
获取 /dev/shm 的总大小(以GB为单位)。 | ||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||
shm_path = "/dev/shm" | ||||||||||||||||||||||||||||||||||||||||||
if not os.path.exists(shm_path): | ||||||||||||||||||||||||||||||||||||||||||
logger.error(f"{shm_path} not exist, this may indicate a system or Docker configuration anomaly.") | ||||||||||||||||||||||||||||||||||||||||||
return 0 | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# shutil.disk_usage 返回 (total, used, free) | ||||||||||||||||||||||||||||||||||||||||||
total_bytes = shutil.disk_usage(shm_path).total | ||||||||||||||||||||||||||||||||||||||||||
total_gb = total_bytes / (1024 ** 3) | ||||||||||||||||||||||||||||||||||||||||||
return total_gb | ||||||||||||||||||||||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||
logger.error(f"Error getting /dev/shm size: {e}") | ||||||||||||||||||||||||||||||||||||||||||
return 0 | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
def check_shm_size(): | ||||||||||||||||||||||||||||||||||||||||||
RED = "\033[91m" | ||||||||||||||||||||||||||||||||||||||||||
GREEN = "\033[92m" | ||||||||||||||||||||||||||||||||||||||||||
ENDC = "\033[0m" | ||||||||||||||||||||||||||||||||||||||||||
shm_size = get_shm_size_gb() | ||||||||||||||||||||||||||||||||||||||||||
required_size = 128 # 128G | ||||||||||||||||||||||||||||||||||||||||||
if shm_size < required_size: | ||||||||||||||||||||||||||||||||||||||||||
logger.warning(f"{RED}Available shm size is less than 128G: {shm_size:.2f}G{ENDC}") | ||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||
logger.info(f"{GREEN}/dev/shm available space is sufficient ({shm_size:.2f} GB >= {required_size} GB).{ENDC}") | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+47
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better maintainability, define
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
def setup_signal_handlers(http_server_process, process_manager): | ||||||||||||||||||||||||||||||||||||||||||
def signal_handler(sig, frame): | ||||||||||||||||||||||||||||||||||||||||||
if sig == signal.SIGINT: | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -62,6 +94,19 @@ def signal_handler(sig, frame): | |||||||||||||||||||||||||||||||||||||||||
def normal_or_p_d_start(args): | ||||||||||||||||||||||||||||||||||||||||||
set_unique_server_name(args) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
check_shm_size() | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if not args.disable_shm_warning: | ||||||||||||||||||||||||||||||||||||||||||
import threading | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
def periodic_shm_warning(): | ||||||||||||||||||||||||||||||||||||||||||
while True: | ||||||||||||||||||||||||||||||||||||||||||
check_shm_size() | ||||||||||||||||||||||||||||||||||||||||||
time.sleep(120) # 每 120 秒打印一次警告日志 | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
shm_warning_thread = threading.Thread(target=periodic_shm_warning, daemon=True) | ||||||||||||||||||||||||||||||||||||||||||
shm_warning_thread.start() | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+100
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For style and maintainability:
Since I can't suggest changes outside the diff, I'll define the constant locally, but consider moving both the import and the constant to the module level.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if args.enable_mps: | ||||||||||||||||||||||||||||||||||||||||||
from lightllm.utils.device_utils import enable_mps | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function calculates the total SHM size but the PR description refers to "available" space. This can be misleading. To check for available space, use
shutil.disk_usage(shm_path).free
and rename the function toget_shm_free_size_gb
for clarity.