This is the third article in the “Systrace Thread CPU State Analysis Tips” series. It focuses on the Sleep and Uninterruptible Sleep states in Systrace—their causes, troubleshooting, and optimization. These states often represent normal waiting; investigate their conditions and dependencies when they delay a critical path.
The goal of this series is to use Systrace to view the Android system from a different perspective and to learn the Framework through visualization. While reading Framework source code can be difficult to remember, seeing the flow in Systrace can lead to deeper understanding. You can find the complete Systrace Basics and Action Series here.
Technical review — 2026-10-14: This 2022 article retains historical screenshots with corrected signal, wakeup-attribution, and I/O-flag interpretation. Code examples are explicitly Linux v5.10; Android-specific events have separate sources. These references do not establish the screenshot device versions. Use Perfetto for new captures and treat missing fields as unknown.
Table of Contents
- What are Sleep States in Linux?
- Analyzing the Sleep State
- Analyzing the Uninterruptible Sleep State
- Appendix
- About Me && Blog
- Systrace Thread CPU State Analysis Tips - Runnable
- Systrace Thread CPU State Analysis Tips - Running
- Systrace Thread CPU State Analysis Tips - Sleep and Uninterruptible Sleep
What are Sleep States in Linux?
TASK_INTERRUPTIBLE vs. TASK_UNINTERRUPTIBLE
A thread which is neither Running nor Runnable is not necessarily sleeping: it may be stopped, traced, or exiting. The following are three common waiting semantics, not an exhaustive list of Linux states:
TASK_INTERRUPTIBLE: the wait can be woken by its condition or an applicable pending signal.TASK_UNINTERRUPTIBLE: ordinary signals or SIGKILL alone do not end the wait; a signal may remain pending until the wait returns.TASK_KILLABLE: combinesTASK_WAKEKILL | TASK_UNINTERRUPTIBLEand responds to signals the kernel classifies as fatal, notably SIGKILL.TASK_WAKEKILLis a flag, not a separate sleeping mechanism.

Figure 1 is a simplified model. Historical viewers commonly label interruptible waits Sleep and distinguish Uninterruptible Sleep, but colors vary by viewer and theme. A sleeping thread is not executing on a CPU; after wakeup it must be scheduled again.
“Uninterruptible” does not mean permanently unwakeable or hardware interrupts disabled. Completion, an explicit wakeup, or a timeout supported by the particular wait API can resume the task. For example, wait_event_timeout uses an uninterruptible wait with a timeout. See the Linux 6.12 wait APIs and Linux 5.10 state definitions.
Looper polling and userspace futex waits commonly appear as Sleep, but Java/native locks and network operations do not all imply one kernel state. Inspect the actual path and wait API. An idle main thread waiting for messages is normally healthy; replacing that wait with busy polling is not an optimization.
The Purpose of TASK_UNINTERRUPTIBLE
Interruptibility here concerns how a wait responds to signals. POSIX signals, softirqs, and hardware IRQs are different mechanisms with different execution contexts; a sleeping thread is not simultaneously executing hardware interrupt handlers.
A kernel operation may use an uninterruptible wait because it has no ordinary-signal cancellation semantics or must await an internal condition. This is distinct from disabling preemption or local CPU interrupts. TASK_UNINTERRUPTIBLE does not itself disable an interrupt controller.
I/O completion, some kernel locks, page waits, and driver synchronization can use such waits. Not every I/O operation, network access, or lock wait enters D. Inspect the target kernel’s actual wait function; Linux 5.10 is a versioned reference, while a changing “latest” page cannot establish the implementation behind an old screenshot.
Analysis Philosophy
TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE are normal. A high sleeping percentage can simply mean idle work. Investigate when waiting delays a required result or deadline. Master these two points:
- Troubleshooting Methodology
- Optimization Methodology
You must identify if a sleep is active or passive. If active, is the logic sound? If passive, what is the source? This requires deep system knowledge and experience.
Note: I’ll use “Sleep” for TASK_INTERRUPTIBLE and “UninterruptibleSleep” for TASK_UNINTERRUPTIBLE to match Systrace terminology.
It is easy to get lost when you first analyze Sleep and UninterruptibleSleep. Reading Framework and kernel code helps you make sense of the clues in a trace. The trace only covers the events that were captured, and Systrace’s wakeup_from does not by itself identify a lock owner or the complete business dependency. You need both an understanding of the system and the trace to explain the cause. Otherwise, you end up doing what I call ‘performance optimization by bluffing’: you assert a cause that nobody can check, send the testers through another round of retesting, and let the issue disappear when they cannot reproduce it.
This article covers common types and cases. Use these diagnostic methods and source code analysis to navigate unique problems.
Visualization in Trace


These are historical viewer palettes, not standardized kernel colors. Non-IO versus Block I/O classification also depends on the captured events. A missing I/O flag leaves I/O classification unknown, not automatically Non-IO. A missing blocked function leaves the wait location unknown without invalidating an I/O flag that was captured.
Analyzing the Sleep State


The crops show waiting around Choreographer#doFrame / DrawFrame and a binder transaction. They suggest hypotheses such as UI-to-render-thread synchronization or a synchronous Binder reply wait. They do not include enough stacks, transaction links, and timing context to establish the entire dependency or root cause.
Diagnostic Methods
Use wakeup from tid: *** to Find Waking Threads
As discussed in the Runnable article, waking up and actually executing are separate steps. Timers, device completion, and interrupt paths can wake tasks as well as other threads. Preemption, yielding, and newly enqueued tasks also contribute runnable work; the original two-case classification was incomplete.
wakeup from tid identifies the wakeup context recorded by scheduler events. It is not necessarily the business-level producer or the owner of a contested lock. Interrupt context, proxy wakeups, multiple waiters, and missing events can make a simple tid attribution misleading.

The red annotations are historical. In particular, “Running instead” does not prove the other task had higher priority or caused the delay; it helps identify other work running at that time. The shown wakeup from tid: 14116 is a lead to investigate.
Current Perfetto can correlate sched_switch, sched_waking, and thread-state details. Depending on the capture, tables may expose waker_utid and irq_context. Missing values do not establish that there was no waker. See scheduler events and the thread_state table.
Other Methods
- Stacks and off-CPU analysis: ordinary CPU sampling mainly observes stacks while the thread runs; it does not reconstruct a complete execution flow during sleep. With supported kernels, permissions, and versions, simpleperf’s
--trace-offcpucombines scheduling information with stacks at descheduling. It still does not record every function entry and exit. See the official simpleperf reference. - Event correlation: use timing to identify candidates, then confirm with Binder transactions, futex addresses, application identifiers, kernel stacks, or source. Simultaneous events alone do not establish causality.
Ask what condition is awaited, who advances it, when it becomes satisfied, and how long scheduling takes afterward, rather than merely matching colors on timelines.
Common Causes for Long Sleep
- Binder: a synchronous call may wait for remote queueing, execution, and a reply. Follow transaction links and distinguish service-side execution, lock waits, and CPU waits. A
onewaycall does not wait for a synchronous reply in the same way. - Java/futex locks and conditions: contention may occur in apps or services, but a futex is a mechanism and does not always mean a mutex wait. Identify the actual condition, lock, and dependency.
- Intentional waits: timers, semaphores, and message queues can provide necessary pacing. Establish whether the wait delays a required result before trying to remove it.
- Graphics fences: a fence can track GPU, display, or buffer use; waiting does not prove the GPU is continuously busy. Identify the producer, submission, and signal times, then consider shader, resolution, or texture reductions where relevant. Increasing GPU frequency is not a general app-level fix. See the AOSP synchronization framework.
Analyzing the Uninterruptible Sleep State
Diagnostic Methods
First establish a D-class wait, then look for I/O classification and a blocked function. These are optional capture details, not properties that every UninterruptibleSleep interval necessarily exposes:
- The I/O-wait flag can be 0, 1, or absent.
- Block reason depends on kernel tracepoints, capture configuration, symbols, and parser support.
IOWait vs. Non-IOWait
Here I/O wait is a kernel flag recorded for the task, not a complete test for any I/O performed by an operation, nor the CPU-usage statistic called iowait. iowait=0 means this point was not marked as I/O waiting; it does not rule out I/O elsewhere in the operation. A missing field is not zero.
A page-cache miss may cause storage access, while a cache hit may still require page-lock, writeback, or other synchronization. One syscall may include several running and waiting intervals. Non-IO candidates include kernel locks, page waits, and driver conditions; Non-IO is not synonymous with a kernel-lock wait.
Block Reason
The historical sched_blocked_reason change is c9f00aa0, authored by Riley Andrews on 2015-10-02, with a committer date of 2016-04-20 in this repository. Its title is:
1 | sched: add sched blocked tracepoint which dumps out context of sleep. |
In the inspected Android Common android12-5.10 event definition, pid comes from the task ID, caller from get_wchan(tsk), and iowait from tsk->in_iowait. This is a wait-location clue, not a full stack, lock address, or owner. Availability is kernel-dependent, and the recording must enable sched/sched_blocked_reason; see the Perfetto analysis guide.
The original line is retained as a format example:
1 | sched_blocked_reason: pid=30235 iowait=0 caller=get_user_pages_fast+0x34/0x70 |

The event’s pid is a task ID (TID); 30120 in the image is the process PID. These are not directly comparable fields. Without the selected thread’s TID and raw records, do not automatically combine the example line and screenshot as one event. Resolve get_user_pages_fast+0x34/0x70 against the actual device’s kernel build and symbols. The Linux 5.10 example below explains a mechanism; it does not establish the screenshot’s kernel version.
Here is the complete wrapper from Linux v5.10:
1 | int get_user_pages_fast(unsigned long start, int nr_pages, |
This version adds page references with FOLL_GET; that differs from the FOLL_PIN semantics of pin_user_pages*() and is not a generic long-term DMA-pinning API. See GUP and pin_user_pages.
The internal implementation attempts a fast path and falls back for remaining pages when permitted. The slow path may acquire mmap_lock or encounter faults and other page waits; the wrapper’s name alone does not identify one lock as the cause. Interrupt protection within the fast path also does not mean the D state disables interrupts.

The later Runnable selection shows wakeup from tid: 30235. It identifies a related wakeup, not proof that 30235 owned the earlier lock. Correlate complete stacks, lock or mmap operations, and timing. The full trace is unavailable here, so these crops do not verify the root cause.
Common Causes for IOWait and Optimizations
1. Active IO Operations
Candidates include synchronous reads/writes, fsync, filesystem metadata, competing storage users, and the actual swap backend. Distinguish them using request sizes, access patterns, latency, queues, and errors. A D interval alone does not diagnose fragmentation, flash aging, or low free space.
Optimization methods:
- Reduce critical-path synchronous I/O, combine unnecessary small requests, and batch appropriately. After making work asynchronous, check that the wait was not merely moved onto another critical dependency.
- Readahead helps predictable locality; excessive prefetch consumes bandwidth and memory. Measure the target workload instead of always increasing it.
- Page-cache reclaim, system-file residency, and storage-maintenance policies belong to platform configuration. PinFile or locking many pages is not a general app solution and can crowd out other work.
- An I/O benchmark describes its own conditions, not the complete application workload, cache state, temperature, and filesystem behavior.
Swap-in need not read physical storage. Android commonly uses compressed RAM through zRAM, with CPU decompression cost. zRAM configured with a backing device/writeback may also use storage. Check the actual configuration; see Android memory management and zRAM.
2. High IO due to Low Memory
File-page caching reduces repeated reads. Memory pressure may cause more eviction, faults, reclaim, or writeback, but it does not mean almost every I/O bypasses memory and hits disk. Distinguish file-backed and anonymous pages, clean and dirty pages, and the swap backend.
Optimization methods:
- Reduce synchronous I/O on critical paths and organize data/prefetch for the measured access pattern.
- Avoid unbounded business caches, unnecessary residency, and excessive short-lived allocations.
- At the platform level, correlate reclaim, faults, storage, and memory-pressure events. Distinguish useful cache occupancy from pressure delaying work rather than maximizing free RAM.
System memory is shared by all processes. An app that grabs resources without considering its neighbors can hurt them, then suffer itself when the system intervenes. Expecting every developer to account for all of this is unrealistic. I think clear, enforced platform rules may be the way out.
Common Causes for Non-IOWait
- Reclaim or page waits: pressure can involve locks, page waits, and writeback, with either Non-IO or I/O-marked intervals. Inspect the actual stack and events.
- Binder kernel paths: particular operations or locks can produce this state, but waiting for a synchronous Binder reply commonly appears as ordinary Sleep. Transaction volume alone is not a diagnosis.
- Other kernel locks, drivers, and completion conditions: Non-IO is a starting classification, not the final cause.
System Scheduling and UninterruptibleSleep Coupling
If a verified lock owner spends a long time Runnable, its scheduling delay can extend another thread’s lock wait; priority inversion is one possible case. Establish ownership first instead of inferring it from Non-IO or wakeup from.
Shorten critical sections, avoid expensive work while holding locks, and investigate why the dependency is not running. Linux provides RT-mutex / PI-futex priority inheritance for applicable locks, but not every mutex, rwsem, or futex wait automatically has PI. It does not replace sound locking design, and scheduler modification is not the only possible remedy.
Appendix
Linux Thread State Definitions
These are common Trace display symbols, not an exact mapping of every kernel version’s /proc state characters. Parsers also support historical combinations; use the actual event and viewer version.
| Display symbol | Meaning and limits |
|---|---|
| S | Sleeping, typically an interruptible wait |
| R | Runnable; raw Linux TASK_RUNNING also includes execution, which the viewer separates as Running |
| R+ | Runnable after preemption |
| D | Uninterruptible Sleep; alone it does not establish I/O or fatal-signal behavior |
| T / t | Stopped / traced |
| Z | Zombie |
| X / x | Historical exit/task-dead representations |
| K | Wake-kill flag, potentially combined with other states; not a synonym for D |
| W | Waking, depending on kernel and parser reporting |
| I / P / N | Idle / Parked / No-load markers, version-dependent |
| Unknown or absent fields | Insufficient data, not automatically Sleep, Non-IO, or zero wait |
See Perfetto scheduling states.
Case: Waiting for Swap Data

The selected entry shows Uninterruptible Sleep - Block I/O with do_swap_page+0x138/0xf34, supporting investigation of the swap-in path. It does not prove the backing data came from flash or that the entire 295.448 ms selection at the top belongs to this one wait. Check the backend, page/I/O events, selected state interval, and kernel version.
Case: mmap Contention Across Multiple Threads

The UI thread’s blocked location is vm_mmap_pgoff+0x74/0x108; “Running instead” shows RenderThread. This suggests investigating address-space mapping contention, but does not prove RenderThread owns the relevant lock.
Threads in one process normally share mm_struct. The complete Linux v5.10 vm_mmap_pgoff below is a versioned mechanism reference:
1 | unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr, |
The write-protected region runs from mmap_write_lock_killable() to mmap_write_unlock(). Its lock wait can return -EINTR for a fatal signal, so a D display alone does not prove SIGKILL is ineffective. mm_populate() runs after unlock; the function name alone does not locate the wait at lock acquisition. Resolve the offset with matching build symbols and correlate lock and thread activity.
About Me && Blog
Below is my personal intro and related links. I look forward to exchanging ideas with fellow professionals. “When three walk together, one can always be my teacher!”
- Blogger Intro: Includes personal WeChat and WeChat group links.
- Blog Content Navigation: A guide for my blog content.
- Curated Excellent Blog Articles - Android Performance Optimization Must-Knows: Welcome to recommend projects/articles.
- Android Performance Optimization Knowledge Planet: The paid community stopped operating in 2026 and no longer accepts new members; this link preserves its history.
One walks faster alone, but a group walks further together.
