SlideShare a Scribd company logo
2
Most read
3
Most read
7
Most read
Cgroups in Android
Prasad T.V.R
Cgroups In Android
Android uses mainly to achieve the following
➢ Monitor System memory
The Low Memory Killer Daemon (lmkd) uses cgroups to monitor the system memory.
➢ Process Grouping For Effective CPU Sharing
To group processes into various groups so that the UI or the foreground tasks get the priority.
Memory cgroups
Create cgroup mount point for memory
➢ mount tmpfs none /sys/fs/cgroup mode=0750,uid=0,gid=1000
➢ mkdir /sys/fs/cgroup/memory 0750 root system
➢ mount cgroup none /sys/fs/cgroup/memory memory
➢ chown root system /sys/fs/cgroup/memory/tasks
➢ chmod 0660 /sys/fs/cgroup/memory/tasks
➢ mkdir /sys/fs/cgroup/memory/sw 0750 root system
➢ chown root system /sys/fs/cgroup/memory/sw/tasks
➢ chmod 0660 /sys/fs/cgroup/memory/sw/tasks
➢ mkdir /dev/memcg 0700 root system
➢ mount cgroup none /dev/memcg memory
Low Memory Killer
init_mp function in System/core/lmkd/lmkd.c
Use the memory control group to receive memory pressure events.
evfd = eventfd(0, EFD_NONBLOCK);
mpfd = open(MEMCG_SYSFS_PATH "memory.pressure_level", O_RDONLY);
evctlfd = open(MEMCG_SYSFS_PATH "cgroup.event_control", O_WRONLY);
Monitor for the medium presuure level and let the eventfd be notifed when the pressure level
reaches the medium level.
ret = snprintf(buf, sizeof(buf), "%d %d %s", evfd, mpfd,“medium“);
ret = write(evctlfd, buf, strlen(buf) + 1);
mp_event function in system/core/lmkd/lmkd.c handles the memory pressure event.
This function identifies a process to kill and kills it.
Cgroups and init.rc
Create cgroup mount points for process groups
➢ mkdir /dev/cpuctl
➢ mount cgroup none /dev/cpuctl cpu
➢ write /dev/cpuctl/cpu.shares 1024
Real time tasks in the cpuctl group run for 0.8 sec in a period of 1 second
➢ write /dev/cpuctl/cpu.rt_runtime_us 800000
➢ write /dev/cpuctl/cpu.rt_period_us 1000000
Create the cgroup for background tasks
➢ mkdir /dev/cpuctl/bg_non_interactive
Tasks in the bg_non_interactive group get nearly 5% of the CPU (52/1024)
➢ write /dev/cpuctl/bg_non_interactive/cpu.shares 52
Real time tasks in the bg_non_interactive group run for 0.7 sec in a period of 1 second.
➢ write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 700000
➢ write /dev/cpuctl/bg_non_interactive/cpu.rt_period_us 1000000
Cgroups And Android Scheduling
Android groups processes into the following groups based on their scheduling policy set:
➢ SP_BACKGROUND
➢ SP_FOREGROUND
➢ SP_SYSTEM
➢ SP_AUDIO_APP
➢ SP_AUDIO_SYS
References
➢ System/core/libcutils/sched_policy.c
➢ base/core/jni/android_util_Process.cpp
➢ ActivityManagerService.java
➢ Process.java
➢ ActivityThread.java
➢ android_os_Process_setProcessGroup function
➢ android_os_Process_setSwappiness
➢ setSchedulingGroup
➢ https://github.com/dweinstein/android_notes/wiki/AndroidScheduling

More Related Content

PDF
Scheduling in Android
PDF
Q4.11: Introduction to eMMC
PDF
BKK16-208 EAS
PDF
Linux System Monitoring basic commands
PPT
Process and Threads in Linux - PPT
PDF
The Linux Kernel Scheduler (For Beginners) - SFO17-421
PDF
SFO15-302: Energy Aware Scheduling: Progress Update
PPTX
Ext4 write barrier
Scheduling in Android
Q4.11: Introduction to eMMC
BKK16-208 EAS
Linux System Monitoring basic commands
Process and Threads in Linux - PPT
The Linux Kernel Scheduler (For Beginners) - SFO17-421
SFO15-302: Energy Aware Scheduling: Progress Update
Ext4 write barrier

What's hot (20)

PDF
PDF
PDF
Linux dma engine
PDF
Kdump and the kernel crash dump analysis
PDF
Introduction to char device driver
PDF
Linux-Internals-and-Networking
PPTX
Linux Network Stack
PPTX
The TCP/IP Stack in the Linux Kernel
PPTX
U-Boot presentation 2013
PDF
Memory Mapping Implementation (mmap) in Linux Kernel
PDF
CNIT 126: 10: Kernel Debugging with WinDbg
PDF
Android Boot Time Optimization
PDF
Linux Profiling at Netflix
PPT
Basic Linux Internals
PDF
Java Performance Analysis on Linux with Flame Graphs
PDF
BPF: Tracing and more
PDF
Arm device tree and linux device drivers
PDF
Automating linux network performance testing
PDF
Linux Performance Profiling and Monitoring
PPT
U Boot or Universal Bootloader
Linux dma engine
Kdump and the kernel crash dump analysis
Introduction to char device driver
Linux-Internals-and-Networking
Linux Network Stack
The TCP/IP Stack in the Linux Kernel
U-Boot presentation 2013
Memory Mapping Implementation (mmap) in Linux Kernel
CNIT 126: 10: Kernel Debugging with WinDbg
Android Boot Time Optimization
Linux Profiling at Netflix
Basic Linux Internals
Java Performance Analysis on Linux with Flame Graphs
BPF: Tracing and more
Arm device tree and linux device drivers
Automating linux network performance testing
Linux Performance Profiling and Monitoring
U Boot or Universal Bootloader
Ad

Similar to Cgroups in android (20)

PDF
Kernel Recipes 2015 - Kernel dump analysis
PDF
Control your service resources with systemd
PPT
Qemu - Raspberry | while42 Singapore #2
PDF
SiteGround Tech TeamBuilding
PDF
Docker Security in Production Overview
PDF
MINCS - containers in the shell script (Eng. ver.)
PPT
Linux Crash Dump Capture and Analysis
PDF
Dev ops
PDF
HKG15-409: ARM Hibernation enablement on SoCs - a case study
PDF
PDF
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdf
PDF
Advanced Namespaces and cgroups
PDF
OS scheduling and The anatomy of a context switch
PDF
HKG18-TR14 - Postmortem Debugging with Coresight
PDF
YOW2020 Linux Systems Performance
PDF
Provision Intel® Optane™ DC Persistent Memory in Linux*
PDF
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
PPT
Vpu technology &gpgpu computing
PDF
005 skyeye
PPT
Vpu technology &gpgpu computing
Kernel Recipes 2015 - Kernel dump analysis
Control your service resources with systemd
Qemu - Raspberry | while42 Singapore #2
SiteGround Tech TeamBuilding
Docker Security in Production Overview
MINCS - containers in the shell script (Eng. ver.)
Linux Crash Dump Capture and Analysis
Dev ops
HKG15-409: ARM Hibernation enablement on SoCs - a case study
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdf
Advanced Namespaces and cgroups
OS scheduling and The anatomy of a context switch
HKG18-TR14 - Postmortem Debugging with Coresight
YOW2020 Linux Systems Performance
Provision Intel® Optane™ DC Persistent Memory in Linux*
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Vpu technology &gpgpu computing
005 skyeye
Vpu technology &gpgpu computing
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars

Cgroups in android

  • 2. Cgroups In Android Android uses mainly to achieve the following ➢ Monitor System memory The Low Memory Killer Daemon (lmkd) uses cgroups to monitor the system memory. ➢ Process Grouping For Effective CPU Sharing To group processes into various groups so that the UI or the foreground tasks get the priority.
  • 3. Memory cgroups Create cgroup mount point for memory ➢ mount tmpfs none /sys/fs/cgroup mode=0750,uid=0,gid=1000 ➢ mkdir /sys/fs/cgroup/memory 0750 root system ➢ mount cgroup none /sys/fs/cgroup/memory memory ➢ chown root system /sys/fs/cgroup/memory/tasks ➢ chmod 0660 /sys/fs/cgroup/memory/tasks ➢ mkdir /sys/fs/cgroup/memory/sw 0750 root system ➢ chown root system /sys/fs/cgroup/memory/sw/tasks ➢ chmod 0660 /sys/fs/cgroup/memory/sw/tasks ➢ mkdir /dev/memcg 0700 root system ➢ mount cgroup none /dev/memcg memory
  • 4. Low Memory Killer init_mp function in System/core/lmkd/lmkd.c Use the memory control group to receive memory pressure events. evfd = eventfd(0, EFD_NONBLOCK); mpfd = open(MEMCG_SYSFS_PATH "memory.pressure_level", O_RDONLY); evctlfd = open(MEMCG_SYSFS_PATH "cgroup.event_control", O_WRONLY); Monitor for the medium presuure level and let the eventfd be notifed when the pressure level reaches the medium level. ret = snprintf(buf, sizeof(buf), "%d %d %s", evfd, mpfd,“medium“); ret = write(evctlfd, buf, strlen(buf) + 1); mp_event function in system/core/lmkd/lmkd.c handles the memory pressure event. This function identifies a process to kill and kills it.
  • 5. Cgroups and init.rc Create cgroup mount points for process groups ➢ mkdir /dev/cpuctl ➢ mount cgroup none /dev/cpuctl cpu ➢ write /dev/cpuctl/cpu.shares 1024 Real time tasks in the cpuctl group run for 0.8 sec in a period of 1 second ➢ write /dev/cpuctl/cpu.rt_runtime_us 800000 ➢ write /dev/cpuctl/cpu.rt_period_us 1000000 Create the cgroup for background tasks ➢ mkdir /dev/cpuctl/bg_non_interactive Tasks in the bg_non_interactive group get nearly 5% of the CPU (52/1024) ➢ write /dev/cpuctl/bg_non_interactive/cpu.shares 52 Real time tasks in the bg_non_interactive group run for 0.7 sec in a period of 1 second. ➢ write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 700000 ➢ write /dev/cpuctl/bg_non_interactive/cpu.rt_period_us 1000000
  • 6. Cgroups And Android Scheduling Android groups processes into the following groups based on their scheduling policy set: ➢ SP_BACKGROUND ➢ SP_FOREGROUND ➢ SP_SYSTEM ➢ SP_AUDIO_APP ➢ SP_AUDIO_SYS
  • 7. References ➢ System/core/libcutils/sched_policy.c ➢ base/core/jni/android_util_Process.cpp ➢ ActivityManagerService.java ➢ Process.java ➢ ActivityThread.java ➢ android_os_Process_setProcessGroup function ➢ android_os_Process_setSwappiness ➢ setSchedulingGroup ➢ https://github.com/dweinstein/android_notes/wiki/AndroidScheduling