Skip to content

refactor(cache): lazy initialize rwlock to reduce memory usage#1149

Open
xiaoyang-hhh wants to merge 1 commit intoalibaba:release/0.9from
xiaoyang-hhh:cache_optimize
Open

refactor(cache): lazy initialize rwlock to reduce memory usage#1149
xiaoyang-hhh wants to merge 1 commit intoalibaba:release/0.9from
xiaoyang-hhh:cache_optimize

Conversation

@xiaoyang-hhh
Copy link
Contributor

@xiaoyang-hhh xiaoyang-hhh commented Mar 17, 2026

Change LruEntry::rw_lock_ from direct member to std::unique_ptr for lazy initialization in Full File Cache:

  • rw_lock_ is now created when the openCount in LruEntry changes from 0 to 1, and destroyed when it changes from 1 to 0
  • Add spinlock to protect rw_lock_ pointer during init/destroy

This reduces memory usage when there are many cache files, but only a small number of them are being read or written at any moment.

@lihuiba
Copy link
Collaborator

lihuiba commented Mar 18, 2026

given that you bind the life-cycle of rwlock to FileStore, is it possible to move the rwlock from LruEntry to FileStore?

@xiaoyang-hhh xiaoyang-hhh force-pushed the cache_optimize branch 3 times, most recently from 0a9319c to 87eef3f Compare March 18, 2026 11:44
@xiaoyang-hhh
Copy link
Contributor Author

given that you bind the life-cycle of rwlock to FileStore, is it possible to move the rwlock from LruEntry to FileStore?

The previous implementation had some issues. A cached file may correspond to multiple CacheStores meanwhile, so the rwlock is still kept in LruEntry, with its creation and destruction controlled by openCount.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants