# alinux-instance

Part of **ALINUX**

<!-- intent-backlink:auto -->

> 💡 **Path Selection**: This skill is one implementation path for the following routing skills. If you're unsure which path to take, check the corresponding routing skill:

> - [Deploy AI models for inference or training](../../intent/alinux-deploy-model/SKILL.md)
> - [Manage ECS instance creation, configuration, and maintenance](../../intent/alinux-manage-lifecycle/SKILL.md)

# Alibaba Cloud Linux Instance Management

## Capabilities Overview

| Sub-capability | Calling Mode | Description |
|----------------|--------------|-------------|
| Limit Page Cache Usage | Synchronous | Configure limits on page cache memory usage per memory control group (memcg) to prevent memory pressure and OOM errors. |
| List Available Container Images | Synchronous | Retrieve information about available AI container images for Alibaba Cloud Linux, including base OS, frameworks, and hardware support. |

## API Calling Patterns

### Authentication
No authentication is required for these capabilities, as they involve direct interaction with the operating system kernel or publicly available image metadata. These operations are performed locally on an Alibaba Cloud Linux instance with appropriate privileges (e.g., `sudo` access).

### Service Endpoint
These capabilities do not use remote HTTP endpoints. Instead:
- **Limit Page Cache Usage**: Configured via local sysfs interfaces at paths like `/sys/kernel/mm/pagecache_limit/` and `/sys/fs/cgroup/memory/`.
- **List Available Container Images**: Information is obtained from public documentation or container registries; no programmatic API endpoint is provided in the source material.

### Direct System Configuration (Synchronous)
For **Limit Page Cache Usage**, configuration is applied immediately by writing values to sysfs files:
1. Enable the global Page Cache Limit feature by writing to `/sys/kernel/mm/pagecache_limit/enabled`
2. Create or select a memory cgroup under `/sys/fs/cgroup/memory/`
3. Set per-cgroup parameters (`memory.pagecache_limit.size`, `memory.pagecache_limit.enable`, `memory.pagecache_limit.sync`)
4. Changes take effect synchronously upon write

No polling or asynchronous handling is required—operations complete immediately.

## Parameter Reference

### Limit Page Cache Usage

| Parameter | Type | Required | Default | Constraints | Description |
|-----------|------|----------|---------|-------------|-------------|
| enabled | integer | false | 0 | 0 or 1 | Global on/off switch for Page Cache Limit. Valid values: 0 (disabled) or 1 (enabled). |
| memory.pagecache_limit.enable | integer | false | 0 | 0 or 1 | Per-memcg on/off switch. Valid values: 0 (disabled) or 1 (enabled). |
| memory.pagecache_limit.size | integer | false | 0 | 0 to memory.limit_in_bytes | Sets the maximum page cache usage for a memcg in bytes. |
| memory.pagecache_limit.sync | integer | false | 0 | 0 or 1 | Controls the reclaim mode: 0 for asynchronous reclaim, 1 for synchronous reclaim. |

## Code Examples

### Enable Global Page Cache Limit - Bash - All Regions

```bash
sudo sh -c 'echo 1 > /sys/kernel/mm/pagecache_limit/enabled'
```

### Create Memory Cgroup and Set Page Cache Limit - Bash - All Regions

```bash
sudo mkdir -p /sys/fs/cgroup/memory/test/
sudo sh -c 'echo 10485760 > /sys/fs/cgroup/memory/test/memory.pagecache_limit.size'
sudo sh -c 'echo 0 > /sys/fs/cgroup/memory/test/memory.pagecache_limit.sync'
sudo sh -c 'echo 1 > /sys/fs/cgroup/memory/test/memory.pagecache_limit.enable'
```

### Install cgroup Tools for Management - Bash - All Regions

```bash
sudo yum install libcgroup-tools
```

### Run Workload Under Cgroup and Verify Cache Usage - Bash - All Regions

```bash
sudo dd if=/dev/zero of=./testfile bs=1M count=20 oflag=direct
sudo cgexec -g "memory:test" cat ./testfile > /dev/null
grep cache /sys/fs/cgroup/memory/test/memory.stat
cat /sys/fs/cgroup/memory/test/memory.exstat
```

## Error Handling

This domain does not define specific error codes, as operations are local system configurations. Common failure modes include:
- Permission denied (run with `sudo`)
- Invalid parameter values (respect constraints like 0/1 for boolean flags)
- Path not found (ensure cgroup hierarchy is mounted)

### Rate Limits & Retry
Not applicable—these are local system operations with no rate limiting.

## Environment Requirements

- An Elastic Compute Service (ECS) instance running **Alibaba Cloud Linux 3**, kernel version **5.10.134-14 or later**
- `sudo` access on the instance
- For cgroup management: `libcgroup-tools` package (install via `sudo yum install libcgroup-tools`)

## FAQ

Q: Do I need an API key or Alibaba Cloud credentials to use these features?
A: No. These capabilities involve direct interaction with the operating system kernel and require only local `sudo` access on an Alibaba Cloud Linux instance.

Q: Can I configure Page Cache Limit on Alibaba Cloud Linux 2?
A: No. The Page Cache Limit feature is only available in Alibaba Cloud Linux 3 with kernel version 5.10.134-14 or later.

Q: How do I list available container images programmatically?
A: The source documentation does not provide a programmatic API for listing container images. Users should refer to the official Alibaba Cloud documentation or container registry for available image tags and descriptions.

Q: What happens when page cache exceeds the limit?
A: Excess cache is reclaimed based on the configured mode: asynchronously (default) or synchronously. This prevents unbounded memory growth and reduces the risk of OOM kills.

Q: Are these features billed separately?
A: No. These are built-in kernel features of Alibaba Cloud Linux and are not billed separately from the underlying ECS instance.

## Pricing & Billing

### Billing Model
Free — these are kernel-level features included with Alibaba Cloud Linux 3 and not billed separately.

### Free Tier
No explicit free tier mentioned; the feature is part of the operating system kernel.

### Usage Limits
No specific quotas mentioned beyond memory limits set via memcg (e.g., `memory.pagecache_limit.size` must be ≤ `memory.limit_in_bytes`).

### Billing Notes
This is a kernel-level feature included in Alibaba Cloud Linux 3 and not billed separately. Container image usage follows standard ECS and storage billing based on actual resource consumption.