-
Notifications
You must be signed in to change notification settings - Fork 3
[Fix] Resolve cache obj double free #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b5fb056
86921ed
90a9fa0
6de9ef3
e025ae9
894b8d5
a0ec1f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,6 +281,8 @@ def __init__( | |
| _cache=LIRS_init(_create_common_params(cache_size, default_ttl, hashpower, consider_obj_metadata)) | ||
| ) | ||
|
|
||
| def insert(self, req: Request) -> Optional[CacheObject]: | ||
| return super().insert(req) | ||
|
|
||
| class TwoQ(CacheBase): | ||
| """2Q replacement algorithm | ||
|
|
@@ -360,7 +362,7 @@ def __init__( | |
| update_weight: bool = True, | ||
| lru_weight: float = 0.5, | ||
| ): | ||
| cache_specific_params = f"update-weight={update_weight}, lru-weight={lru_weight}" | ||
| cache_specific_params = f"update-weight={int(update_weight)}, lru-weight={lru_weight}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good to see the explicit conversion of cache_specific_params = f"update-weight={int(update_weight)}, lru-weight={lru_weight}" |
||
| super().__init__( | ||
| _cache=LeCaR_init( | ||
| _create_common_params(cache_size, default_ttl, hashpower, consider_obj_metadata), cache_specific_params | ||
|
|
@@ -383,7 +385,7 @@ class ClockPro(CacheBase): | |
| """Clock-Pro replacement algorithm | ||
|
|
||
| Special parameters: | ||
| init_req: initial reference count (default: 0) | ||
| init_ref: initial reference count (default: 0) | ||
| init_ratio_cold: initial ratio of cold pages (default: 1) | ||
| """ | ||
|
|
||
|
|
@@ -393,10 +395,10 @@ def __init__( | |
| default_ttl: int = 86400 * 300, | ||
| hashpower: int = 24, | ||
| consider_obj_metadata: bool = False, | ||
| init_req: int = 0, | ||
| init_ref: int = 0, | ||
| init_ratio_cold: float = 0.5, | ||
| ): | ||
| cache_specific_params = f"init-req={init_req}, init-ratio-cold={init_ratio_cold}" | ||
| cache_specific_params = f"init-ref={init_ref}, init-ratio-cold={init_ratio_cold}" | ||
| super().__init__( | ||
| _cache=ClockPro_init( | ||
| _create_common_params(cache_size, default_ttl, hashpower, consider_obj_metadata), cache_specific_params | ||
|
|
@@ -451,13 +453,19 @@ def __init__( | |
|
|
||
|
|
||
| class LRUProb(CacheBase): | ||
| """LRU with Probabilistic Replacement (no special parameters)""" | ||
| """LRU with Probabilistic Replacement | ||
|
|
||
| Special parameters: | ||
| prob: probability of promoting an object to the head of the queue (default: 0.5) | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, cache_size: int, default_ttl: int = 86400 * 300, hashpower: int = 24, consider_obj_metadata: bool = False | ||
| self, cache_size: int, default_ttl: int = 86400 * 300, hashpower: int = 24, consider_obj_metadata: bool = False, | ||
| prob: float = 0.5, | ||
| ): | ||
| cache_specific_params = f"prob={prob}" | ||
| super().__init__( | ||
| _cache=LRU_Prob_init(_create_common_params(cache_size, default_ttl, hashpower, consider_obj_metadata)) | ||
| _cache=LRU_Prob_init(_create_common_params(cache_size, default_ttl, hashpower, consider_obj_metadata), cache_specific_params) | ||
| ) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,7 @@ | ||||||||||||||
| git submodule update --init --recursive | ||||||||||||||
| # Sync submodules | ||||||||||||||
| git submodule update --recursive --remote | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a check to ensure that the git submodule update command succeeds. This can be done by checking the exit code of the command and exiting the script with an error message if it fails.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| # Build the main libCacheSim C++ library first | ||||||||||||||
| echo "Building main libCacheSim library..." | ||||||||||||||
| pushd src/libCacheSim | ||||||||||||||
| bash scripts/install_dependency.sh | ||||||||||||||
| rm -rf build | ||||||||||||||
| cmake -G Ninja -B build | ||||||||||||||
| ninja -C build | ||||||||||||||
| popd | ||||||||||||||
|
|
||||||||||||||
| # Now build and install the Python binding | ||||||||||||||
| echo "Building Python binding..." | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -256,7 +256,7 @@ auto make_cache_wrapper(const std::string& fn_name) { | |||||||||
| cache_t* ptr = InitFn(cc_params, params_cstr); | ||||||||||
| return std::unique_ptr<cache_t, CacheDeleter>(ptr); | ||||||||||
| }, | ||||||||||
| "cc_params"_a, "cache_specific_params"_a = ""); | ||||||||||
| "cc_params"_a, "cache_specific_params"_a = ""); | ||||||||||
| }; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -280,7 +280,8 @@ void export_cache(py::module& m) { | |||||||||
| .def( | ||||||||||
| "find", | ||||||||||
| [](cache_t& self, const request_t& req, const bool update_cache) { | ||||||||||
| return self.find(&self, &req, update_cache); | ||||||||||
| cache_obj_t* obj = self.find(&self, &req, update_cache); | ||||||||||
| return py::cast(obj, py::return_value_policy::reference); | ||||||||||
|
Comment on lines
+283
to
+284
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||
| }, | ||||||||||
| "req"_a, "update_cache"_a = true) | ||||||||||
| .def( | ||||||||||
|
|
@@ -289,16 +290,23 @@ void export_cache(py::module& m) { | |||||||||
| return self.can_insert(&self, &req); | ||||||||||
| }, | ||||||||||
| "req"_a) | ||||||||||
| .def( | ||||||||||
| "insert", | ||||||||||
| [](cache_t& self, const request_t& req) { | ||||||||||
| return self.insert(&self, &req); | ||||||||||
| }, | ||||||||||
| "req"_a) | ||||||||||
| .def( | ||||||||||
| "insert", | ||||||||||
| [](cache_t& self, const request_t& req) -> std::optional<cache_obj_t*> { | ||||||||||
| cache_obj_t* inserted = self.insert(&self, &req); | ||||||||||
| if (inserted == nullptr) { | ||||||||||
| return std::nullopt; | ||||||||||
| } | ||||||||||
| return inserted; | ||||||||||
| }, | ||||||||||
| "req"_a, | ||||||||||
| py::return_value_policy::reference // optional still respected | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| .def( | ||||||||||
| "need_eviction", | ||||||||||
| [](cache_t& self, const request_t& req) { | ||||||||||
| return self.need_eviction(&self, &req); | ||||||||||
| return self.get_occupied_byte(&self) + req.obj_size > self.cache_size; | ||||||||||
| }, | ||||||||||
|
Comment on lines
+309
to
310
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition
Suggested change
|
||||||||||
| "req"_a) | ||||||||||
| .def( | ||||||||||
|
|
@@ -316,7 +324,8 @@ void export_cache(py::module& m) { | |||||||||
| .def( | ||||||||||
| "to_evict", | ||||||||||
| [](cache_t& self, const request_t& req) { | ||||||||||
| return self.to_evict(&self, &req); | ||||||||||
| cache_obj_t* obj = self.to_evict(&self, &req); | ||||||||||
| return py::cast(obj, py::return_value_policy::reference); | ||||||||||
| }, | ||||||||||
| "req"_a) | ||||||||||
| .def("get_occupied_byte", | ||||||||||
|
|
@@ -348,7 +357,7 @@ void export_cache(py::module& m) { | |||||||||
| params->default_ttl = default_ttl; | ||||||||||
| params->hashpower = hashpower; | ||||||||||
| params->consider_obj_metadata = consider_obj_metadata; | ||||||||||
| return params; | ||||||||||
| return std::unique_ptr<common_cache_params_t, CommonCacheParamsDeleter>(params); | ||||||||||
| }), | ||||||||||
| "cache_size"_a, "default_ttl"_a = 86400 * 300, "hashpower"_a = 24, | ||||||||||
| "consider_obj_metadata"_a = false) | ||||||||||
|
|
@@ -407,7 +416,7 @@ void export_cache(py::module& m) { | |||||||||
| req->hv = hv; | ||||||||||
| req->next_access_vtime = next_access_vtime; | ||||||||||
| req->ttl = ttl; | ||||||||||
| return req; | ||||||||||
| return std::unique_ptr<request_t, RequestDeleter>(req); | ||||||||||
| }), | ||||||||||
| "obj_size"_a = 1, "op"_a = OP_NOP, "valid"_a = true, "obj_id"_a = 0, | ||||||||||
| "clock_time"_a = 0, "hv"_a = 0, "next_access_vtime"_a = -2, | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to ensure that XGBOOST_INCLUDE_DIR is not already defined before setting it. This can prevent potential conflicts if the variable is defined elsewhere.