obdecho enviroment is already CL_thread type, so
easy to reuse cl_env cache instead of allocate env on each
ioctl call. It reduce cpu usage dramatically.
Cray-bug-id: LUS-7552
Signed-off-by: Alexey Lyashkov <c17817@cray.com>
Change-Id: Id4b36626233be6b65efc4daef649bf0ef97c2e60
Reviewed-on: https://review.whamcloud.com/35700
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
* with the standard tags.
*/
if (cl_envs[cpu].cec_count < cl_envs_cached_max &&
* with the standard tags.
*/
if (cl_envs[cpu].cec_count < cl_envs_cached_max &&
- (env->le_ctx.lc_tags & ~LCT_HAS_EXIT) == LCT_CL_THREAD &&
- (env->le_ses->lc_tags & ~LCT_HAS_EXIT) == LCT_SESSION) {
+ (env->le_ctx.lc_tags & ~LCT_HAS_EXIT) == lu_context_tags_default &&
+ (env->le_ses->lc_tags & ~LCT_HAS_EXIT) == lu_session_tags_default) {
read_lock(&cl_envs[cpu].cec_guard);
list_add(&cle->ce_linkage, &cl_envs[cpu].cec_envs);
cl_envs[cpu].cec_count++;
read_lock(&cl_envs[cpu].cec_guard);
list_add(&cle->ce_linkage, &cl_envs[cpu].cec_envs);
cl_envs[cpu].cec_count++;
* predefined when the lu_device type are registered, during the module probe
* phase.
*/
* predefined when the lu_device type are registered, during the module probe
* phase.
*/
-u32 lu_context_tags_default;
-u32 lu_session_tags_default;
+u32 lu_context_tags_default = LCT_CL_THREAD;
+u32 lu_session_tags_default = LCT_SESSION;
-#ifdef HAVE_SERVER_SUPPORT
void lu_context_tags_update(__u32 tags)
{
spin_lock(&lu_context_remembered_guard);
void lu_context_tags_update(__u32 tags)
{
spin_lock(&lu_context_remembered_guard);
spin_unlock(&lu_context_remembered_guard);
}
EXPORT_SYMBOL(lu_session_tags_clear);
spin_unlock(&lu_context_remembered_guard);
}
EXPORT_SYMBOL(lu_session_tags_clear);
-#endif /* HAVE_SERVER_SUPPORT */
int lu_env_init(struct lu_env *env, __u32 tags)
{
int lu_env_init(struct lu_env *env, __u32 tags)
{
+/* echo thread key have a CL_THREAD flag, which set cl_env function directly */
+#define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
+#define ECHO_DT_CTX_TAG (LCT_REMEMBER | LCT_DT_THREAD)
+#define ECHO_SES_TAG (LCT_REMEMBER | LCT_SESSION | LCT_SERVER_SESSION)
+
struct echo_device {
struct cl_device ed_cl;
struct echo_client_obd *ed_ec;
struct echo_device {
struct cl_device ed_cl;
struct echo_client_obd *ed_ec;
ucred->uc_valid = UCRED_INIT;
}
ucred->uc_valid = UCRED_INIT;
}
-#define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
-#define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION | LCT_SERVER_SESSION)
static int echo_md_handler(struct echo_device *ed, int command,
char *path, int path_len, __u64 id, int count,
struct obd_ioctl_data *data)
static int echo_md_handler(struct echo_device *ed, int command,
char *path, int path_len, __u64 id, int count,
struct obd_ioctl_data *data)
if (IS_ERR(env))
RETURN(PTR_ERR(env));
if (IS_ERR(env))
RETURN(PTR_ERR(env));
- rc = lu_env_refill_by_tags(env, ECHO_MD_CTX_TAG, ECHO_MD_SES_TAG);
+ rc = lu_env_refill_by_tags(env, ECHO_MD_CTX_TAG, ECHO_SES_TAG);
if (rc != 0)
GOTO(out_env, rc);
if (rc != 0)
GOTO(out_env, rc);
struct echo_object *eco;
struct obd_ioctl_data *data = karg;
struct lu_env *env;
struct echo_object *eco;
struct obd_ioctl_data *data = karg;
struct lu_env *env;
+ unsigned long env_tags = 0;
+ __u16 refcheck;
struct obdo *oa;
struct lu_fid fid;
int rw = OBD_BRW_READ;
int rc = 0;
struct obdo *oa;
struct lu_fid fid;
int rw = OBD_BRW_READ;
int rc = 0;
-#ifdef HAVE_SERVER_SUPPORT
- struct lu_context echo_session;
-#endif
ENTRY;
oa = &data->ioc_obdo1;
ENTRY;
oa = &data->ioc_obdo1;
- OBD_ALLOC_PTR(env);
- if (!env)
- RETURN(-ENOMEM);
+ env = cl_env_get(&refcheck);
+ if (IS_ERR(env))
+ RETURN(PTR_ERR(env));
- rc = lu_env_init(env, LCT_DT_THREAD);
- if (rc)
- GOTO(out_alloc, rc = -ENOMEM);
- if (rc)
- GOTO(out_env_fini, rc = -ENOMEM);
#ifdef HAVE_SERVER_SUPPORT
#ifdef HAVE_SERVER_SUPPORT
- env->le_ses = &echo_session;
- rc = lu_context_init(env->le_ses, LCT_SERVER_SESSION | LCT_NOREF);
- if (unlikely(rc < 0))
- GOTO(out_env, rc);
- lu_context_enter(env->le_ses);
+ if (cmd == OBD_IOC_ECHO_MD || cmd == OBD_IOC_ECHO_ALLOC_SEQ)
+ env_tags = ECHO_MD_CTX_TAG;
+ else
+#endif
+ env_tags = ECHO_DT_CTX_TAG;
+ rc = lu_env_refill_by_tags(env, env_tags, ECHO_SES_TAG);
+ if (rc != 0)
+ GOTO(out, rc);
+
+#ifdef HAVE_SERVER_SUPPORT
- tsi->tsi_exp = ec->ec_exp;
+ /* treat as local operation */
+ tsi->tsi_exp = NULL;
tsi->tsi_jobid = NULL;
#endif
tsi->tsi_jobid = NULL;
#endif
switch (cmd) {
case OBD_IOC_CREATE: /* may create echo object */
if (!cfs_capable(CFS_CAP_SYS_ADMIN))
switch (cmd) {
case OBD_IOC_CREATE: /* may create echo object */
if (!cfs_capable(CFS_CAP_SYS_ADMIN))
GOTO(out, rc);
}
case OBD_IOC_ECHO_ALLOC_SEQ: {
GOTO(out, rc);
}
case OBD_IOC_ECHO_ALLOC_SEQ: {
- struct lu_env *cl_env;
- __u16 refcheck;
__u64 seq;
int max_count;
if (!cfs_capable(CFS_CAP_SYS_ADMIN))
GOTO(out, rc = -EPERM);
__u64 seq;
int max_count;
if (!cfs_capable(CFS_CAP_SYS_ADMIN))
GOTO(out, rc = -EPERM);
- cl_env = cl_env_get(&refcheck);
- if (IS_ERR(cl_env))
- GOTO(out, rc = PTR_ERR(cl_env));
-
- rc = lu_env_refill_by_tags(cl_env, ECHO_MD_CTX_TAG,
- ECHO_MD_SES_TAG);
- if (rc != 0) {
- cl_env_put(cl_env, &refcheck);
- GOTO(out, rc);
- }
-
- rc = seq_client_get_seq(cl_env, ed->ed_cl_seq, &seq);
- cl_env_put(cl_env, &refcheck);
+ rc = seq_client_get_seq(env, ed->ed_cl_seq, &seq);
if (rc < 0) {
CERROR("%s: Can not alloc seq: rc = %d\n",
obd->obd_name, rc);
if (rc < 0) {
CERROR("%s: Can not alloc seq: rc = %d\n",
obd->obd_name, rc);
-#ifdef HAVE_SERVER_SUPPORT
- lu_context_exit(env->le_ses);
- lu_context_fini(env->le_ses);
-out_env:
-#endif
-out_env_fini:
- lu_env_fini(env);
-out_alloc:
- OBD_FREE_PTR(env);
+ cl_env_put(env, &refcheck);
INIT_LIST_HEAD(&ec->ec_locks);
ec->ec_unique = 0;
INIT_LIST_HEAD(&ec->ec_locks);
ec->ec_unique = 0;
+ lu_context_tags_update(ECHO_DT_CTX_TAG);
+ lu_session_tags_update(ECHO_SES_TAG);
+
if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
#ifdef HAVE_SERVER_SUPPORT
lu_context_tags_update(ECHO_MD_CTX_TAG);
if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
#ifdef HAVE_SERVER_SUPPORT
lu_context_tags_update(ECHO_MD_CTX_TAG);
- lu_session_tags_update(ECHO_MD_SES_TAG);
#else
CERROR(
"Local operations are NOT supported on client side. Only remote operations are supported. Metadata client must be run on server side.\n");
#else
CERROR(
"Local operations are NOT supported on client side. Only remote operations are supported. Metadata client must be run on server side.\n");
+ lu_session_tags_clear(ECHO_SES_TAG & ~LCT_SESSION);
+ lu_context_tags_clear(ECHO_DT_CTX_TAG);
if (ed->ed_next_ismd) {
#ifdef HAVE_SERVER_SUPPORT
lu_context_tags_clear(ECHO_MD_CTX_TAG);
if (ed->ed_next_ismd) {
#ifdef HAVE_SERVER_SUPPORT
lu_context_tags_clear(ECHO_MD_CTX_TAG);
- lu_session_tags_clear(ECHO_MD_SES_TAG);
#else
CERROR(
"This is client-side only module, does not support metadata echo client.\n");
#else
CERROR(
"This is client-side only module, does not support metadata echo client.\n");