Skip to content

[Bug]: CRC in 2KB data block cause unnecessary memmove (20% CPU time) #25040

Closed

Description

@cpegeric

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

6b98c6b

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

The data file contains multiple 2KB CRC-block which require memove to remove the CRC (4 byte) for every 2KB to make a contiguous memory for lz4 decompression. de-interleave operations took 20% CPU time.

Cold-scan profile — where cold time goes (read + decode, NOT materialize)

CPU profile of an f32 table scan (SELECT COUNT(*) … WHERE l2_distance(embedding,'[…]')≥0) with the
SHARED cache reverted to the default ~512 MB (the 3 GB column ≫ cache, so scans stay cold), vs the
warm scan. runtime.memmove (46% of cold CPU) splits cleanly: 46% lz4 decode + 45% FileWithChecksum
de-interleave + 8% UnionBatch
.

stage cold scan warm scan
read path (FileWithChecksum.ReadAt): pread + de-interleave + CRC ~51% 0 (cache-served)
├ pread syscall (kernel copy from page cache) ~27% —
├ de-interleave memmove (2 KB CRC-block → contiguous) ~21% —
└ CRC verify ~3% —
lz4 decode (decodeBlock) ~21% 0
materialize (UnionBatch memmove) ~4% ~56%
distance ~3% ~33%
  • Cold is read-path + decode bound (~72%); materialize is ~4%. Warm is the mirror — pure
    materialize + distance, with zero read/CRC/lz4 (decoded data served from cache).
  • lz4 runs ONLY on the cold (miss) path — the cache stores decoded data, so a warm hit never
    decompresses. The UnionBatch materialization fix is therefore a warm-scan win (~4% of cold vs ~56% of warm).
  • For bulk cold scans the FileWithChecksum de-interleave is ~21% (vs ~1.85% in point search) — it
    scales with bytes pushed through the per-2 KB-CRC on-disk format.

Expected Behavior

reduce/remove the number of memmove for de-interleave

Steps to Reproduce

Table scan with vecf32 vector

Additional information

No response

Activity

  1. added
    kind/bug
    on Jun 17, 2026
  2. LeftHandCold commented on Jun 17, 2026

    @LeftHandCold
    Collaborator

    Thanks for the detailed profile. One thing to clarify: this 2KB CRC-block format is specific to the local disk fileservice path (DISK / LocalFS, via FileWithChecksum). It is not inherent to all MatrixOne local tests.

    In the standalone/local launch configs, if SHARED is not explicitly configured, mo-service fills it with the default DISK backend. In that case TAE data files are stored through LocalFS, so cold scans can hit FileWithChecksum.ReadAt, read 2KB+CRC blocks, verify CRC, and copy the payload into contiguous memory before lz4 decode. That matches the profile here.

    For local testing we can still use the S3FS code path without running MinIO or any external object store. S3FS supports a disk-backed object storage mode: configure SHARED with backend = "S3", set [fileservice.s3].endpoint = "disk", and set [fileservice.s3].bucket to a local directory. In this setup, MatrixOne still uses S3FS semantics, but the objects are stored under a local directory. This avoids the LocalFS / FileWithChecksum 2KB CRC-block layout for the main TAE data path.

    LOCAL can still be configured as DISK for local metadata/cache/tmp usage. The table data path is controlled by tn.Txn.Storage.fileservice = "SHARED".

    A standalone/local config shape is:

    [[fileservice]]
    name = "LOCAL"
    backend = "DISK"
    data-dir = "./mo-data/local"
    
    [[fileservice]]
    name = "SHARED"
    backend = "S3"
    
    [fileservice.s3]
    endpoint = "disk"
    bucket = "./mo-data/s3fs-shared"
    key-prefix = "server/data"
    
    [fileservice.cache]
    memory-capacity = "512MB"
    disk-capacity = "2GB"
    disk-path = "./mo-data/file-service-cache"
    
    [tn.Txn.Storage]
    backend = "TAE"
    fileservice = "SHARED"
    log-backend = "logservice"

    The important part is backend = "S3" plus endpoint = "disk". In the code this creates an S3FS backed by diskObjectStorage; bucket is treated as the local root directory and key-prefix is the object prefix below it.

    So I would treat this issue as a LocalFS/DISK backend optimization. It is still worth optimizing if local-disk cold scan performance matters, but for real S3 deployments, and for local tests using S3FS with endpoint = "disk", this specific CRC de-interleave overhead should not be on the main data read path.

  3. cpegeric commented on Jun 18, 2026

    @cpegeric
    ContributorAuthor

    Hi, just discuss with Feng. We need to remove the CRC and keep the same file format as s3fs. For compatibility, keep the same LOCAL (with CRC) and create a new LOCAL2 to remove the CRC and change the .toml to use LOCAL2. After a few month and no one complain, we remove LOCAL completely from the repo.

  4. LeftHandCold commented on Jun 18, 2026

    @LeftHandCold
    Collaborator

    完全可以不使用localfs,直接配置本地使用s3fs就可以了,不需要再做什么工作去修改localfs

  5. cpegeric commented on Jun 18, 2026

    @cpegeric
    ContributorAuthor

    @LeftHandCold to follow up your idea.

    1. keep localfs untouch.
    2. change all .toml to use local s3fs
  6. added
    severity/s0
    on Jun 30, 2026
  7. added this to the MO-202607 milestone on Jun 30, 2026
  8. removed
    severity/s0
    on Jul 17, 2026
  9. XuPeng-SH commented on Jul 17, 2026

    @XuPeng-SH
    Contributor

    @cpegeric please help to close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions