]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
crimson/common: added templated LRU cache
authorJianpeng Ma <jianpeng.ma@intel.com>
Thu, 22 Nov 2018 08:25:20 +0000 (16:25 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 14 Feb 2019 16:47:31 +0000 (00:47 +0800)
commitdd34fdb361cde5a32d392520a833526c5ad39b04
tree8d44aa202205ac13dcef6247bfb689c303a66f45
parent9842703f89ce01dc78e5d7282cbc91e4c9ffd32e
crimson/common: added templated LRU cache

the implementation is modeled after src/common/shared_cache.hpp, with
following changes/improvements

* split the implementation into two parts:
  - simple_lru.h: for the basic LRU cache. which tracks the least recently
    used (LRU) cache using a list, and uses a map for lookup. in
    future, we could use boost's multiple-index-container to replace
    this combination.
  - shared_lru.h: for the improved version of LRU cache, it also tries
    to track the evcited but still alive objects using a customized
    deleter of shared_ptr, and it keeps a map of weak_ptr pointing to
    these objects. the customized deleter will remove the tracked
    item in weak_ptr map once all shared_ptrs are destroyed.
* specialize LRUCache for ordered and non-ordered lookup. in existing
  OSD, `SimpleLRU` is used for caching the encoded osdmaps, and we
  don't use `lower_bound()`, `upper_bound()` or `get_next()` accessors
  for accessing these maps, so no need to store them with `std::map`.
  and in crimson-osd, it would be great if we can ditch `SimpleLRU`,
  and reuse `LRUCache` directly if `SharedLRU` is overkill. so let's
  prepare for this by specializing for the `unordered_map<>`.
* remove (not yet) unused methods from SharedLRU, like `purge()`,
  dump_weak_refs()
* change some function signatures to resemble those in `std::map`,
  for instance,
  - change `lookup()` to `find()`
  - change `lookup_or_create()` to `operator[]()`
* add comment to document `SharedLRU` class
* add test for SharedLRU

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/common/shared_lru.h [new file with mode: 0644]
src/crimson/common/simple_lru.h [new file with mode: 0644]
src/test/crimson/CMakeLists.txt
src/test/crimson/test_lru.cc [new file with mode: 0644]