1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_CACHE_SIMPLE_POLICY_H
5 #define CEPH_CACHE_SIMPLE_POLICY_H
7 #include "common/ceph_context.h"
8 #include "common/ceph_mutex.h"
9 #include "include/lru.h"
12 #include <unordered_map>
16 namespace immutable_obj_cache
{
18 class SimplePolicy
: public Policy
{
20 SimplePolicy(CephContext
*cct
, uint64_t block_num
, uint64_t max_inflight
,
24 cache_status_t
lookup_object(std::string file_name
);
25 cache_status_t
get_status(std::string file_name
);
27 void update_status(std::string file_name
,
28 cache_status_t new_status
,
31 int evict_entry(std::string file_name
);
33 void get_evict_list(std::list
<std::string
>* obj_list
);
35 uint64_t get_free_size();
36 uint64_t get_promoting_entry_num();
37 uint64_t get_promoted_entry_num();
38 std::string
get_evict_entry();
41 cache_status_t
alloc_entry(std::string file_name
);
43 class Entry
: public LRUObject
{
45 cache_status_t status
;
46 Entry() : status(OBJ_CACHE_NONE
) {}
47 std::string file_name
;
53 uint64_t m_max_inflight_ops
;
54 uint64_t m_max_cache_size
;
55 std::atomic
<uint64_t> inflight_ops
= 0;
57 std::unordered_map
<std::string
, Entry
*> m_cache_map
;
58 ceph::shared_mutex m_cache_map_lock
=
59 ceph::make_shared_mutex("rbd::cache::SimplePolicy::m_cache_map_lock");
61 std::atomic
<uint64_t> m_cache_size
;
66 } // namespace immutable_obj_cache
68 #endif // CEPH_CACHE_SIMPLE_POLICY_H