Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Resizing /dev/shm

Updated on 2024-01-16 GMT+08:00

Scenario

/dev/shm is a temporary file system (tmpfs), which is a memory-based file system implemented in Linux or Unix and has high read/write efficiency.

If you use /dev/shm for data interaction between processes or for temporary data storage, the default size of /dev/shm (64 MB) in CCI cannot meet your requirements. CCI allows you to modify the size.

This practice shows how to resize /dev/shm by setting memory-backed emptyDir or running securityContext and mount commands.

Constraints

  • /dev/shm uses a memory-based tmpfs to temporarily store data. Data is not retained after the container is restarted.
  • You can use either of the following methods to modify the size of /dev/shm. However, do not use both methods in one pod.
  • The emptyDir uses the memory requested by the pod and does not occupy extra resources.
  • Writing data to /dev/shm is to request memory. In this scenario, you need to evaluate the memory usage of processes. When the sum of the memory requested by processes in the container plus the data volume in the emptyDir exceeds the memory limit of the container, memory overflow occurs.
  • When resizing /dev/shm, set the size to 50% of the pod's memory request.

Resizing /dev/shm Using Memory-backed emptyDir

emptyDir is applicable to temporary data storage, disaster recovery, and runtime data sharing. It will be deleted upon deletion or transfer of workload pods.

CCI supports the mounting of memory-backed emptyDir. You can specify the memory size allocated to the emptyDir and mount it to the /dev/shm directory in the container to resize /dev/shm.

apiVersion: v1
kind: Pod
metadata:  
 name: pod-emptydir-name
spec:  
 containers:   
  - image: 'library/ubuntu:latest'     
    volumeMounts:      
     - name: volume-emptydir1    
       mountPath: /dev/shm   
    name: container-0   
    resources:      
     limits:        
      cpu: '4'      
      memory: 8Gi  
     requests:   
      cpu: '4'    
      memory: 8Gi 
 volumes:   
  - emptyDir:     
     medium: Memory   
     sizeLimit: 4Gi  
    name: volume-emptydir1

After the pod is started, run the df -h command to go to the /dev/shm directory. If the following information is displayed, the size is successfully modified.

Figure 1 /dev/shm directory details

Resizing /dev/shm by Running securityContext and mount Commands

  • Grant the SYS_ADMIN permission to the container.

Linux provides the SYS_ADMIN permission. To apply this permission to the container, Kubernetes needs to add this information to pods by adding the description of the securityContext field to the pod's description file. For example:

 "securityContext": { 
                    "capabilities": {
                         "add": [
                             "SYS_ADMIN"
                                ]
                                     } 
                    }

Another description field CapAdd also needs to be added to the container description.

  "CapAdd": [
                 "SYS_ADMIN"
            ],

In this case, a parameter is added when the container is automatically started by kubelet.

docker run --cap-add=SYS_ADMIN
  • Insert the mount command in the startup command to resize /dev/shm.
apiVersion: v1
kind: Pod
metadata:
  name: pod-emptydir-name
spec:
  containers:
    - command:
        - /bin/sh
        - '-c'
        - mount -o size=4096M -o remount /dev/shm;bash
      securityContext:
        capabilities:
          add: ["SYS_ADMIN"]
      image: 'library/ubuntu:latest'
      name: container-0
      resources:
        limits:
          cpu: '4'
          memory: 8Gi
        requests:
          cpu: '4'
          memory: 8Gi

After the pod is started, run the df -h command to go to the /dev/shm directory. If the following information is displayed, the size is successfully modified.

Figure 2 /dev/shm directory details

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback