<div dir="ltr"><div class="gmail_default" style="font-size:small">I dislike a sleep in this code.</div><div class="gmail_default" style="font-size:small">I think you should use req->rq_sent time to have a some delay, as way as osc redo code does.</div><div class="gmail_default" style="font-size:small">ptlrpc_check_set()</div><div class="gmail_default" style="font-size:small">..</div><div class="gmail_default" style="font-size:small">







<p class="gmail-p1"><span class="gmail-s1">                /* delayed send - skip */</span></p>
<p class="gmail-p1"><span class="gmail-s1">                if (req->rq_phase == RQ_PHASE_NEW && req->rq_sent)</span></p>
<p class="gmail-p1"><span class="gmail-s1">                        continue;</span></p><p class="gmail-p1"><span class="gmail-s1"><br></span></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 21, 2017 at 10:43 PM, Yan Li <span dir="ltr"><<a href="mailto:yanli@ascar.io" target="_blank">yanli@ascar.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Yan Li <<a href="mailto:yanli@ascar.io">yanli@ascar.io</a>><br>
---<br>
 lustre/osc/osc_cache.c    |  3 +++<br>
 lustre/osc/osc_internal.h | 66 ++++++++++++++++++++++++++++++<wbr>+++++++++++++++++<br>
 2 files changed, 69 insertions(+)<br>
<br>
diff --git a/lustre/osc/osc_cache.c b/lustre/osc/osc_cache.c<br>
index 236263c..2f9d4e1 100644<br>
--- a/lustre/osc/osc_cache.c<br>
+++ b/lustre/osc/osc_cache.c<br>
@@ -2316,6 +2316,9 @@ static int osc_io_unplug0(const struct lu_env *env, struct client_obd *cli,<br>
        } else {<br>
                CDEBUG(D_CACHE, "Queue writeback work for client %p.\n", cli);<br>
                LASSERT(cli->cl_writeback_work != NULL);<br>
+#ifdef ENABLE_RLQOS<br>
+               qos_throttle(&cli->qos);<br>
+#endif<br>
                rc = ptlrpcd_queue_work(cli->cl_<wbr>writeback_work);<br>
        }<br>
        return rc;<br>
diff --git a/lustre/osc/osc_internal.h b/lustre/osc/osc_internal.h<br>
index 06c21b3..d31d5ba 100644<br>
--- a/lustre/osc/osc_internal.h<br>
+++ b/lustre/osc/osc_internal.h<br>
@@ -245,4 +245,70 @@ extern unsigned long osc_cache_shrink_count(struct shrinker *sk,<br>
 extern unsigned long osc_cache_shrink_scan(struct shrinker *sk,<br>
                                           struct shrink_control *sc);<br>
<br>
+#ifdef ENABLE_RLQOS<br>
+static inline void qos_throttle(struct qos_data_t *qos)<br>
+{<br>
+       struct timeval now;<br>
+       long           usec_since_last_rpc;<br>
+       long           need_sleep_usec = 0;<br>
+<br>
+       spin_lock(&qos->lock);<br>
+       if (0 == qos->min_usec_between_rpcs)<br>
+               goto out;<br>
+<br>
+       do_gettimeofday(&now);<br>
+       usec_since_last_rpc = cfs_timeval_sub(&now, &qos->last_rpc_time, NULL);<br>
+       if (usec_since_last_rpc < 0) {<br>
+               usec_since_last_rpc = 0;<br>
+       }<br>
+       if (usec_since_last_rpc < qos->min_usec_between_rpcs) {<br>
+               need_sleep_usec = qos->min_usec_between_rpcs - usec_since_last_rpc;<br>
+       }<br>
+       qos->last_rpc_time = now;<br>
+out:<br>
+       spin_unlock(&qos->lock);<br>
+       if (0 == need_sleep_usec) {<br>
+               return;<br>
+       }<br>
+<br>
+       /* About timer ranges:<br>
+          Ref: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__www.kernel.org_doc_Documentation_timers_timers-2Dhowto.txt&d=DwICAg&c=IGDlg0lD0b-nebmJJ0Kp8A&r=m8P9AM2wTf4l79yg9e1LHD5IHagtwa3P4AXaemlM6Lg&m=w0oijGmz2ea38--CHGZq4fPu44dwEldJr2BDVZcBR2U&s=jN5WjVQ8jELL9iEXADWoal4-Yo76FIU3VVDcdN3zsC4&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.<wbr>com/v2/url?u=https-3A__www.<wbr>kernel.org_doc_Documentation_<wbr>timers_timers-2Dhowto.txt&d=<wbr>DwICAg&c=IGDlg0lD0b-<wbr>nebmJJ0Kp8A&r=<wbr>m8P9AM2wTf4l79yg9e1LHD5IHagtwa<wbr>3P4AXaemlM6Lg&m=w0oijGmz2ea38-<wbr>-CHGZq4fPu44dwEldJr2BDVZcBR2U&<wbr>s=jN5WjVQ8jELL9iEXADWoal4-<wbr>Yo76FIU3VVDcdN3zsC4&e=</a>  */<br>
+       if (need_sleep_usec < 1000) {<br>
+               udelay(need_sleep_usec);<br>
+       } else if (need_sleep_usec < 20000) {<br>
+               usleep_range(need_sleep_usec - 1, need_sleep_usec);<br>
+       } else {<br>
+               msleep(need_sleep_usec / 1000);<br>
+       }<br>
+}<br>
+#endif /* ENABLE_RLQOS */<br>
+<br>
+/* You must call LPROCFS_CLIMP_CHECK() on the obd device before and<br>
+ * LPROCFS_CLIMP_EXIT() after calling this function. They are not called inside<br>
+ * this function, because they may return an error code.<br>
+ */<br>
+static inline void set_max_rpcs_in_flight(int val, struct client_obd *cli)<br>
+{<br>
+       int adding, added, req_count;<br>
+<br>
+       adding = val - cli->cl_max_rpcs_in_flight;<br>
+       req_count = atomic_read(&osc_pool_req_<wbr>count);<br>
+       if (adding > 0 && req_count < osc_reqpool_maxreqcount) {<br>
+               /*<br>
+                * There might be some race which will cause over-limit<br>
+                * allocation, but it is fine.<br>
+                */<br>
+               if (req_count + adding > osc_reqpool_maxreqcount)<br>
+                       adding = osc_reqpool_maxreqcount - req_count;<br>
+<br>
+               added = osc_rq_pool->prp_populate(osc_<wbr>rq_pool, adding);<br>
+               atomic_add(added, &osc_pool_req_count);<br>
+       }<br>
+<br>
+       spin_lock(&cli->cl_loi_list_<wbr>lock);<br>
+       cli->cl_max_rpcs_in_flight = val;<br>
+       client_adjust_max_dirty(cli);<br>
+       spin_unlock(&cli->cl_loi_list_<wbr>lock);<br>
+}<br>
+<br>
 #endif /* OSC_INTERNAL_H */<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<br>
<br>
______________________________<wbr>_________________<br>
lustre-devel mailing list<br>
<a href="mailto:lustre-devel@lists.lustre.org">lustre-devel@lists.lustre.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.lustre.org_listinfo.cgi_lustre-2Ddevel-2Dlustre.org&d=DwICAg&c=IGDlg0lD0b-nebmJJ0Kp8A&r=m8P9AM2wTf4l79yg9e1LHD5IHagtwa3P4AXaemlM6Lg&m=w0oijGmz2ea38--CHGZq4fPu44dwEldJr2BDVZcBR2U&s=ppAA2u9phKTaqwpnFsNVQGtqbG3xF6tk4_Q9mVL_lGk&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.<wbr>com/v2/url?u=http-3A__lists.<wbr>lustre.org_listinfo.cgi_<wbr>lustre-2Ddevel-2Dlustre.org&d=<wbr>DwICAg&c=IGDlg0lD0b-<wbr>nebmJJ0Kp8A&r=<wbr>m8P9AM2wTf4l79yg9e1LHD5IHagtwa<wbr>3P4AXaemlM6Lg&m=w0oijGmz2ea38-<wbr>-CHGZq4fPu44dwEldJr2BDVZcBR2U&<wbr>s=<wbr>ppAA2u9phKTaqwpnFsNVQGtqbG3xF6<wbr>tk4_Q9mVL_lGk&e=</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Alexey Lyashkov <strong>·</strong> Technical lead for a Morpheus team<br>
Seagate Technology, LLC<br>
<a href="http://www.seagate.com" target="_blank">www.seagate.com</a><br><div><a href="http://www.lustre.org" target="_blank">www.lustre.org</a></div></div></div>
</div>