diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h
index 55424051e7fa46f58c1e5eea8665316cbc620827..994dd10b1765ec44987b39fd6f155bc1f9e02995 100644
--- a/lustre/include/obd_class.h
+++ b/lustre/include/obd_class.h
@@ -58,6 +58,7 @@
 /* OBD Device Declarations */
 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
 extern spinlock_t obd_dev_lock;
+extern cfs_mem_cache_t *obd_lvfs_ctxt_cache;
 
 /* OBD Operations Declarations */
 extern struct obd_device *class_conn2obd(struct lustre_handle *);
diff --git a/lustre/mds/mds_fs.c b/lustre/mds/mds_fs.c
index e59eb197d5aa35551948a6700bcbfd45931c22d6..d317a57602b02fdeef161a6a17421abef11a23e6 100644
--- a/lustre/mds/mds_fs.c
+++ b/lustre/mds/mds_fs.c
@@ -177,12 +177,18 @@ int mds_client_add(struct obd_device *obd, struct obd_export *exp,
         mds_export_stats_init(obd, exp, localdata);
 
         if (new_client) {
-                struct lvfs_run_ctxt saved;
+                struct lvfs_run_ctxt *saved = NULL;
                 loff_t off = med->med_lr_off;
                 struct file *file = mds->mds_rcvd_filp;
                 void *handle;
 
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+                OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
+                if (saved == NULL) {
+                        CERROR("cannot allocate memory for run ctxt\n");
+                        RETURN(-ENOMEM);
+                }
+
+                push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
                 handle = fsfilt_start(obd, file->f_dentry->d_inode,
                                       FSFILT_OP_SETATTR, NULL);
                 if (IS_ERR(handle)) {
@@ -202,7 +208,8 @@ int mds_client_add(struct obd_device *obd, struct obd_export *exp,
                         fsfilt_commit(obd, file->f_dentry->d_inode, handle, 0);
                 }
 
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+                pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
+                OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
 
                 if (rc)
                         return rc;
@@ -219,7 +226,7 @@ int mds_client_free(struct obd_export *exp)
         struct mds_obd *mds = &exp->exp_obd->u.mds;
         struct obd_device *obd = exp->exp_obd;
         struct lsd_client_data zero_lcd;
-        struct lvfs_run_ctxt saved;
+        struct lvfs_run_ctxt *saved = NULL;
         int rc;
         loff_t off;
         ENTRY;
@@ -256,13 +263,18 @@ int mds_client_free(struct obd_export *exp)
         }
 
         if (!(exp->exp_flags & OBD_OPT_FAILOVER)) {
+                OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
+                if (saved == NULL) {
+                        CERROR("cannot allocate memory for run ctxt\n");
+                        GOTO(free, rc = -ENOMEM);
+                }
                 memset(&zero_lcd, 0, sizeof(zero_lcd));
-                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+                push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
                 rc = fsfilt_write_record(obd, mds->mds_rcvd_filp, &zero_lcd,
                                          sizeof(zero_lcd), &off,
                                          (!exp->exp_libclient ||
                                           exp->exp_need_sync));
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+                pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
 
                 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
                        "zeroing out client %s idx %u in %s rc %d\n",
@@ -282,7 +294,10 @@ int mds_client_free(struct obd_export *exp)
         mds_update_server_data(exp->exp_obd, 0);
 
         EXIT;
- free:
+free:
+        if (saved)
+                OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
+
         OBD_FREE_PTR(med->med_lcd);
         med->med_lcd = NULL;
 
@@ -523,7 +538,7 @@ err_msd:
 int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
 {
         struct mds_obd *mds = &obd->u.mds;
-        struct lvfs_run_ctxt saved;
+        struct lvfs_run_ctxt *saved = NULL;
         struct dentry *dentry;
         struct file *file;
         int rc;
@@ -535,6 +550,12 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
         if (rc)
                 RETURN(rc);
 
+        OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
+        if (saved == NULL) {
+                CERROR("cannot allocate memory for run ctxt\n");
+                RETURN(-ENOMEM);
+        }
+
         mds->mds_vfsmnt = mnt;
         /* why not mnt->mnt_sb instead of mnt->mnt_root->d_inode->i_sb? */
         obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb;
@@ -550,7 +571,7 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
         obd->obd_lvfs_ctxt.cb_ops = mds_lvfs_ops;
 
         /* setup the directory tree */
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
         dentry = simple_mkdir(current->fs->pwd, mnt, "ROOT", 0755, 0);
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
@@ -649,8 +670,8 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
         if (rc)
                 GOTO(err_health_check, rc);
 err_pop:
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
+        pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
+        OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
         return rc;
 
 err_health_check:
@@ -678,9 +699,15 @@ err_fid:
 int mds_fs_cleanup(struct obd_device *obd)
 {
         struct mds_obd *mds = &obd->u.mds;
-        struct lvfs_run_ctxt saved;
+        struct lvfs_run_ctxt *saved = NULL;
         int rc = 0;
 
+        OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
+        if (saved == NULL) {
+                CERROR("cannot allocate memory for run ctxt\n");
+                RETURN(-ENOMEM);
+        }
+
         if (obd->obd_fail)
                 LCONSOLE_WARN("%s: shutting down for failover; client state "
                               "will be preserved.\n", obd->obd_name);
@@ -688,7 +715,7 @@ int mds_fs_cleanup(struct obd_device *obd)
         class_disconnect_exports(obd); /* cleans up client info too */
         mds_server_free_data(mds);
 
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        push_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
         if (mds->mds_rcvd_filp) {
                 rc = filp_close(mds->mds_rcvd_filp, 0);
                 mds->mds_rcvd_filp = NULL;
@@ -719,7 +746,8 @@ int mds_fs_cleanup(struct obd_device *obd)
 
         lquota_fs_cleanup(mds_quota_interface_ref, obd);
 
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+        pop_ctxt(saved, &obd->obd_lvfs_ctxt, NULL);
+        OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
         shrink_dcache_parent(mds->mds_fid_de);
         dput(mds->mds_fid_de);
         LL_DQUOT_OFF(obd->u.obt.obt_sb);
@@ -738,17 +766,23 @@ int mds_obd_create(struct obd_export *exp, struct obdo *oa,
         unsigned int tmpname = ll_rand();
         struct file *filp;
         struct dentry *new_child;
-        struct lvfs_run_ctxt saved;
+        struct lvfs_run_ctxt *saved = NULL;
         char fidname[LL_FID_NAMELEN];
         void *handle;
         struct lvfs_ucred ucred = { 0 };
         int rc = 0, err, namelen;
         ENTRY;
 
+        OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
+        if (saved == NULL) {
+                CERROR("cannot allocate memory for run ctxt\n");
+                RETURN(-ENOMEM);
+        }
+
         /* the owner of object file should always be root */
         cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE);
 
-        push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
+        push_ctxt(saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
 
         sprintf(fidname, "OBJECTS/%u.%u", tmpname, current->pid);
         filp = filp_open(fidname, O_CREAT | O_EXCL, 0666);
@@ -813,7 +847,8 @@ out_close:
                         rc = err;
         }
 out_pop:
-        pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
+        pop_ctxt(saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
+        OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
         RETURN(rc);
 }
 
@@ -824,7 +859,7 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
         struct mds_obd *mds = &exp->exp_obd->u.mds;
         struct inode *parent_inode = mds->mds_objects_dir->d_inode;
         struct obd_device *obd = exp->exp_obd;
-        struct lvfs_run_ctxt saved;
+        struct lvfs_run_ctxt *saved = NULL;
         struct lvfs_ucred ucred = { 0 };
         char fidname[LL_FID_NAMELEN];
         struct inode *inode = NULL;
@@ -833,8 +868,14 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
         int err, namelen, rc = 0;
         ENTRY;
 
+        OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
+        if (saved == NULL) {
+                CERROR("cannot allocate memory for run ctxt\n");
+                RETURN(-ENOMEM);
+        }
+
         cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE);
-        push_ctxt(&saved, &obd->obd_lvfs_ctxt, &ucred);
+        push_ctxt(saved, &obd->obd_lvfs_ctxt, &ucred);
 
         namelen = ll_fid2str(fidname, oa->o_id, oa->o_generation);
 
@@ -881,6 +922,7 @@ out_dput:
         if (inode)
                 iput(inode);
 
-        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &ucred);
+        pop_ctxt(saved, &obd->obd_lvfs_ctxt, &ucred);
+        OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
         RETURN(rc);
 }
diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c
index b0ea3d3718d5f6a53709675a7df4d92f72831057..4493250128ce202a04f62d67409c6cc6f6cd33f4 100644
--- a/lustre/obdclass/class_obd.c
+++ b/lustre/obdclass/class_obd.c
@@ -58,6 +58,7 @@ atomic_t libcfs_kmemory = {0};
 struct obd_device *obd_devs[MAX_OBD_DEVICES];
 struct list_head obd_types;
 spinlock_t obd_dev_lock = SPIN_LOCK_UNLOCKED;
+cfs_mem_cache_t *obd_lvfs_ctxt_cache;
 
 /* The following are visible and mutable through /proc/sys/lustre/. */
 unsigned int obd_debug_peer_on_timeout;
@@ -375,6 +376,7 @@ void *obd_psdev = NULL;
 #endif
 
 EXPORT_SYMBOL(obd_devs);
+EXPORT_SYMBOL(obd_lvfs_ctxt_cache);
 EXPORT_SYMBOL(obd_print_fail_loc);
 EXPORT_SYMBOL(obd_race_waitq);
 EXPORT_SYMBOL(obd_race_state);
@@ -548,6 +550,11 @@ int init_obdclass(void)
                              LPROCFS_CNTR_AVGMINMAX, 
                              "pagesused", "pages");
 #endif
+        obd_lvfs_ctxt_cache = cfs_mem_cache_create("obd_lvfs_ctxt_cache",
+                sizeof(struct lvfs_run_ctxt), 0, 0);
+        if (obd_lvfs_ctxt_cache == NULL)
+                RETURN(-ENOMEM);
+
         err = obd_init_checks();
         if (err == -EOVERFLOW)
                 return err;
@@ -630,6 +637,8 @@ static void cleanup_obdclass(void)
         memory_max = obd_memory_max();
         pages_max = obd_pages_max();
 
+        cfs_mem_cache_destroy(obd_lvfs_ctxt_cache);
+
         lprocfs_free_stats(&obd_memory);
         CDEBUG((memory_leaked | pages_leaked) ? D_ERROR : D_INFO,
                "obd_memory max: "LPU64", leaked: "LPU64" "
diff --git a/lustre/obdclass/llog_obd.c b/lustre/obdclass/llog_obd.c
index 7d371c25c4aa24eba849f2eb05590001b0c23d9c..638f1fdee181258a484280d7c8d9c218bf51a6e7 100644
--- a/lustre/obdclass/llog_obd.c
+++ b/lustre/obdclass/llog_obd.c
@@ -292,13 +292,17 @@ int llog_obd_origin_setup(struct obd_device *obd, int index,
 {
         struct llog_ctxt *ctxt;
         struct llog_handle *handle;
-        struct lvfs_run_ctxt saved;
+        struct lvfs_run_ctxt *saved = NULL;
         int rc;
         ENTRY;
 
         if (count == 0)
                 RETURN(0);
 
+        OBD_SLAB_ALLOC_PTR(saved, obd_lvfs_ctxt_cache);
+        if (saved == NULL)
+                RETURN(-ENOMEM);
+
         LASSERT(count == 1);
 
         ctxt = llog_get_context(obd, index);
@@ -316,9 +320,9 @@ int llog_obd_origin_setup(struct obd_device *obd, int index,
                 GOTO(out, rc);
 
         ctxt->loc_handle = handle;
-        push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
+        push_ctxt(saved, &disk_obd->obd_lvfs_ctxt, NULL);
         rc = llog_init_handle(handle, LLOG_F_IS_CAT, NULL);
-        pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
+        pop_ctxt(saved, &disk_obd->obd_lvfs_ctxt, NULL);
         if (rc)
                 GOTO(out, rc);
 
@@ -327,6 +331,7 @@ int llog_obd_origin_setup(struct obd_device *obd, int index,
                 CERROR("llog_process with cat_cancel_cb failed: %d\n", rc);
 out:
         llog_ctxt_put(ctxt);
+        OBD_SLAB_FREE_PTR(saved, obd_lvfs_ctxt_cache);
         RETURN(rc);
 }
 EXPORT_SYMBOL(llog_obd_origin_setup);