Fundamentals 11 min read

How TencentOS Redefines Memory Unloading to Slash Costs and Boost Performance

This article explains how Tencent Cloud’s rapid growth has driven innovative memory management techniques—such as multi‑level memory offloading, hot‑cold page detection, and swap subsystem redesign—to reduce memory costs, improve performance, and enhance scalability across diverse cloud workloads.

Tencent Architect
Tencent Architect
Tencent Architect
How TencentOS Redefines Memory Unloading to Slash Costs and Boost Performance

01. Memory Management and Multi‑Level Unloading

In today’s digital era, Tencent Cloud’s business scale and complexity have exploded, driving up memory costs and management complexity. Memory, a core cost in data centers, is scarce on both desktop and mobile platforms, making its management crucial for performance and cost.

The system contains a large amount of cold memory that has not been accessed for a long time. Memory offloading aims to fully utilize all resources by moving cold memory to secondary storage devices.

02. Why the Operating System Should Actively Unload Memory

Key industry challenges include:

Hotness detection: Identifying cold memory in production while balancing accuracy and performance.

Memory offloading: Understanding bottlenecks in anonymous page → SWAP and cache → reclamation efficiency.

mTHP management: New mTHP concepts introduce challenges with varying huge‑page sizes.

Memory management overhead optimization: Reducing kernel overhead and ensuring scalability as system size grows.

Tencent Cloud has explored and implemented a series of innovations, contributing them back to the Linux kernel and advancing OpenCloudOS.

03. Industry Pain Points and Our Breakthroughs

The kernel handles virtual memory management, including page tables, page faults, over‑commit, migration, compaction, and allocation. It uses CPU resources for memory control, awareness, and mapping, enabling global resource scheduling. Hotness detection allows the kernel to precisely identify cold pages and swap them out to colder devices.

For anonymous pages, the kernel’s SWAP can move them to block devices, freeing valuable memory.

Breakthrough 1: Cold Memory Identification and Eviction Optimization

The traditional Active/Inactive LRU mechanism has drawbacks such as heavy scanning of page‑table access bits and high overhead during memory pressure. Tencent discovered that Linux kernel 6.1’s MGLRU favors file‑page reclamation, hurting performance in hot‑file scenarios. To address this, they:

Refactored the Workingset Refault Distance algorithm to fit the MGLRU framework, fixing upstream OOM regressions.

Adapted a timestamp algorithm, assigning an 8‑byte timestamp to each evicted page and maintaining a per‑LRU eviction‑count timestamp, enabling precise hotness judgment and yielding 5‑57% latency reductions in certain workloads.

Breakthrough 2: SWAP Allocator Refactor and Lock Optimization

The kernel’s SWAP path remains complex and inefficient. Tencent’s contributions include fixing an eight‑year‑old data‑corruption bug, optimizing Page Cache/Xarray algorithms (improving performance by ~10%), and proposing a new SWAP Table data structure that enhances performance and reduces memory usage.

SWAP Table illustration
SWAP Table illustration

Breakthrough 3: Cache Eviction Efficiency Optimization

Beyond page‑level management, the kernel also handles sub‑page objects (Inode, Dentry, Shadow Node). Global List LRU locks become a bottleneck under memory pressure across containers. Tencent applied RCU and lock‑semantic stabilization to improve allocation and reclamation paths.

Cache eviction optimization diagram
Cache eviction optimization diagram

Breakthrough 4: Fundamental Performance and Scalability – Memory Counting

Memory page counting (RSS) is a core kernel capability. Traditional per‑task batch updates sacrifice accuracy for performance. Tencent introduced a Global Per‑CPU RSS Counter design, integrating with the scheduler to achieve low memory overhead and high concurrency performance.

04. Achievements in Multiple Scenarios

In smooth scaling scenarios, memory compression reduced configurations from 4C8G to 4C4G without performance loss, improving resource utilization. In load‑throttling scenarios, enabling memory compression significantly increased QPS. In mixed‑workload environments, compression freed memory, allowing more offline resources to be scheduled.

Database, social avatar, and transcoding workloads also benefited from reduced memory usage, lower failure rates, and stable CPU utilization.

Scenario performance gains
Scenario performance gains

05. Future Outlook

As system scale and memory capacity continue to grow, the Linux kernel still has ample room for improvement in memory management. Tencent Cloud will keep advancing kernel technologies, having obtained review rights for the SWAP subsystem and planning deeper involvement in kernel development to tackle upcoming challenges.

Linuxtencentoscloud operations
Tencent Architect
Written by

Tencent Architect

We share insights on storage, computing, networking and explore leading industry technologies together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.