return rc;
}
+static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ struct obd_device *obd = data;
+ struct client_obd *cli = &obd->u.cli;
+ int rc;
+ __u64 val;
+
+ if (obd == NULL)
+ return 0;
+
+ rc = lprocfs_write_u64_helper(buffer, count, &val);
+ if (rc)
+ return rc;
+
+ /* this is only for shrinking grant */
+ client_obd_list_lock(&cli->cl_loi_list_lock);
+ if (val >= cli->cl_avail_grant) {
+ client_obd_list_unlock(&cli->cl_loi_list_lock);
+ return 0;
+ }
+ client_obd_list_unlock(&cli->cl_loi_list_lock);
+
+ LPROCFS_CLIMP_CHECK(obd);
+ if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
+ rc = osc_shrink_grant_to_target(cli, val);
+ LPROCFS_CLIMP_EXIT(obd);
+ if (rc)
+ return rc;
+ return count;
+}
+
+static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ struct obd_device *obd = data;
+
+ if (obd == NULL)
+ return 0;
+ return snprintf(page, count, "%d\n",
+ obd->u.cli.cl_grant_shrink_interval);
+}
+
+static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ struct obd_device *obd = data;
+ int val, rc;
+
+ if (obd == NULL)
+ return 0;
+
+ rc = lprocfs_write_helper(buffer, count, &val);
+ if (rc)
+ return rc;
+
+ if (val <= 0)
+ return -ERANGE;
+
+ obd->u.cli.cl_grant_shrink_interval = val;
+
+ return count;
+}
+
static int osc_rd_create_count(char *page, char **start, off_t off, int count,
int *eof, void *data)
{
osc_wr_max_rpcs_in_flight, 0 },
{ "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
{ "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
- { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
+ { "cur_grant_bytes", osc_rd_cur_grant_bytes,
+ osc_wr_cur_grant_bytes, 0 },
+ { "grant_shrink_interval", osc_rd_grant_shrink_interval,
+ osc_wr_grant_shrink_interval, 0 },
{ "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
{ "max_create_count", osc_rd_max_create_count,
osc_wr_max_create_count, 0},
RETURN(-ENOMEM);
body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
- lustre_set_wire_obdo(&body->oa, oinfo->oi_oa);
+ lustre_set_wire_obdo(&body->oa, oinfo->oi_oa);
ptlrpc_req_set_repsize(req, 2, size);
RETURN(-ENOMEM);
body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
- lustre_set_wire_obdo(&body->oa, oinfo->oi_oa);
+ lustre_set_wire_obdo(&body->oa, oinfo->oi_oa);
ptlrpc_req_set_repsize(req, 2, size);
if (body == NULL)
GOTO(out, rc = -EPROTO);
- lustre_get_wire_obdo(oinfo->oi_oa, &body->oa);
+ lustre_get_wire_obdo(oinfo->oi_oa, &body->oa);
EXIT;
out:
GOTO(out, rc = -EPROTO);
}
- lustre_get_wire_obdo(aa->aa_oi->oi_oa, &body->oa);
+ lustre_get_wire_obdo(aa->aa_oi->oi_oa, &body->oa);
out:
rc = aa->aa_oi->oi_cb_up(aa->aa_oi, rc);
RETURN(rc);
oinfo->oi_oa->o_lcookie = *oti->oti_logcookies;
}
- lustre_set_wire_obdo(&body->oa, oinfo->oi_oa);
+ lustre_set_wire_obdo(&body->oa, oinfo->oi_oa);
ptlrpc_req_set_repsize(req, 2, size);
/* do mds to ost setattr asynchronouly */
if (!rqset) {
GOTO(out, rc = -ENOMEM);
body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
- lustre_set_wire_obdo(&body->oa, oa);
+ lustre_set_wire_obdo(&body->oa, oa);
ptlrpc_req_set_repsize(req, 2, size);
if ((oa->o_valid & OBD_MD_FLFLAGS) &&
GOTO (out_req, rc = -EPROTO);
}
- lustre_get_wire_obdo(oa, &body->oa);
+ lustre_get_wire_obdo(oa, &body->oa);
/* This should really be sent by the OST */
oa->o_blksize = PTLRPC_MAX_BRW_SIZE;
GOTO(out, rc = -EPROTO);
}
- lustre_get_wire_obdo(aa->aa_oi->oi_oa, &body->oa);
+ lustre_get_wire_obdo(aa->aa_oi->oi_oa, &body->oa);
out:
rc = aa->aa_oi->oi_cb_up(aa->aa_oi, rc);
RETURN(rc);
static void osc_update_next_shrink(struct client_obd *cli)
{
- int time = GRANT_SHRINK_INTERVAL;
- cli->cl_next_shrink_grant = cfs_time_shift(time);
+ cli->cl_next_shrink_grant =
+ cfs_time_shift(cli->cl_grant_shrink_interval);
CDEBUG(D_CACHE, "next time %ld to shrink grant \n",
cli->cl_next_shrink_grant);
}
struct client_obd *cli = &req->rq_import->imp_obd->u.cli;
struct obdo *oa = aa->aa_oa;
struct ost_body *body;
-
+
if (rc != 0) {
client_obd_list_lock(&cli->cl_loi_list_lock);
cli->cl_avail_grant += oa->o_grant;
osc_update_grant(cli, body);
out:
OBD_FREE_PTR(oa);
- return rc;
+ return rc;
}
static void osc_shrink_grant_local(struct client_obd *cli, struct obdo *oa)
{
client_obd_list_lock(&cli->cl_loi_list_lock);
oa->o_grant = cli->cl_avail_grant / 4;
- cli->cl_avail_grant -= oa->o_grant;
+ cli->cl_avail_grant -= oa->o_grant;
client_obd_list_unlock(&cli->cl_loi_list_lock);
oa->o_flags |= OBD_FL_SHRINK_GRANT;
osc_update_next_shrink(cli);
}
+/* Shrink the current grant, either from some large amount to enough for a
+ * full set of in-flight RPCs, or if we have already shrunk to that limit
+ * then to enough for a single RPC. This avoids keeping more grant than
+ * needed, and avoids shrinking the grant piecemeal. */
static int osc_shrink_grant(struct client_obd *cli)
{
+ long target = (cli->cl_max_rpcs_in_flight + 1) *
+ cli->cl_max_pages_per_rpc;
+
+ client_obd_list_lock(&cli->cl_loi_list_lock);
+ if (cli->cl_avail_grant <= target)
+ target = cli->cl_max_pages_per_rpc;
+ client_obd_list_unlock(&cli->cl_loi_list_lock);
+
+ return osc_shrink_grant_to_target(cli, target);
+}
+
+int osc_shrink_grant_to_target(struct client_obd *cli, long target)
+{
int rc = 0;
struct ost_body *body;
ENTRY;
+ client_obd_list_lock(&cli->cl_loi_list_lock);
+ /* Don't shrink if we are already above or below the desired limit
+ * We don't want to shrink below a single RPC, as that will negatively
+ * impact block allocation and long-term performance. */
+ if (target < cli->cl_max_pages_per_rpc)
+ target = cli->cl_max_pages_per_rpc;
+
+ if (target >= cli->cl_avail_grant) {
+ client_obd_list_unlock(&cli->cl_loi_list_lock);
+ RETURN(0);
+ }
+ client_obd_list_unlock(&cli->cl_loi_list_lock);
+
OBD_ALLOC_PTR(body);
if (!body)
RETURN(-ENOMEM);
osc_announce_cached(cli, &body->oa, 0);
- osc_shrink_grant_local(cli, &body->oa);
+
+ client_obd_list_lock(&cli->cl_loi_list_lock);
+ body->oa.o_grant = cli->cl_avail_grant - target;
+ cli->cl_avail_grant = target;
+ client_obd_list_unlock(&cli->cl_loi_list_lock);
+ body->oa.o_flags |= OBD_FL_SHRINK_GRANT;
+ osc_update_next_shrink(cli);
+
rc = osc_set_info_async(cli->cl_import->imp_obd->obd_self_export,
sizeof(KEY_GRANT_SHRINK), KEY_GRANT_SHRINK,
sizeof(*body), body, NULL);
cli->cl_avail_grant += body->oa.o_grant;
client_obd_list_unlock(&cli->cl_loi_list_lock);
}
- if (body)
- OBD_FREE_PTR(body);
+ OBD_FREE_PTR(body);
RETURN(rc);
}
{
int rc;
- rc = ptlrpc_add_timeout_client(GRANT_SHRINK_INTERVAL,
- TIMEOUT_GRANT,
- osc_grant_shrink_grant_cb, NULL,
- &client->cl_grant_shrink_list);
+ rc = ptlrpc_add_timeout_client(client->cl_grant_shrink_interval,
+ TIMEOUT_GRANT,
+ osc_grant_shrink_grant_cb, NULL,
+ &client->cl_grant_shrink_list);
if (rc) {
- CERROR("add grant client %s error %d\n",
+ CERROR("add grant client %s error %d\n",
client->cl_import->imp_obd->obd_name, rc);
return rc;
}
- CDEBUG(D_CACHE, "add grant client %s \n",
+ CDEBUG(D_CACHE, "add grant client %s \n",
client->cl_import->imp_obd->obd_name);
osc_update_next_shrink(client);
- return 0;
+ return 0;
}
static int osc_del_shrink_grant(struct client_obd *client)
{
- return ptlrpc_del_timeout_client(&client->cl_grant_shrink_list,
+ return ptlrpc_del_timeout_client(&client->cl_grant_shrink_list,
TIMEOUT_GRANT);
}
osc_announce_cached(cli, &body->oa, opc == OST_WRITE ? requested_nob:0);
if (osc_should_shrink_grant(cli))
- osc_shrink_grant_local(cli, &body->oa);
+ osc_shrink_grant_local(cli, &body->oa);
/* size[REQ_REC_OFF] still sizeof (*body) */
if (opc == OST_WRITE) {
if (copy == NULL)
GOTO(out, rc = -ENOMEM);
memcpy(copy, ppga, pages_per_brw * sizeof(*copy));
-
+
OBDO_ALLOC(oa);
if (oa == NULL) {
OBD_FREE(copy, pages_per_brw * sizeof(*copy));
obd_count i;
for (i = 0; i < aa->aa_page_count; i++)
osc_release_write_grant(aa->aa_cli, aa->aa_ppga[i], 1);
-
+
if (aa->aa_oa->o_flags & OBD_FL_TEMPORARY)
OBDO_FREE(aa->aa_oa);
}
#if defined(__KERNEL__) && defined(__linux__)
if(!(PageLocked(oap->oap_page) &&
(CheckWriteback(oap->oap_page, cmd) || oap->oap_oig !=NULL))) {
- CDEBUG(D_PAGE, "page %p lost wb %lx/%x\n",
+ CDEBUG(D_PAGE, "page %p lost wb %lx/%x\n",
oap->oap_page, (long)oap->oap_page->flags, oap->oap_async_flags);
LBUG();
}
*stripe = 0;
RETURN(0);
} else if (KEY_IS(KEY_OFF_RPCSIZE)) {
- struct client_obd *cli = &exp->exp_obd->u.cli;
- __u64 *rpcsize = val;
- LASSERT(*vallen == sizeof(__u64));
- *rpcsize = (__u64)cli->cl_max_pages_per_rpc;
- RETURN(0);
- } else if (KEY_IS(KEY_LAST_ID)) {
+ struct client_obd *cli = &exp->exp_obd->u.cli;
+ __u64 *rpcsize = val;
+ LASSERT(*vallen == sizeof(__u64));
+ *rpcsize = (__u64)cli->cl_max_pages_per_rpc;
+ RETURN(0);
+ } else if (KEY_IS(KEY_LAST_ID)) {
struct ptlrpc_request *req;
obd_id *reply;
char *bufs[2] = { NULL, key };
}
*oa = ((struct ost_body *)val)->oa;
aa->aa_oa = oa;
-
+
size[1] = vallen;
ptlrpc_req_set_repsize(req, 2, size);
ptlrpcd_add_req(req);
* causes the following problem if setup (connect) and cleanup
* (disconnect) are tangled together.
* connect p1 disconnect p2
- * ptlrpc_connect_import
+ * ptlrpc_connect_import
* ............... class_manual_cleanup
* osc_disconnect
* del_shrink_grant
* ptlrpc_connect_interrupt
* init_grant_shrink
- * add this client to shrink list
+ * add this client to shrink list
* cleanup_osc
* Bang! pinger trigger the shrink.
* So the osc should be disconnected from the shrink list, after we
- * are sure the import has been destroyed. BUG18662
+ * are sure the import has been destroyed. BUG18662
*/
if (obd->u.cli.cl_import == NULL)
osc_del_shrink_grant(&obd->u.cli);
struct lprocfs_static_vars lvars = { 0 };
struct client_obd *cli = &obd->u.cli;
+ cli->cl_grant_shrink_interval = GRANT_SHRINK_INTERVAL;
lprocfs_osc_init_vars(&lvars);
if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0) {
lproc_osc_attach_seqstat(obd);