Metadata configuration and tuning

Updated at:

Optimizing the number of metadata requests that ossfs 2.0 sends to Object Storage Service (OSS) reduces OSS requests and service invocation costs, and improves the concurrent processing and read/write performance of mount targets. This topic covers metadata tuning best practices for typical scenarios.

Configuration items

Configuration item

Description

attr_timeout

The time in seconds before the metadata cache expires. The default value is 60 s. After expiration, a new request is sent to OSS for the latest metadata.

max_inode_cache_count

Enables active control over the number of metadata cache entries.

  • The default value is 0. This means active control is disabled, and the operating system automatically evicts metadata.

  • If set to a positive integer, active control is enabled. When the number of cache entries exceeds the set value, ossfs 2.0 evicts the excess entries based on specific rules.

oss_negative_cache_timeout

The expiration time for the negative cache, in seconds.

  • The default value is 0, which means negative caching is disabled.

  • If set to a positive integer, negative caching is enabled and the cache expires after the specified time.

oss_negative_cache_size

The maximum number of entries in the negative cache. The default value is 10000. When the number of cache entries exceeds this value, ossfs 2.0 evicts the excess entries based on specific rules.

Scenarios and suggestions

Reduce OSS requests and accelerate performance

Scenario

Suggestion

Sequentially accessing files from a known file list

Enable the metadata cache. When you traverse all files in a folder, first run the ls command to preload file metadata into the local cache, and set a long expiration time for attr_timeout. This reduces repeated metadata requests for subsequent access and improves overall performance.

Creating many files

Enable the negative metadata cache. When mounting, specify --oss_negative_cache_timeout=30 (in seconds). A value smaller than attr_timeout is recommended. You can also specify --oss_negative_cache_size. The default value is 10,000, which is sufficient for most use cases.

This scenario applies if all of the following conditions are met:

  • The dataset contains many files (for example, more than 1 million) that are infrequently modified and require repeated access, such as in a read-only scenario.

  • Read and write operations consume the machine's page cache, which triggers the operating system to evict metadata under memory pressure.

  • The machine has sufficient memory available.

    Important

    Based on an average filename length of 50 bytes, the memory usage for 1 million metadata entries is approximately 600 MiB, and for 10 million metadata entries is approximately 6 GiB. You must reserve ample extra memory.

Example scenario: An ImageNet training task with a dataset of 10 million entries runs on a machine with 64 GiB of memory. The task first traverses the dataset to build metadata, and then reads the files.

Suggestion: The read task occupies the machine's page cache, causing the operating system kernel to request metadata eviction. Enable the metadata cache to prevent eviction and keep all metadata in memory, which reduces subsequent OSS metadata requests. The machine has enough memory to cache all 10 million entries.

  • Set --max_inode_cache_count to a value greater than the total number of files, for example, 11,000,000, to cache all metadata.

  • Set --attr_timeout to a large value, for example, 36,000 (10 hours), to prevent frequent metadata expiration.

Memory control

Access scenario

Example scenario

Suggestion

A small number of files are accessed

Fewer than 1 million files are accessed.

No special settings are required. The operating system automatically manages the metadata cache.

Files are not accessed repeatedly

After a folder is accessed, the files in the folder do not need to be read again before the metadata expires.

No special settings are required. The operating system automatically manages the metadata cache.

Memory usage is a concern

You want to reduce the metadata memory usage of the ossfs 2.0 process, and metadata performance is not a priority.

Set the --max_inode_cache_count parameter as needed.

The read and write buffers of ossfs 2.0 also consume memory. For more information, see Mounting options. Reserve some additional memory for actual operations.

Usage examples

Example scenario

Suggestion

Running an ImageNet training task

  • Machine specifications: 16-core CPU, 64 GiB memory

  • Dataset size: 10 million

When you mount the file system, specify --max_inode_cache_count=11,000,000 --attr_timeout=36,000 to cache all metadata with a 10-hour expiration time. With this configuration, the ossfs 2.0 process uses approximately 5.9 GiB of memory during training, and the training speed is approximately 2,100 images per second.

By contrast, if you use the default parameters, the training speed is approximately 630 images per second.

Frequently querying small files (for example, 10 KB) or having no concurrent access

  • Machine specifications: 8-core CPU, 32 GiB memory

  • Number of files: 100,000

When you mount the file system, specify --attr_timeout=36,000. Because the metadata does not consume much memory, you can set a long expiration time such as 10 hours. For 10 hours after the first access to the 100,000 files, subsequent accesses hit the cache. For example, running the stat command in a single stream to query 100,000 files in a bucket takes approximately 781 s on the first access. Subsequent repeated accesses within 10 hours each take approximately 55 s.

Starting 10 concurrent processes, with each process creating 10,000 empty files

  • Machine specifications: 8-core CPU, 32 GiB memory

  • Number of files: 100,000, with 10,000 per concurrent process

When you mount the file system, specify --oss_negative_cache_timeout=30. With the negative cache enabled, the operation takes approximately 470 s.

Without the negative cache, the operation takes approximately 680 s, and the number of OSS metadata requests doubles.

Sequentially reading the metadata of files in a single folder

  • Machine specifications: 8-core CPU, 32 GiB memory

  • Number of files: 10,000

When you mount the file system, specify --attr_timeout=36,000. Run the ls command first to preload metadata, and then read file metadata in the folder. The operation takes approximately 18 s.

Without running ls first, directly reading the file metadata in the folder takes approximately 111 s.