|
19 | 19 | * Copyright (c) 2013 NVIDIA Corporation. All rights reserved. |
20 | 20 | * Copyright (c) 2016 Research Organization for Information Science |
21 | 21 | * and Technology (RIST). All rights reserved. |
| 22 | + * Copyright (c) 2020 Google, LLC. All rights reserved. |
22 | 23 | * |
23 | 24 | * $COPYRIGHT$ |
24 | 25 | * |
@@ -167,24 +168,56 @@ static inline void do_unregistration_gc (mca_rcache_base_module_t *rcache) |
167 | 168 | dereg_mem ((mca_rcache_base_registration_t *) item); |
168 | 169 | } |
169 | 170 | } |
| 171 | + |
| 172 | +static inline mca_rcache_base_registration_t *mca_rcache_grdma_remove_lru_head(mca_rcache_grdma_cache_t *cache) { |
| 173 | + mca_rcache_base_registration_t *old_reg; |
| 174 | + int32_t old_flags; |
| 175 | + |
| 176 | + do { |
| 177 | + opal_mutex_lock (&cache->vma_module->vma_lock); |
| 178 | + old_reg = (mca_rcache_base_registration_t *) opal_list_remove_first (&cache->lru_list); |
| 179 | + if (NULL == old_reg) { |
| 180 | + opal_mutex_unlock (&cache->vma_module->vma_lock); |
| 181 | + break; |
| 182 | + } |
| 183 | + |
| 184 | + do { |
| 185 | + int32_t new_flags; |
| 186 | + old_flags = old_reg->flags; |
| 187 | + /* registration has been selected for removal and is no longer in the LRU. mark it |
| 188 | + * as such. */ |
| 189 | + new_flags = (old_flags & ~MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU) | MCA_RCACHE_FLAGS_INVALID; |
| 190 | + if (opal_atomic_compare_exchange_strong_32(&old_reg->flags, &old_flags, new_flags)) { |
| 191 | + break; |
| 192 | + } |
| 193 | + } while (1); |
| 194 | + opal_mutex_unlock (&cache->vma_module->vma_lock); |
| 195 | + |
| 196 | + if (old_flags & MCA_RCACHE_FLAGS_INVALID) { |
| 197 | + /* registration was already invalidated. in this case its fate is being determined |
| 198 | + * by another thread. */ |
| 199 | + continue; |
| 200 | + } |
| 201 | + |
| 202 | + return old_reg; |
| 203 | + } while (1); |
| 204 | + |
| 205 | + return NULL; |
| 206 | +} |
| 207 | + |
170 | 208 | static inline bool mca_rcache_grdma_evict_lru_local (mca_rcache_grdma_cache_t *cache) |
171 | 209 | { |
172 | 210 | mca_rcache_grdma_module_t *rcache_grdma; |
173 | 211 | mca_rcache_base_registration_t *old_reg; |
174 | 212 |
|
175 | | - opal_mutex_lock (&cache->vma_module->vma_lock); |
176 | | - old_reg = (mca_rcache_base_registration_t *) |
177 | | - opal_list_remove_first (&cache->lru_list); |
| 213 | + old_reg = mca_rcache_grdma_remove_lru_head(cache); |
178 | 214 | if (NULL == old_reg) { |
179 | | - opal_mutex_unlock (&cache->vma_module->vma_lock); |
180 | 215 | return false; |
181 | 216 | } |
182 | 217 |
|
183 | 218 | rcache_grdma = (mca_rcache_grdma_module_t *) old_reg->rcache; |
184 | 219 |
|
185 | 220 | (void) dereg_mem (old_reg); |
186 | | - opal_mutex_unlock (&cache->vma_module->vma_lock); |
187 | | - |
188 | 221 | rcache_grdma->stat_evicted++; |
189 | 222 |
|
190 | 223 | return true; |
@@ -230,11 +263,9 @@ static inline void mca_rcache_grdma_remove_from_lru (mca_rcache_grdma_module_t * |
230 | 263 |
|
231 | 264 | /* opal lists are not thread safe at this time so we must lock :'( */ |
232 | 265 | opal_mutex_lock (&rcache_grdma->cache->vma_module->vma_lock); |
233 | | - |
234 | 266 | opal_list_remove_item (&rcache_grdma->cache->lru_list, (opal_list_item_t *) grdma_reg); |
235 | 267 | /* clear the LRU flag */ |
236 | 268 | grdma_reg->flags &= ~MCA_RCACHE_GRDMA_REG_FLAG_IN_LRU; |
237 | | - |
238 | 269 | opal_mutex_unlock (&rcache_grdma->cache->vma_module->vma_lock); |
239 | 270 | } |
240 | 271 |
|
|
0 commit comments