Skip to content

FileBackedStorageEngine may cause DirectMemory OutOfMemoryError when handling large objects #3285

@ShadowUnderMoon

Description

@ShadowUnderMoon

Hello,

I am using Ehcache 3 to cache very large objects. When testing the disk cache implementation (FileBackedStorageEngine), I found that file read/write operations are based on FileChannelImpl, which internally uses DirectByteBuffer. As a result, the temporary off-heap memory required can be roughly as large as the serialized object itself.

This can easily lead to exceeding the configured direct memory limit (-XX:MaxDirectMemorySize). On JDK 8, this situation may even trigger a deadlock due to JDK-8054039
.

In contrast, Ehcache 2 uses RandomAccessFile for file operations, which internally allocates memory via JNI malloc and does not encounter the same problem.

My question is: is there any plan to optimize this for large-object scenarios in Ehcache 3? For example, by implementing chunked writes/reads instead of requiring a single large direct buffer.

Environment:

Ehcache version: 3.10.8

JDK: 1.8

OS: Linux

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions