Whamcloud - gitweb
LU-3416 llite: reset writeback index in ll_writepages
[fs/lustre-release.git] / lustre / osc / osc_cache.c
index 581beb6..7711496 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  *
  */
 /*
@@ -99,22 +99,23 @@ static inline char list_empty_marker(cfs_list_t *list)
 
 #define EXTSTR       "[%lu -> %lu/%lu]"
 #define EXTPARA(ext) (ext)->oe_start, (ext)->oe_end, (ext)->oe_max_end
+static const char *oes_strings[] = {
+       "inv", "active", "cache", "locking", "lockdone", "rpc", "trunc", NULL };
 
 #define OSC_EXTENT_DUMP(lvl, extent, fmt, ...) do {                          \
        struct osc_extent *__ext = (extent);                                  \
-       const char *__str[] = OES_STRINGS;                                    \
        char __buf[16];                                                       \
                                                                              \
        CDEBUG(lvl,                                                           \
                "extent %p@{" EXTSTR ", "                                     \
                "[%d|%d|%c|%s|%s|%p], [%d|%d|%c|%c|%p|%u|%p]} " fmt,          \
-               /* ----- extent part 0 ----- */                               \
+               /* ----- extent part 0 ----- */                               \
                __ext, EXTPARA(__ext),                                        \
                /* ----- part 1 ----- */                                      \
                cfs_atomic_read(&__ext->oe_refc),                             \
                cfs_atomic_read(&__ext->oe_users),                            \
                list_empty_marker(&__ext->oe_link),                           \
-               __str[__ext->oe_state], ext_flags(__ext, __buf),              \
+               oes_strings[__ext->oe_state], ext_flags(__ext, __buf),        \
                __ext->oe_obj,                                                \
                /* ----- part 2 ----- */                                      \
                __ext->oe_grants, __ext->oe_nr_pages,                         \
@@ -128,10 +129,10 @@ static inline char list_empty_marker(cfs_list_t *list)
 #undef EASSERTF
 #define EASSERTF(expr, ext, fmt, args...) do {                         \
        if (!(expr)) {                                                  \
-               OSC_EXTENT_DUMP(D_ERROR, (ext), fmt, ##args);            \
-               osc_extent_tree_dump(D_ERROR, (ext)->oe_obj);            \
+               OSC_EXTENT_DUMP(D_ERROR, (ext), fmt, ##args);           \
+               osc_extent_tree_dump(D_ERROR, (ext)->oe_obj);           \
                LASSERT(expr);                                          \
-       }                                                                    \
+       }                                                               \
 } while (0)
 
 #undef EASSERT
@@ -1307,15 +1308,19 @@ static int osc_completion(const struct lu_env *env, struct osc_async_page *oap,
        RETURN(0);
 }
 
-#define OSC_DUMP_GRANT(cli, fmt, args...) do {                               \
+#define OSC_DUMP_GRANT(lvl, cli, fmt, args...) do {                          \
        struct client_obd *__tmp = (cli);                                     \
-       CDEBUG(D_CACHE, "%s: { dirty: %ld/%ld dirty_pages: %d/%d "            \
-              "dropped: %ld avail: %ld, reserved: %ld, flight: %d } " fmt,   \
+       CDEBUG(lvl, "%s: grant { dirty: %ld/%ld dirty_pages: %d/%d "          \
+              "dropped: %ld avail: %ld, reserved: %ld, flight: %d } "        \
+              "lru {in list: %d, left: %d, waiters: %d }" fmt,               \
               __tmp->cl_import->imp_obd->obd_name,                           \
               __tmp->cl_dirty, __tmp->cl_dirty_max,                          \
               cfs_atomic_read(&obd_dirty_pages), obd_max_dirty_pages,        \
               __tmp->cl_lost_grant, __tmp->cl_avail_grant,                   \
-              __tmp->cl_reserved_grant, __tmp->cl_w_in_flight, ##args);      \
+              __tmp->cl_reserved_grant, __tmp->cl_w_in_flight,               \
+              cfs_atomic_read(&__tmp->cl_lru_in_list),                       \
+              cfs_atomic_read(&__tmp->cl_lru_busy),                          \
+              cfs_atomic_read(&__tmp->cl_lru_shrinkers), ##args);            \
 } while (0)
 
 /* caller must hold loi_list_lock */
@@ -1456,7 +1461,7 @@ static int osc_enter_cache_try(struct client_obd *cli,
 {
        int rc;
 
-       OSC_DUMP_GRANT(cli, "need:%d.\n", bytes);
+       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d.\n", bytes);
 
        rc = osc_reserve_grant(cli, bytes);
        if (rc < 0)
@@ -1482,7 +1487,7 @@ static int ocw_granted(struct client_obd *cli, struct osc_cache_waiter *ocw)
 {
        int rc;
        client_obd_list_lock(&cli->cl_loi_list_lock);
-       rc = cfs_list_empty(&ocw->ocw_entry) || cli->cl_w_in_flight == 0;
+       rc = cfs_list_empty(&ocw->ocw_entry);
        client_obd_list_unlock(&cli->cl_loi_list_lock);
        return rc;
 }
@@ -1500,11 +1505,12 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
        struct osc_object *osc = oap->oap_obj;
        struct lov_oinfo  *loi = osc->oo_oinfo;
        struct osc_cache_waiter ocw;
-       struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
+       struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(600), NULL,
+                                                 LWI_ON_SIGNAL_NOOP, NULL);
        int rc = -EDQUOT;
        ENTRY;
 
-       OSC_DUMP_GRANT(cli, "need:%d.\n", bytes);
+       OSC_DUMP_GRANT(D_CACHE, cli, "need:%d.\n", bytes);
 
        client_obd_list_lock(&cli->cl_loi_list_lock);
 
@@ -1528,7 +1534,7 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
        cfs_waitq_init(&ocw.ocw_waitq);
        ocw.ocw_oap   = oap;
        ocw.ocw_grant = bytes;
-       if (cli->cl_dirty > 0 || cli->cl_w_in_flight > 0) {
+       while (cli->cl_dirty > 0 || cli->cl_w_in_flight > 0) {
                cfs_list_add_tail(&ocw.ocw_entry, &cli->cl_cache_waiters);
                ocw.ocw_rc = 0;
                client_obd_list_unlock(&cli->cl_loi_list_lock);
@@ -1542,31 +1548,31 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
 
                client_obd_list_lock(&cli->cl_loi_list_lock);
 
-               /* l_wait_event is interrupted by signal */
+               /* l_wait_event is interrupted by signal, or timed out */
                if (rc < 0) {
+                       if (rc == -ETIMEDOUT) {
+                               OSC_DUMP_GRANT(D_ERROR, cli,
+                                               "try to reserve %d.\n", bytes);
+                               osc_extent_tree_dump(D_ERROR, osc);
+                               rc = -EDQUOT;
+                       }
+
                        cfs_list_del_init(&ocw.ocw_entry);
                        GOTO(out, rc);
                }
 
-               /* If ocw_entry isn't empty, which means it's not waked up
-                * by osc_wake_cache_waiters(), then the page must not be
-                * granted yet. */
-               if (!cfs_list_empty(&ocw.ocw_entry)) {
-                       rc = -EDQUOT;
-                       cfs_list_del_init(&ocw.ocw_entry);
-               } else {
-                       rc = ocw.ocw_rc;
-               }
+               LASSERT(cfs_list_empty(&ocw.ocw_entry));
+               rc = ocw.ocw_rc;
 
                if (rc != -EDQUOT)
                        GOTO(out, rc);
                if (osc_enter_cache_try(cli, oap, bytes, 0))
-                       rc = 0;
+                       GOTO(out, rc = 0);
        }
        EXIT;
 out:
        client_obd_list_unlock(&cli->cl_loi_list_lock);
-       OSC_DUMP_GRANT(cli, "returned %d.\n", rc);
+       OSC_DUMP_GRANT(D_CACHE, cli, "returned %d.\n", rc);
        RETURN(rc);
 }
 
@@ -1578,31 +1584,25 @@ void osc_wake_cache_waiters(struct client_obd *cli)
 
        ENTRY;
        cfs_list_for_each_safe(l, tmp, &cli->cl_cache_waiters) {
-               /* if we can't dirty more, we must wait until some is written */
+               ocw = cfs_list_entry(l, struct osc_cache_waiter, ocw_entry);
+               cfs_list_del_init(&ocw->ocw_entry);
+
+               ocw->ocw_rc = -EDQUOT;
+               /* we can't dirty more */
                if ((cli->cl_dirty + CFS_PAGE_SIZE > cli->cl_dirty_max) ||
                    (cfs_atomic_read(&obd_dirty_pages) + 1 >
                     obd_max_dirty_pages)) {
                        CDEBUG(D_CACHE, "no dirty room: dirty: %ld "
                               "osc max %ld, sys max %d\n", cli->cl_dirty,
                               cli->cl_dirty_max, obd_max_dirty_pages);
-                       return;
-               }
-
-               /* if still dirty cache but no grant wait for pending RPCs that
-                * may yet return us some grant before doing sync writes */
-               if (cli->cl_w_in_flight && cli->cl_avail_grant < CFS_PAGE_SIZE) {
-                       CDEBUG(D_CACHE, "%u BRW writes in flight, no grant\n",
-                              cli->cl_w_in_flight);
-                       return;
+                       goto wakeup;
                }
 
-               ocw = cfs_list_entry(l, struct osc_cache_waiter, ocw_entry);
-               cfs_list_del_init(&ocw->ocw_entry);
-
                ocw->ocw_rc = 0;
                if (!osc_enter_cache_try(cli, ocw->ocw_oap, ocw->ocw_grant, 0))
                        ocw->ocw_rc = -EDQUOT;
 
+wakeup:
                CDEBUG(D_CACHE, "wake up %p for oap %p, avail grant %ld, %d\n",
                       ocw, ocw->ocw_oap, cli->cl_avail_grant, ocw->ocw_rc);
 
@@ -2137,23 +2137,24 @@ static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli,
 static int osc_io_unplug0(const struct lu_env *env, struct client_obd *cli,
                          struct osc_object *osc, pdl_policy_t pol, int async)
 {
-       int has_rpcs = 1;
        int rc = 0;
 
-       client_obd_list_lock(&cli->cl_loi_list_lock);
-       if (osc != NULL)
-               has_rpcs = __osc_list_maint(cli, osc);
-       if (has_rpcs) {
-               if (!async) {
-                       osc_check_rpcs(env, cli, pol);
-               } else {
-                       CDEBUG(D_CACHE, "Queue writeback work for client %p.\n",
-                              cli);
-                       LASSERT(cli->cl_writeback_work != NULL);
-                       rc = ptlrpcd_queue_work(cli->cl_writeback_work);
-               }
+       if (osc != NULL && osc_list_maint(cli, osc) == 0)
+               return 0;
+
+       if (!async) {
+               /* disable osc_lru_shrink() temporarily to avoid
+                * potential stack overrun problem. LU-2859 */
+               cfs_atomic_inc(&cli->cl_lru_shrinkers);
+               client_obd_list_lock(&cli->cl_loi_list_lock);
+               osc_check_rpcs(env, cli, pol);
+               client_obd_list_unlock(&cli->cl_loi_list_lock);
+               cfs_atomic_dec(&cli->cl_lru_shrinkers);
+       } else {
+               CDEBUG(D_CACHE, "Queue writeback work for client %p.\n", cli);
+               LASSERT(cli->cl_writeback_work != NULL);
+               rc = ptlrpcd_queue_work(cli->cl_writeback_work);
        }
-       client_obd_list_unlock(&cli->cl_loi_list_lock);
        return rc;
 }
 
@@ -2709,7 +2710,7 @@ again:
                 * should take care of it. */
                rc = osc_extent_wait(env, waiting, OES_INV);
                if (rc < 0)
-                       OSC_EXTENT_DUMP(D_CACHE, ext, "wait error: %d.\n", rc);
+                       OSC_EXTENT_DUMP(D_CACHE, waiting, "error: %d.\n", rc);
 
                osc_extent_put(env, waiting);
                waiting = NULL;
@@ -2919,7 +2920,7 @@ int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj,
                        result = rc;
        }
 
-       OSC_IO_DEBUG(obj, "cache page out.\n");
+       OSC_IO_DEBUG(obj, "pageout [%lu, %lu], %d.\n", start, end, result);
        RETURN(result);
 }