Skip to content
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

DAOS-16569 vos: fix few defects #15175

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vos/vos_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ gc_reclaim_pool(struct vos_pool *pool, int *credits, bool *empty_ret)
rg.cr_off = umem_get_mb_base_offset(vos_pool2umm(pool), bkt);
rg.cr_size = vos_pool2store(pool)->cache->ca_page_sz;

rc = vos_cache_pin(vos_pool2store(pool), &rg, 1, false, &pin_hdl);
rc = vos_cache_pin(pool, &rg, 1, false, &pin_hdl);
if (rc) {
DL_ERROR(rc, "Failed to pin bucket %u.", bkt);
goto tx_error;
Expand Down
32 changes: 27 additions & 5 deletions src/vos/vos_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,23 @@ vos_obj_reserve(struct umem_instance *umm, struct vos_object *obj,
}

/* vos_obj_cache.c */
static inline struct dtx_handle *
clear_cur_dth(struct vos_pool *pool)
{
struct dtx_handle *dth;

dth = vos_dth_get(pool->vp_sysdb);
vos_dth_set(NULL, pool->vp_sysdb);

return dth;
}

static inline void
restore_cur_dth(struct vos_pool *pool, struct dtx_handle *dth)
{
vos_dth_set(dth, pool->vp_sysdb);
}

static inline struct vos_cache_metrics *
store2cache_metrics(struct umem_store *store)
{
Expand All @@ -1935,9 +1952,9 @@ update_page_stats(struct umem_store *store)
if (vcm == NULL)
return;

d_tm_set_counter(vcm->vcm_pg_ne, cache->ca_pgs_stats[UMEM_PG_STATS_NONEVICTABLE]);
d_tm_set_counter(vcm->vcm_pg_pinned, cache->ca_pgs_stats[UMEM_PG_STATS_PINNED]);
d_tm_set_counter(vcm->vcm_pg_free, cache->ca_pgs_stats[UMEM_PG_STATS_FREE]);
d_tm_set_gauge(vcm->vcm_pg_ne, cache->ca_pgs_stats[UMEM_PG_STATS_NONEVICTABLE]);
d_tm_set_gauge(vcm->vcm_pg_pinned, cache->ca_pgs_stats[UMEM_PG_STATS_PINNED]);
d_tm_set_gauge(vcm->vcm_pg_free, cache->ca_pgs_stats[UMEM_PG_STATS_FREE]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Different from the counter, refreshing the gauge may cause more overhead. So it may be better to do that only when related stats changed.


d_tm_set_counter(vcm->vcm_pg_hit, cache->ca_cache_stats[UMEM_CACHE_STATS_HIT]);
d_tm_set_counter(vcm->vcm_pg_miss, cache->ca_cache_stats[UMEM_CACHE_STATS_MISS]);
Expand All @@ -1947,12 +1964,17 @@ update_page_stats(struct umem_store *store)
}

static inline int
vos_cache_pin(struct umem_store *store, struct umem_cache_range *ranges, int range_nr,
vos_cache_pin(struct vos_pool *pool, struct umem_cache_range *ranges, int range_nr,
bool for_sys, struct umem_pin_handle **pin_handle)
{
int rc;
struct umem_store *store = vos_pool2store(pool);
struct dtx_handle *cur_dth;
int rc;

cur_dth = clear_cur_dth(pool);
rc = umem_cache_pin(store, ranges, range_nr, for_sys, pin_handle);
restore_cur_dth(pool, cur_dth);

update_page_stats(store);

return rc;
Expand Down
2 changes: 1 addition & 1 deletion src/vos/vos_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ reserve_space(struct vos_io_context *ioc, uint16_t media, daos_size_t size,
if (media == DAOS_MEDIA_SCM) {
umem_off_t umoff;

umoff = vos_reserve_scm(ioc->ic_cont, ioc->ic_rsrvd_scm, size, ioc->ic_obj);
umoff = vos_reserve_scm(ioc->ic_cont, ioc->ic_rsrvd_scm, size, ioc->ic_pinned_obj);
if (!UMOFF_IS_NULL(umoff)) {
ioc->ic_umoffs[ioc->ic_umoffs_cnt] = umoff;
ioc->ic_umoffs_cnt++;
Expand Down
27 changes: 21 additions & 6 deletions src/vos/vos_obj_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,27 @@ vos_obj_unpin(struct vos_object *obj)
static void
obj_allot_bkt(struct vos_pool *pool, struct vos_object *obj)
{
struct dtx_handle *cur_dth;

D_ASSERT(umem_tx_none(vos_pool2umm(pool)));

if (obj->obj_bkt_alloting) {
cur_dth = clear_cur_dth(pool);

ABT_mutex_lock(obj->obj_mutex);
ABT_cond_wait(obj->obj_wait_alloting, obj->obj_mutex);
ABT_mutex_unlock(obj->obj_mutex);

D_ASSERT(obj->obj_bkt_alloted == 1);
restore_cur_dth(pool, cur_dth);
return;
}
obj->obj_bkt_alloting = 1;

if (!obj->obj_df) {
cur_dth = clear_cur_dth(pool);
obj->obj_bkt_ids[0] = umem_allot_mb_evictable(vos_pool2umm(pool), 0);
restore_cur_dth(pool, cur_dth);
} else {
struct vos_obj_p2_df *p2 = (struct vos_obj_p2_df *)obj->obj_df;

Expand All @@ -319,6 +326,7 @@ static int
obj_pin_bkt(struct vos_pool *pool, struct vos_object *obj)
{
struct umem_store *store = vos_pool2store(pool);
struct dtx_handle *cur_dth;
struct umem_cache_range rg;
int rc;

Expand All @@ -329,10 +337,13 @@ obj_pin_bkt(struct vos_pool *pool, struct vos_object *obj)
}

if (obj->obj_bkt_loading) {
cur_dth = clear_cur_dth(pool);

ABT_mutex_lock(obj->obj_mutex);
ABT_cond_wait(obj->obj_wait_loading, obj->obj_mutex);
ABT_mutex_unlock(obj->obj_mutex);

restore_cur_dth(pool, cur_dth);
/* The loader failed on vos_cache_pin() */
if (obj->obj_pin_hdl == NULL) {
D_ERROR("Object:"DF_UOID" isn't pinned.\n", DP_UOID(obj->obj_id));
Expand All @@ -343,7 +354,8 @@ obj_pin_bkt(struct vos_pool *pool, struct vos_object *obj)
if (obj->obj_pin_hdl != NULL) {
struct vos_cache_metrics *vcm = store2cache_metrics(store);

d_tm_inc_counter(vcm->vcm_obj_hit, 1);
if (vcm)
d_tm_inc_counter(vcm->vcm_obj_hit, 1);
return 0;
}

Expand All @@ -352,7 +364,7 @@ obj_pin_bkt(struct vos_pool *pool, struct vos_object *obj)
rg.cr_off = umem_get_mb_base_offset(vos_pool2umm(pool), obj->obj_bkt_ids[0]);
rg.cr_size = store->cache->ca_page_sz;

rc = vos_cache_pin(store, &rg, 1, false, &obj->obj_pin_hdl);
rc = vos_cache_pin(pool, &rg, 1, false, &obj->obj_pin_hdl);
if (rc)
DL_ERROR(rc, "Failed to pin object:"DF_UOID".", DP_UOID(obj->obj_id));

Expand Down Expand Up @@ -812,6 +824,7 @@ vos_bkt_array_subset(struct vos_bkt_array *super, struct vos_bkt_array *sub)
{
int i, idx;

D_ASSERT(sub->vba_cnt > 0);
if (sub->vba_cnt > super->vba_cnt)
return false;

Expand All @@ -832,9 +845,11 @@ vos_bkt_array_add(struct vos_bkt_array *bkts, uint32_t bkt_id)
D_ASSERT(bkt_id != UMEM_DEFAULT_MBKT_ID);

/* The @bkt_id is already in bucket array */
idx = daos_array_find(bkts->vba_bkts, bkts->vba_cnt, bkt_id, &bkt_sort_ops);
if (idx >= 0)
return 0;
if (bkts->vba_cnt > 0) {
idx = daos_array_find(bkts->vba_bkts, bkts->vba_cnt, bkt_id, &bkt_sort_ops);
if (idx >= 0)
return 0;
}

/* Bucket array needs be expanded */
if (bkts->vba_cnt == bkts->vba_tot) {
Expand Down Expand Up @@ -890,7 +905,7 @@ vos_bkt_array_pin(struct vos_pool *pool, struct vos_bkt_array *bkts,
ranges[i].cr_size = vos_pool2store(pool)->cache->ca_page_sz;
}

rc = vos_cache_pin(vos_pool2store(pool), ranges, bkts->vba_cnt, false, pin_hdl);
rc = vos_cache_pin(pool, ranges, bkts->vba_cnt, false, pin_hdl);
if (rc)
DL_ERROR(rc, "Failed to pin %u ranges.", bkts->vba_cnt);

Expand Down
Loading