You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R内存占用异常排查:bash脚本运行时的内存分配错误

R批处理模式内存分配错误排查问题

问题概述

此前正常运行的R批处理脚本近期突发内存分配错误,即便分配了远超数据集需求的内存仍无法执行。为排除数据相关问题,编写了仅加载依赖包并执行简单运算的测试脚本,仍出现异常:

  • 在3台16GB节点运行测试脚本,耗时约15分钟后报错:Error: cannot allocate vector of size 4.7 Gb,系统诊断显示作业已使用55.456GB内存
  • 使用R CMD BATCH --vanilla或R CMD BATCH --save --no-restore可正常运行脚本,但仅用R CMD BATCH时会报错,错误信息有时为system call failed: Cannot allocate memory
  • 不同版本的R均存在该问题,但在交互式qrsh会话中运行R一切正常

测试用R脚本

# Turn scientific notation off
options(scipen=999)

# Memory
gc() 

# Install and load in a few packages
library(pryr)
library(plyr)
library(dplyr)
library(lubridate)
library(data.table)

# Memory - check what is being used
mem_used()

# Perform basic operations
2+2
log(10)

# Memory - check again after operations
mem_used()

批处理Bash脚本

#!/bin/bash --login

#$ -cwd  

#$ -l mem256 # Specify 16GB nodes

#$ -pe smp.pe 3 

module load apps/gcc/R/4.1.2

R CMD BATCH Test_NO_DATA.R Test_NO_DATA.R.o$JOB_ID

排查需求

希望找到导致R无法以干净内存状态启动的根本原因,虽然--vanilla参数能临时解决问题,但需要消除潜在隐患。

内容的提问来源于stack exchange,提问作者hhattiecc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 05:20:42