From 3ce365a8ce605229a7e51e6acc31b0d037bf4b0f Mon Sep 17 00:00:00 2001 From: pravin Date: Mon, 30 Aug 2010 14:57:47 +0530 Subject: [PATCH] b=21128 ldlm_cancel_lru fixes for stack overflow v4 and handle PF_MEMALLOC i=oleg i=rahul avoid stack overflow by delegating work to separate thread --- lustre/ldlm/ldlm_internal.h | 2 +- lustre/ldlm/ldlm_lockd.c | 97 ++++++++++++++++++++++++++++++++++----------- lustre/ldlm/ldlm_request.c | 18 ++++----- 3 files changed, 82 insertions(+), 35 deletions(-) diff --git a/lustre/ldlm/ldlm_internal.h b/lustre/ldlm/ldlm_internal.h index d02852b..015d09a 100644 --- a/lustre/ldlm/ldlm_internal.h +++ b/lustre/ldlm/ldlm_internal.h @@ -134,7 +134,7 @@ void ldlm_cancel_locks_for_export(struct obd_export *export); int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld, struct ldlm_lock *lock); int ldlm_bl_to_thread_list(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld, - struct list_head *cancels, int count); + struct list_head *cancels, int count, int mode); void ldlm_handle_bl_callback(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld, struct ldlm_lock *lock); diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index 8f992e8..5837075 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -133,6 +133,9 @@ struct ldlm_bl_work_item { struct ldlm_lock *blwi_lock; struct list_head blwi_head; int blwi_count; + struct completion blwi_comp; + int blwi_mode; + int blwi_mem_pressure; }; #ifdef __KERNEL__ @@ -1580,22 +1583,46 @@ static int ldlm_callback_reply(struct ptlrpc_request *req, int rc) } #ifdef __KERNEL__ -static int ldlm_bl_to_thread(struct ldlm_namespace *ns, - struct ldlm_lock_desc *ld, struct ldlm_lock *lock, - struct list_head *cancels, int count) +static int __ldlm_bl_to_thread(struct ldlm_bl_work_item *blwi, int mode) { struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool; - struct ldlm_bl_work_item *blwi; ENTRY; - if (cancels && count == 0) - RETURN(0); + spin_lock(&blp->blp_lock); + if (blwi->blwi_lock && blwi->blwi_lock->l_flags & LDLM_FL_DISCARD_DATA) { + /* add LDLM_FL_DISCARD_DATA requests to the priority list */ + list_add_tail(&blwi->blwi_entry, &blp->blp_prio_list); + } else { + /* other blocking callbacks are added to the regular list */ + list_add_tail(&blwi->blwi_entry, &blp->blp_list); + } + spin_unlock(&blp->blp_lock); - OBD_ALLOC(blwi, sizeof(*blwi)); - if (blwi == NULL) - RETURN(-ENOMEM); + cfs_waitq_signal(&blp->blp_waitq); + + /* can not use blwi->blwi_mode as blwi could be already freed in + LDLM_ASYNC mode */ + if (mode == LDLM_SYNC) + wait_for_completion(&blwi->blwi_comp); + + RETURN(0); +} + +static inline void init_blwi(struct ldlm_bl_work_item *blwi, + struct ldlm_namespace *ns, + struct ldlm_lock_desc *ld, + struct list_head *cancels, int count, + struct ldlm_lock *lock, + int mode) +{ + init_completion(&blwi->blwi_comp); + INIT_LIST_HEAD(&blwi->blwi_head); + + if (libcfs_memory_pressure_get()) + blwi->blwi_mem_pressure = 1; blwi->blwi_ns = ns; + blwi->blwi_mode = mode; if (ld != NULL) blwi->blwi_ld = *ld; if (count) { @@ -1605,18 +1632,34 @@ static int ldlm_bl_to_thread(struct ldlm_namespace *ns, } else { blwi->blwi_lock = lock; } - spin_lock(&blp->blp_lock); - if (lock && lock->l_flags & LDLM_FL_DISCARD_DATA) { - /* add LDLM_FL_DISCARD_DATA requests to the priority list */ - list_add_tail(&blwi->blwi_entry, &blp->blp_prio_list); +} + +static int ldlm_bl_to_thread(struct ldlm_namespace *ns, + struct ldlm_lock_desc *ld, struct ldlm_lock *lock, + struct list_head *cancels, int count, int mode) +{ + ENTRY; + + if (cancels && count == 0) + RETURN(0); + + if (mode == LDLM_SYNC) { + /* if it is synchronous call do minimum mem alloc, as it could + * be triggered from kernel shrinker + */ + struct ldlm_bl_work_item blwi; + memset(&blwi, 0, sizeof(blwi)); + init_blwi(&blwi, ns, ld, cancels, count, lock, LDLM_SYNC); + RETURN(__ldlm_bl_to_thread(&blwi, LDLM_SYNC)); } else { - /* other blocking callbacks are added to the regular list */ - list_add_tail(&blwi->blwi_entry, &blp->blp_list); - } - cfs_waitq_signal(&blp->blp_waitq); - spin_unlock(&blp->blp_lock); + struct ldlm_bl_work_item *blwi; + OBD_ALLOC(blwi, sizeof(*blwi)); + if (blwi == NULL) + RETURN(-ENOMEM); + init_blwi(blwi, ns, ld, cancels, count, lock, LDLM_ASYNC); - RETURN(0); + RETURN(__ldlm_bl_to_thread(blwi, LDLM_ASYNC)); + } } #endif @@ -1624,17 +1667,17 @@ int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld, struct ldlm_lock *lock) { #ifdef __KERNEL__ - RETURN(ldlm_bl_to_thread(ns, ld, lock, NULL, 0)); + RETURN(ldlm_bl_to_thread(ns, ld, lock, NULL, 0, LDLM_ASYNC)); #else RETURN(-ENOSYS); #endif } int ldlm_bl_to_thread_list(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld, - struct list_head *cancels, int count) + struct list_head *cancels, int count, int mode) { #ifdef __KERNEL__ - RETURN(ldlm_bl_to_thread(ns, ld, NULL, cancels, count)); + RETURN(ldlm_bl_to_thread(ns, ld, NULL, cancels, count, mode)); #else RETURN(-ENOSYS); #endif @@ -1967,6 +2010,8 @@ static int ldlm_bl_thread_main(void *arg) /* added by ldlm_cleanup() */ break; } + if (blwi->blwi_mem_pressure) + libcfs_memory_pressure_set(); if (blwi->blwi_count) { /* The special case when we cancel locks in lru @@ -1979,7 +2024,13 @@ static int ldlm_bl_thread_main(void *arg) ldlm_handle_bl_callback(blwi->blwi_ns, &blwi->blwi_ld, blwi->blwi_lock); } - OBD_FREE(blwi, sizeof(*blwi)); + if (blwi->blwi_mem_pressure) + libcfs_memory_pressure_clr(); + + if (blwi->blwi_mode == LDLM_ASYNC) + OBD_FREE(blwi, sizeof(*blwi)); + else + complete(&blwi->blwi_comp); } atomic_dec(&blp->blp_busy_threads); diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c index aec74e2..4cc1cb8 100644 --- a/lustre/ldlm/ldlm_request.c +++ b/lustre/ldlm/ldlm_request.c @@ -1466,7 +1466,7 @@ int ldlm_cancel_lru_local(struct ldlm_namespace *ns, struct list_head *cancels, * in a thread and this function will return after the thread has been * asked to call the callback. when called with LDLM_SYNC the blocking * callback will be performed in this function. */ -int ldlm_cancel_lru(struct ldlm_namespace *ns, int nr, ldlm_sync_t sync, +int ldlm_cancel_lru(struct ldlm_namespace *ns, int nr, ldlm_sync_t mode, int flags) { CFS_LIST_HEAD(cancels); @@ -1474,19 +1474,15 @@ int ldlm_cancel_lru(struct ldlm_namespace *ns, int nr, ldlm_sync_t sync, ENTRY; #ifndef __KERNEL__ - sync = LDLM_SYNC; /* force to be sync in user space */ + mode = LDLM_SYNC; /* force to be sync in user space */ #endif count = ldlm_cancel_lru_local(ns, &cancels, nr, 0, 0, flags); - if (sync == LDLM_ASYNC) { - rc = ldlm_bl_to_thread_list(ns, NULL, &cancels, count); - if (rc == 0) - RETURN(count); - } - /* If an error occured in ASYNC mode, or this is SYNC mode, - * cancel the list. */ - ldlm_cli_cancel_list(&cancels, count, NULL, 0); - RETURN(count); + rc = ldlm_bl_to_thread_list(ns, NULL, &cancels, count, mode); + if (rc == 0) + RETURN(count); + + RETURN(0); } /* Find and cancel locally unused locks found on resource, matched to the -- 1.8.3.1