4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2013, Intel Corporation.
25 * Copyright 2012 Xyratex Technology Limited
28 * lustre/ptlrpc/nrs_orr.c
30 * Network Request Scheduler (NRS) ORR and TRR policies
32 * Request scheduling in a Round-Robin manner over backend-fs objects and OSTs
35 * Author: Liang Zhen <liang@whamcloud.com>
36 * Author: Nikitas Angelinas <nikitas_angelinas@xyratex.com>
38 #ifdef HAVE_SERVER_SUPPORT
44 #define DEBUG_SUBSYSTEM S_RPC
45 #include <obd_support.h>
46 #include <obd_class.h>
47 #include <lustre_net.h>
48 #include <lustre/lustre_idl.h>
49 #include <lustre_req_layout.h>
50 #include "ptlrpc_internal.h"
53 * \name ORR/TRR policy
55 * ORR/TRR (Object-based Round Robin/Target-based Round Robin) NRS policies
57 * ORR performs batched Round Robin shceduling of brw RPCs, based on the FID of
58 * the backend-fs object that the brw RPC pertains to; the TRR policy performs
59 * batched Round Robin scheduling of brw RPCs, based on the OST index that the
60 * RPC pertains to. Both policies also order RPCs in each batch in ascending
61 * offset order, which is lprocfs-tunable between logical file offsets, and
62 * physical disk offsets, as reported by fiemap.
64 * The TRR policy reuses much of the functionality of ORR. These two scheduling
65 * algorithms could alternatively be implemented under a single NRS policy, that
66 * uses an lprocfs tunable in order to switch between the two types of
67 * scheduling behaviour. The two algorithms have been implemented as separate
68 * policies for reasons of clarity to the user, and to avoid issues that would
69 * otherwise arise at the point of switching between behaviours in the case of
70 * having a single policy, such as resource cleanup for nrs_orr_object
71 * instances. It is possible that this may need to be re-examined in the future,
72 * along with potentially coalescing other policies that perform batched request
73 * scheduling in a Round-Robin manner, all into one policy.
78 #define NRS_POL_NAME_ORR "orr"
79 #define NRS_POL_NAME_TRR "trr"
82 * Checks if the RPC type of \a nrq is currently handled by an ORR/TRR policy
84 * \param[in] orrd the ORR/TRR policy scheduler instance
85 * \param[in] nrq the request
86 * \param[out] opcode the opcode is saved here, just in order to avoid calling
87 * lustre_msg_get_opc() again later
89 * \retval true request type is supported by the policy instance
90 * \retval false request type is not supported by the policy instance
92 static bool nrs_orr_req_supported(struct nrs_orr_data *orrd,
93 struct ptlrpc_nrs_request *nrq, __u32 *opcode)
95 struct ptlrpc_request *req = container_of(nrq, struct ptlrpc_request,
97 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
101 * XXX: nrs_orr_data::od_supp accessed unlocked.
105 rc = orrd->od_supp & NOS_OST_READ;
108 rc = orrd->od_supp & NOS_OST_WRITE;
119 * Returns the ORR/TRR key fields for the request \a nrq in \a key.
121 * \param[in] orrd the ORR/TRR policy scheduler instance
122 * \param[in] nrq the request
123 * \param[in] opc the request's opcode
124 * \param[in] name the policy name
125 * \param[out] key fields of the key are returned here.
127 * \retval 0 key filled successfully
130 static int nrs_orr_key_fill(struct nrs_orr_data *orrd,
131 struct ptlrpc_nrs_request *nrq, __u32 opc,
132 char *name, struct nrs_orr_key *key)
134 struct ptlrpc_request *req = container_of(nrq, struct ptlrpc_request,
136 struct ost_body *body;
138 bool is_orr = strncmp(name, NRS_POL_NAME_ORR,
139 NRS_POL_NAME_MAX) == 0;
141 LASSERT(req != NULL);
144 * This is an attempt to fill in the request key fields while
145 * moving a request from the regular to the high-priority NRS
146 * head (via ldlm_lock_reorder_req()), but the request key has
147 * been adequately filled when nrs_orr_res_get() was called through
148 * ptlrpc_nrs_req_initialize() for the regular NRS head's ORR/TRR
149 * policy, so there is nothing to do.
151 if ((is_orr && nrq->nr_u.orr.or_orr_set) ||
152 (!is_orr && nrq->nr_u.orr.or_trr_set)) {
153 *key = nrq->nr_u.orr.or_key;
157 if (nrq->nr_u.orr.or_orr_set || nrq->nr_u.orr.or_trr_set)
158 memset(&nrq->nr_u.orr.or_key, 0, sizeof(nrq->nr_u.orr.or_key));
160 ost_idx = class_server_data(req->rq_export->exp_obd)->lsd_osd_index;
165 * The request pill for OST_READ and OST_WRITE requests is
166 * initialized in the ost_io service's
167 * ptlrpc_service_ops::so_hpreq_handler, ost_io_hpreq_handler(),
168 * so no need to redo it here.
170 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
174 rc = ostid_to_fid(&key->ok_fid, &body->oa.o_oi, ost_idx);
178 nrq->nr_u.orr.or_orr_set = 1;
180 key->ok_idx = ost_idx;
181 nrq->nr_u.orr.or_trr_set = 1;
188 * Populates the range values in \a range with logical offsets obtained via
191 * \param[in] nb niobuf_remote struct array for this request
192 * \param[in] niocount count of niobuf_remote structs for this request
193 * \param[out] range the offset range is returned here
195 static void nrs_orr_range_fill_logical(struct niobuf_remote *nb, int niocount,
196 struct nrs_orr_req_range *range)
198 /* Should we do this at page boundaries ? */
199 range->or_start = nb[0].offset & CFS_PAGE_MASK;
200 range->or_end = (nb[niocount - 1].offset +
201 nb[niocount - 1].len - 1) | ~CFS_PAGE_MASK;
205 * We obtain information just for a single extent, as the request can only be in
206 * a single place in the binary heap anyway.
208 #define ORR_NUM_EXTENTS 1
211 * Converts the logical file offset range in \a range, to a physical disk offset
212 * range in \a range, for a request. Uses obd_get_info() in order to carry out a
213 * fiemap call and obtain backend-fs extent information. The returned range is
214 * in physical block numbers.
216 * \param[in] nrq the request
217 * \param[in] oa obdo struct for this request
218 * \param[in,out] range the offset range in bytes; logical range in, physical
221 * \retval 0 physical offsets obtained successfully
224 static int nrs_orr_range_fill_physical(struct ptlrpc_nrs_request *nrq,
226 struct nrs_orr_req_range *range)
228 struct ptlrpc_request *req = container_of(nrq,
229 struct ptlrpc_request,
231 char fiemap_buf[offsetof(struct ll_user_fiemap,
232 fm_extents[ORR_NUM_EXTENTS])];
233 struct ll_user_fiemap *fiemap = (struct ll_user_fiemap *)fiemap_buf;
234 struct ll_fiemap_info_key key;
239 key = (typeof(key)) {
243 .fm_start = range->or_start,
244 .fm_length = range->or_end - range->or_start,
245 .fm_extent_count = ORR_NUM_EXTENTS
249 rc = obd_get_info(req->rq_svc_thread->t_env, req->rq_export,
250 sizeof(key), &key, NULL, fiemap, NULL);
254 if (fiemap->fm_mapped_extents == 0 ||
255 fiemap->fm_mapped_extents > ORR_NUM_EXTENTS)
256 GOTO(out, rc = -EFAULT);
259 * Calculate the physical offset ranges for the request from the extent
260 * information and the logical request offsets.
262 start = fiemap->fm_extents[0].fe_physical + range->or_start -
263 fiemap->fm_extents[0].fe_logical;
264 end = start + range->or_end - range->or_start;
266 range->or_start = start;
269 nrq->nr_u.orr.or_physical_set = 1;
275 * Sets the offset range the request covers; either in logical file
276 * offsets or in physical disk offsets.
278 * \param[in] nrq the request
279 * \param[in] orrd the ORR/TRR policy scheduler instance
280 * \param[in] opc the request's opcode
281 * \param[in] moving_req is the request in the process of moving onto the
282 * high-priority NRS head?
284 * \retval 0 range filled successfully
287 static int nrs_orr_range_fill(struct ptlrpc_nrs_request *nrq,
288 struct nrs_orr_data *orrd, __u32 opc,
291 struct ptlrpc_request *req = container_of(nrq,
292 struct ptlrpc_request,
294 struct obd_ioobj *ioo;
295 struct niobuf_remote *nb;
296 struct ost_body *body;
297 struct nrs_orr_req_range range;
302 * If we are scheduling using physical disk offsets, but we have filled
303 * the offset information in the request previously
304 * (i.e. ldlm_lock_reorder_req() is moving the request to the
305 * high-priority NRS head), there is no need to do anything, and we can
306 * exit. Moreover than the lack of need, we would be unable to perform
307 * the obd_get_info() call required in nrs_orr_range_fill_physical(),
308 * because ldlm_lock_reorder_lock() calls into here while holding a
309 * spinlock, and retrieving fiemap information via obd_get_info() is a
310 * potentially sleeping operation.
312 if (orrd->od_physical && nrq->nr_u.orr.or_physical_set)
315 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
317 GOTO(out, rc = -EFAULT);
319 niocount = ioo->ioo_bufcnt;
321 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
323 GOTO(out, rc = -EFAULT);
326 * Use logical information from niobuf_remote structures.
328 nrs_orr_range_fill_logical(nb, niocount, &range);
331 * Obtain physical offsets if selected, and this is an OST_READ RPC
332 * RPC. We do not enter this block if moving_req is set which indicates
333 * that the request is being moved to the high-priority NRS head by
334 * ldlm_lock_reorder_req(), as that function calls in here while holding
335 * a spinlock, and nrs_orr_range_physical() can sleep, so we just use
336 * logical file offsets for the range values for such requests.
338 if (orrd->od_physical && opc == OST_READ && !moving_req) {
339 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
341 GOTO(out, rc = -EFAULT);
344 * Translate to physical block offsets from backend filesystem
346 * Ignore return values; if obtaining the physical offsets
347 * fails, use the logical offsets.
349 nrs_orr_range_fill_physical(nrq, &body->oa, &range);
352 nrq->nr_u.orr.or_range = range;
358 * Generates a character string that can be used in order to register uniquely
359 * named libcfs_hash and slab objects for ORR/TRR policy instances. The
360 * character string is unique per policy instance, as it includes the policy's
361 * name, the CPT number, and a {reg|hp} token, and there is one policy instance
362 * per NRS head on each CPT, and the policy is only compatible with the ost_io
365 * \param[in] policy the policy instance
366 * \param[out] name the character array that will hold the generated name
368 static void nrs_orr_genobjname(struct ptlrpc_nrs_policy *policy, char *name)
370 snprintf(name, NRS_ORR_OBJ_NAME_MAX, "%s%s%s%d",
371 "nrs_", policy->pol_desc->pd_name,
372 policy->pol_nrs->nrs_queue_type == PTLRPC_NRS_QUEUE_REG ?
373 "_reg_" : "_hp_", nrs_pol2cptid(policy));
377 * ORR/TRR hash operations
379 #define NRS_ORR_BITS 24
380 #define NRS_ORR_BKT_BITS 12
381 #define NRS_ORR_HASH_FLAGS (CFS_HASH_RW_BKTLOCK | CFS_HASH_ASSERT_EMPTY)
383 #define NRS_TRR_BITS 4
384 #define NRS_TRR_BKT_BITS 2
385 #define NRS_TRR_HASH_FLAGS CFS_HASH_RW_BKTLOCK
387 static unsigned nrs_orr_hop_hash(cfs_hash_t *hs, const void *key, unsigned mask)
389 return cfs_hash_djb2_hash(key, sizeof(struct nrs_orr_key), mask);
392 static void *nrs_orr_hop_key(cfs_hlist_node_t *hnode)
394 struct nrs_orr_object *orro = cfs_hlist_entry(hnode,
395 struct nrs_orr_object,
397 return &orro->oo_key;
400 static int nrs_orr_hop_keycmp(const void *key, cfs_hlist_node_t *hnode)
402 struct nrs_orr_object *orro = cfs_hlist_entry(hnode,
403 struct nrs_orr_object,
406 return lu_fid_eq(&orro->oo_key.ok_fid,
407 &((struct nrs_orr_key *)key)->ok_fid);
410 static void *nrs_orr_hop_object(cfs_hlist_node_t *hnode)
412 return cfs_hlist_entry(hnode, struct nrs_orr_object, oo_hnode);
415 static void nrs_orr_hop_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
417 struct nrs_orr_object *orro = cfs_hlist_entry(hnode,
418 struct nrs_orr_object,
420 cfs_atomic_inc(&orro->oo_ref);
424 * Removes an nrs_orr_object the hash and frees its memory, if the object has
427 static void nrs_orr_hop_put_free(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
429 struct nrs_orr_object *orro = cfs_hlist_entry(hnode,
430 struct nrs_orr_object,
432 struct nrs_orr_data *orrd = container_of(orro->oo_res.res_parent,
433 struct nrs_orr_data, od_res);
434 cfs_hash_bd_t bds[2];
436 if (cfs_atomic_dec_return(&orro->oo_ref) > 1)
439 cfs_hash_lock(hs, 0);
440 cfs_hash_dual_bd_get_and_lock(hs, &orro->oo_key, bds, 1);
443 * Another thread may have won the race and taken a reference on the
446 if (cfs_atomic_read(&orro->oo_ref) > 1)
449 if (bds[1].bd_bucket == NULL)
450 cfs_hash_bd_del_locked(hs, &bds[0], hnode);
452 hnode = cfs_hash_dual_bd_finddel_locked(hs, bds, &orro->oo_key,
454 LASSERT(hnode != NULL);
456 OBD_SLAB_FREE_PTR(orro, orrd->od_cache);
460 cfs_hash_dual_bd_unlock(hs, bds, 1);
461 cfs_hash_unlock(hs, 0);
464 static void nrs_orr_hop_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
466 struct nrs_orr_object *orro = cfs_hlist_entry(hnode,
467 struct nrs_orr_object,
469 cfs_atomic_dec(&orro->oo_ref);
472 static int nrs_trr_hop_keycmp(const void *key, cfs_hlist_node_t *hnode)
474 struct nrs_orr_object *orro = cfs_hlist_entry(hnode,
475 struct nrs_orr_object,
478 return orro->oo_key.ok_idx == ((struct nrs_orr_key *)key)->ok_idx;
481 static void nrs_trr_hop_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
483 struct nrs_orr_object *orro = cfs_hlist_entry(hnode,
484 struct nrs_orr_object,
486 struct nrs_orr_data *orrd = container_of(orro->oo_res.res_parent,
487 struct nrs_orr_data, od_res);
489 LASSERTF(cfs_atomic_read(&orro->oo_ref) == 0,
490 "Busy NRS TRR policy object for OST with index %u, with %d "
491 "refs\n", orro->oo_key.ok_idx, cfs_atomic_read(&orro->oo_ref));
493 OBD_SLAB_FREE_PTR(orro, orrd->od_cache);
496 static cfs_hash_ops_t nrs_orr_hash_ops = {
497 .hs_hash = nrs_orr_hop_hash,
498 .hs_key = nrs_orr_hop_key,
499 .hs_keycmp = nrs_orr_hop_keycmp,
500 .hs_object = nrs_orr_hop_object,
501 .hs_get = nrs_orr_hop_get,
502 .hs_put = nrs_orr_hop_put_free,
503 .hs_put_locked = nrs_orr_hop_put,
506 static cfs_hash_ops_t nrs_trr_hash_ops = {
507 .hs_hash = nrs_orr_hop_hash,
508 .hs_key = nrs_orr_hop_key,
509 .hs_keycmp = nrs_trr_hop_keycmp,
510 .hs_object = nrs_orr_hop_object,
511 .hs_get = nrs_orr_hop_get,
512 .hs_put = nrs_orr_hop_put,
513 .hs_put_locked = nrs_orr_hop_put,
514 .hs_exit = nrs_trr_hop_exit,
517 #define NRS_ORR_QUANTUM_DFLT 256
520 * Binary heap predicate.
523 * ptlrpc_nrs_request::nr_u::orr::or_round,
524 * ptlrpc_nrs_request::nr_u::orr::or_sequence, and
525 * ptlrpc_nrs_request::nr_u::orr::or_range to compare two binheap nodes and
526 * produce a binary predicate that indicates their relative priority, so that
527 * the binary heap can perform the necessary sorting operations.
529 * \param[in] e1 the first binheap node to compare
530 * \param[in] e2 the second binheap node to compare
535 static int orr_req_compare(cfs_binheap_node_t *e1, cfs_binheap_node_t *e2)
537 struct ptlrpc_nrs_request *nrq1;
538 struct ptlrpc_nrs_request *nrq2;
540 nrq1 = container_of(e1, struct ptlrpc_nrs_request, nr_node);
541 nrq2 = container_of(e2, struct ptlrpc_nrs_request, nr_node);
544 * Requests have been scheduled against a different scheduling round.
546 if (nrq1->nr_u.orr.or_round < nrq2->nr_u.orr.or_round)
548 else if (nrq1->nr_u.orr.or_round > nrq2->nr_u.orr.or_round)
552 * Requests have been scheduled against the same scheduling round, but
553 * belong to a different batch, i.e. they pertain to a different
554 * backend-fs object (for ORR policy instances) or OST (for TRR policy
557 if (nrq1->nr_u.orr.or_sequence < nrq2->nr_u.crr.cr_sequence)
559 else if (nrq1->nr_u.orr.or_sequence > nrq2->nr_u.crr.cr_sequence)
563 * If round numbers and sequence numbers are equal, the two requests
564 * have been scheduled on the same round, and belong to the same batch,
565 * which means they pertain to the same backend-fs object (if this is an
566 * ORR policy instance), or to the same OST (if this is a TRR policy
567 * instance), so these requests should be sorted by ascending offset
570 if (nrq1->nr_u.orr.or_range.or_start <
571 nrq2->nr_u.orr.or_range.or_start) {
573 } else if (nrq1->nr_u.orr.or_range.or_start >
574 nrq2->nr_u.orr.or_range.or_start) {
578 * Requests start from the same offset; Dispatch the shorter one
579 * first; perhaps slightly more chances of hitting caches like
582 return nrq1->nr_u.orr.or_range.or_end <
583 nrq2->nr_u.orr.or_range.or_end;
588 * ORR binary heap operations
590 static cfs_binheap_ops_t nrs_orr_heap_ops = {
593 .hop_compare = orr_req_compare,
597 * Prints a warning message if an ORR/TRR policy is started on a service with
598 * more than one CPT. Not printed on the console for now, since we don't
599 * have any performance metrics in the first place, and it is annoying.
601 * \param[in] policy the policy instance
605 static int nrs_orr_init(struct ptlrpc_nrs_policy *policy)
607 if (policy->pol_nrs->nrs_svcpt->scp_service->srv_ncpts > 1)
608 CDEBUG(D_CONFIG, "%s: The %s NRS policy was registered on a "
609 "service with multiple service partitions. This policy "
610 "may perform better with a single partition.\n",
611 policy->pol_nrs->nrs_svcpt->scp_service->srv_name,
612 policy->pol_desc->pd_name);
618 * Called when an ORR policy instance is started.
620 * \param[in] policy the policy
622 * \retval -ENOMEM OOM error
625 static int nrs_orr_start(struct ptlrpc_nrs_policy *policy)
627 struct nrs_orr_data *orrd;
636 OBD_CPT_ALLOC_PTR(orrd, nrs_pol2cptab(policy), nrs_pol2cptid(policy));
641 * Binary heap instance for sorted incoming requests.
643 orrd->od_binheap = cfs_binheap_create(&nrs_orr_heap_ops,
644 CBH_FLAG_ATOMIC_GROW, 4096, NULL,
645 nrs_pol2cptab(policy),
646 nrs_pol2cptid(policy));
647 if (orrd->od_binheap == NULL)
648 GOTO(failed, rc = -ENOMEM);
650 nrs_orr_genobjname(policy, orrd->od_objname);
653 * Slab cache for NRS ORR/TRR objects.
655 orrd->od_cache = kmem_cache_create(orrd->od_objname,
656 sizeof(struct nrs_orr_object),
658 if (orrd->od_cache == NULL)
659 GOTO(failed, rc = -ENOMEM);
661 if (strncmp(policy->pol_desc->pd_name, NRS_POL_NAME_ORR,
662 NRS_POL_NAME_MAX) == 0) {
663 ops = &nrs_orr_hash_ops;
664 cur_bits = NRS_ORR_BITS;
665 max_bits = NRS_ORR_BITS;
666 bkt_bits = NRS_ORR_BKT_BITS;
667 flags = NRS_ORR_HASH_FLAGS;
669 ops = &nrs_trr_hash_ops;
670 cur_bits = NRS_TRR_BITS;
671 max_bits = NRS_TRR_BITS;
672 bkt_bits = NRS_TRR_BKT_BITS;
673 flags = NRS_TRR_HASH_FLAGS;
677 * Hash for finding objects by struct nrs_orr_key.
678 * XXX: For TRR, it might be better to avoid using libcfs_hash?
679 * All that needs to be resolved are OST indices, and they
680 * will stay relatively stable during an OSS node's lifetime.
682 orrd->od_obj_hash = cfs_hash_create(orrd->od_objname, cur_bits,
683 max_bits, bkt_bits, 0,
685 CFS_HASH_MAX_THETA, ops, flags);
686 if (orrd->od_obj_hash == NULL)
687 GOTO(failed, rc = -ENOMEM);
689 /* XXX: Fields accessed unlocked */
690 orrd->od_quantum = NRS_ORR_QUANTUM_DFLT;
691 orrd->od_supp = NOS_DFLT;
692 orrd->od_physical = true;
694 * Set to 1 so that the test inside nrs_orr_req_add() can evaluate to
697 orrd->od_sequence = 1;
699 policy->pol_private = orrd;
704 if (orrd->od_cache) {
705 kmem_cache_destroy(orrd->od_cache);
706 LASSERTF(rc == 0, "Could not destroy od_cache slab\n");
708 if (orrd->od_binheap != NULL)
709 cfs_binheap_destroy(orrd->od_binheap);
717 * Called when an ORR/TRR policy instance is stopped.
719 * Called when the policy has been instructed to transition to the
720 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state and has no more
721 * pending requests to serve.
723 * \param[in] policy the policy
725 static void nrs_orr_stop(struct ptlrpc_nrs_policy *policy)
727 struct nrs_orr_data *orrd = policy->pol_private;
730 LASSERT(orrd != NULL);
731 LASSERT(orrd->od_binheap != NULL);
732 LASSERT(orrd->od_obj_hash != NULL);
733 LASSERT(orrd->od_cache != NULL);
734 LASSERT(cfs_binheap_is_empty(orrd->od_binheap));
736 cfs_binheap_destroy(orrd->od_binheap);
737 cfs_hash_putref(orrd->od_obj_hash);
738 kmem_cache_destroy(orrd->od_cache);
744 * Performs a policy-specific ctl function on ORR/TRR policy instances; similar
747 * \param[in] policy the policy instance
748 * \param[in] opc the opcode
749 * \param[in,out] arg used for passing parameters and information
751 * \pre spin_is_locked(&policy->pol_nrs->->nrs_lock)
752 * \post spin_is_locked(&policy->pol_nrs->->nrs_lock)
754 * \retval 0 operation carried successfully
757 int nrs_orr_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc,
760 LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock));
762 switch((enum nrs_ctl_orr)opc) {
766 case NRS_CTL_ORR_RD_QUANTUM: {
767 struct nrs_orr_data *orrd = policy->pol_private;
769 *(__u16 *)arg = orrd->od_quantum;
773 case NRS_CTL_ORR_WR_QUANTUM: {
774 struct nrs_orr_data *orrd = policy->pol_private;
776 orrd->od_quantum = *(__u16 *)arg;
777 LASSERT(orrd->od_quantum != 0);
781 case NRS_CTL_ORR_RD_OFF_TYPE: {
782 struct nrs_orr_data *orrd = policy->pol_private;
784 *(bool *)arg = orrd->od_physical;
788 case NRS_CTL_ORR_WR_OFF_TYPE: {
789 struct nrs_orr_data *orrd = policy->pol_private;
791 orrd->od_physical = *(bool *)arg;
795 case NRS_CTL_ORR_RD_SUPP_REQ: {
796 struct nrs_orr_data *orrd = policy->pol_private;
798 *(enum nrs_orr_supp *)arg = orrd->od_supp;
802 case NRS_CTL_ORR_WR_SUPP_REQ: {
803 struct nrs_orr_data *orrd = policy->pol_private;
805 orrd->od_supp = *(enum nrs_orr_supp *)arg;
806 LASSERT((orrd->od_supp & NOS_OST_RW) != 0);
814 * Obtains resources for ORR/TRR policy instances. The top-level resource lives
815 * inside \e nrs_orr_data and the second-level resource inside
816 * \e nrs_orr_object instances.
818 * \param[in] policy the policy for which resources are being taken for
820 * \param[in] nrq the request for which resources are being taken
821 * \param[in] parent parent resource, embedded in nrs_orr_data for the
823 * \param[out] resp used to return resource references
824 * \param[in] moving_req signifies limited caller context; used to perform
825 * memory allocations in an atomic context in this
828 * \retval 0 we are returning a top-level, parent resource, one that is
829 * embedded in an nrs_orr_data object
830 * \retval 1 we are returning a bottom-level resource, one that is embedded
831 * in an nrs_orr_object object
833 * \see nrs_resource_get_safe()
835 int nrs_orr_res_get(struct ptlrpc_nrs_policy *policy,
836 struct ptlrpc_nrs_request *nrq,
837 const struct ptlrpc_nrs_resource *parent,
838 struct ptlrpc_nrs_resource **resp, bool moving_req)
840 struct nrs_orr_data *orrd;
841 struct nrs_orr_object *orro;
842 struct nrs_orr_object *tmp;
843 struct nrs_orr_key key = { { { 0 } } };
848 * struct nrs_orr_data is requested.
850 if (parent == NULL) {
851 *resp = &((struct nrs_orr_data *)policy->pol_private)->od_res;
855 orrd = container_of(parent, struct nrs_orr_data, od_res);
858 * If the request type is not supported, fail the enqueuing; the RPC
859 * will be handled by the fallback NRS policy.
861 if (!nrs_orr_req_supported(orrd, nrq, &opc))
865 * Fill in the key for the request; OST FID for ORR policy instances,
866 * and OST index for TRR policy instances.
868 rc = nrs_orr_key_fill(orrd, nrq, opc, policy->pol_desc->pd_name, &key);
873 * Set the offset range the request covers
875 rc = nrs_orr_range_fill(nrq, orrd, opc, moving_req);
879 orro = cfs_hash_lookup(orrd->od_obj_hash, &key);
883 OBD_SLAB_CPT_ALLOC_PTR_GFP(orro, orrd->od_cache,
884 nrs_pol2cptab(policy), nrs_pol2cptid(policy),
885 (moving_req ? GFP_ATOMIC :
891 cfs_atomic_set(&orro->oo_ref, 1);
893 tmp = cfs_hash_findadd_unique(orrd->od_obj_hash, &orro->oo_key,
896 OBD_SLAB_FREE_PTR(orro, orrd->od_cache);
901 * For debugging purposes
903 nrq->nr_u.orr.or_key = orro->oo_key;
905 *resp = &orro->oo_res;
911 * Called when releasing references to the resource hierachy obtained for a
912 * request for scheduling using ORR/TRR policy instances
914 * \param[in] policy the policy the resource belongs to
915 * \param[in] res the resource to be released
917 static void nrs_orr_res_put(struct ptlrpc_nrs_policy *policy,
918 const struct ptlrpc_nrs_resource *res)
920 struct nrs_orr_data *orrd;
921 struct nrs_orr_object *orro;
924 * Do nothing for freeing parent, nrs_orr_data resources.
926 if (res->res_parent == NULL)
929 orro = container_of(res, struct nrs_orr_object, oo_res);
930 orrd = container_of(res->res_parent, struct nrs_orr_data, od_res);
932 cfs_hash_put(orrd->od_obj_hash, &orro->oo_hnode);
936 * Called when polling an ORR/TRR policy instance for a request so that it can
937 * be served. Returns the request that is at the root of the binary heap, as
938 * that is the lowest priority one (i.e. libcfs_heap is an implementation of a
941 * \param[in] policy the policy instance being polled
942 * \param[in] peek when set, signifies that we just want to examine the
943 * request, and not handle it, so the request is not removed
945 * \param[in] force force the policy to return a request; unused in this policy
947 * \retval the request to be handled
948 * \retval NULL no request available
950 * \see ptlrpc_nrs_req_get_nolock()
951 * \see nrs_request_get()
954 struct ptlrpc_nrs_request *nrs_orr_req_get(struct ptlrpc_nrs_policy *policy,
955 bool peek, bool force)
957 struct nrs_orr_data *orrd = policy->pol_private;
958 cfs_binheap_node_t *node = cfs_binheap_root(orrd->od_binheap);
959 struct ptlrpc_nrs_request *nrq;
961 nrq = unlikely(node == NULL) ? NULL :
962 container_of(node, struct ptlrpc_nrs_request, nr_node);
964 if (likely(!peek && nrq != NULL)) {
965 struct nrs_orr_object *orro;
967 orro = container_of(nrs_request_resource(nrq),
968 struct nrs_orr_object, oo_res);
970 LASSERT(nrq->nr_u.orr.or_round <= orro->oo_round);
972 cfs_binheap_remove(orrd->od_binheap, &nrq->nr_node);
975 if (strncmp(policy->pol_desc->pd_name, NRS_POL_NAME_ORR,
976 NRS_POL_NAME_MAX) == 0)
978 "NRS: starting to handle %s request for object "
979 "with FID "DFID", from OST with index %u, with "
980 "round "LPU64"\n", NRS_POL_NAME_ORR,
981 PFID(&orro->oo_key.ok_fid),
982 nrq->nr_u.orr.or_key.ok_idx,
983 nrq->nr_u.orr.or_round);
986 "NRS: starting to handle %s request from OST "
987 "with index %u, with round "LPU64"\n",
988 NRS_POL_NAME_TRR, nrq->nr_u.orr.or_key.ok_idx,
989 nrq->nr_u.orr.or_round);
991 /** Peek at the next request to be served */
992 node = cfs_binheap_root(orrd->od_binheap);
994 /** No more requests */
995 if (unlikely(node == NULL)) {
998 struct ptlrpc_nrs_request *next;
1000 next = container_of(node, struct ptlrpc_nrs_request,
1003 if (orrd->od_round < next->nr_u.orr.or_round)
1004 orrd->od_round = next->nr_u.orr.or_round;
1012 * Sort-adds request \a nrq to an ORR/TRR \a policy instance's set of queued
1013 * requests in the policy's binary heap.
1015 * A scheduling round is a stream of requests that have been sorted in batches
1016 * according to the backend-fs object (for ORR policy instances) or OST (for TRR
1017 * policy instances) that they pertain to (as identified by its IDIF FID or OST
1018 * index respectively); there can be only one batch for each object or OST in
1019 * each round. The batches are of maximum size nrs_orr_data:od_quantum. When a
1020 * new request arrives for scheduling for an object or OST that has exhausted
1021 * its quantum in its current round, the request will be scheduled on the next
1022 * scheduling round. Requests are allowed to be scheduled against a round until
1023 * all requests for the round are serviced, so an object or OST might miss a
1024 * round if requests are not scheduled for it for a long enough period of time.
1025 * Objects or OSTs that miss a round will continue with having their next
1026 * request scheduled, starting at the round that requests are being dispatched
1027 * for, at the time of arrival of this request.
1029 * Requests are tagged with the round number and a sequence number; the sequence
1030 * number indicates the relative ordering amongst the batches of requests in a
1031 * round, and is identical for all requests in a batch, as is the round number.
1032 * The round and sequence numbers are used by orr_req_compare() in order to use
1033 * nrs_orr_data::od_binheap in order to maintain an ordered set of rounds, with
1034 * each round consisting of an ordered set of batches of requests, and each
1035 * batch consisting of an ordered set of requests according to their logical
1036 * file or physical disk offsets.
1038 * \param[in] policy the policy
1039 * \param[in] nrq the request to add
1041 * \retval 0 request successfully added
1042 * \retval != 0 error
1044 static int nrs_orr_req_add(struct ptlrpc_nrs_policy *policy,
1045 struct ptlrpc_nrs_request *nrq)
1047 struct nrs_orr_data *orrd;
1048 struct nrs_orr_object *orro;
1051 orro = container_of(nrs_request_resource(nrq),
1052 struct nrs_orr_object, oo_res);
1053 orrd = container_of(nrs_request_resource(nrq)->res_parent,
1054 struct nrs_orr_data, od_res);
1056 if (orro->oo_quantum == 0 || orro->oo_round < orrd->od_round ||
1057 (orro->oo_active == 0 && orro->oo_quantum > 0)) {
1060 * If there are no pending requests for the object/OST, but some
1061 * of its quantum still remains unused, which implies we did not
1062 * get a chance to schedule up to its maximum allowed batch size
1063 * of requests in the previous round this object/OST
1064 * participated in, schedule this next request on a new round;
1065 * this avoids fragmentation of request batches caused by
1066 * intermittent inactivity on the object/OST, at the expense of
1067 * potentially slightly increased service time for the request
1068 * batch this request will be a part of.
1070 if (orro->oo_active == 0 && orro->oo_quantum > 0)
1073 /** A new scheduling round has commenced */
1074 if (orro->oo_round < orrd->od_round)
1075 orro->oo_round = orrd->od_round;
1077 /** I was not the last object/OST that scheduled a request */
1078 if (orro->oo_sequence < orrd->od_sequence)
1079 orro->oo_sequence = ++orrd->od_sequence;
1081 * Reset the quantum if we have reached the maximum quantum
1082 * size for this batch, or even if we have not managed to
1083 * complete a batch size up to its maximum allowed size.
1084 * XXX: Accessed unlocked
1086 orro->oo_quantum = orrd->od_quantum;
1089 nrq->nr_u.crr.cr_round = orro->oo_round;
1090 nrq->nr_u.crr.cr_sequence = orro->oo_sequence;
1092 rc = cfs_binheap_insert(orrd->od_binheap, &nrq->nr_node);
1095 if (--orro->oo_quantum == 0)
1102 * Removes request \a nrq from an ORR/TRR \a policy instance's set of queued
1105 * \param[in] policy the policy
1106 * \param[in] nrq the request to remove
1108 static void nrs_orr_req_del(struct ptlrpc_nrs_policy *policy,
1109 struct ptlrpc_nrs_request *nrq)
1111 struct nrs_orr_data *orrd;
1112 struct nrs_orr_object *orro;
1115 orro = container_of(nrs_request_resource(nrq),
1116 struct nrs_orr_object, oo_res);
1117 orrd = container_of(nrs_request_resource(nrq)->res_parent,
1118 struct nrs_orr_data, od_res);
1120 LASSERT(nrq->nr_u.orr.or_round <= orro->oo_round);
1122 is_root = &nrq->nr_node == cfs_binheap_root(orrd->od_binheap);
1124 cfs_binheap_remove(orrd->od_binheap, &nrq->nr_node);
1128 * If we just deleted the node at the root of the binheap, we may have
1129 * to adjust round numbers.
1131 if (unlikely(is_root)) {
1132 /** Peek at the next request to be served */
1133 cfs_binheap_node_t *node = cfs_binheap_root(orrd->od_binheap);
1135 /** No more requests */
1136 if (unlikely(node == NULL)) {
1139 nrq = container_of(node, struct ptlrpc_nrs_request,
1142 if (orrd->od_round < nrq->nr_u.orr.or_round)
1143 orrd->od_round = nrq->nr_u.orr.or_round;
1149 * Called right after the request \a nrq finishes being handled by ORR policy
1150 * instance \a policy.
1152 * \param[in] policy the policy that handled the request
1153 * \param[in] nrq the request that was handled
1155 static void nrs_orr_req_stop(struct ptlrpc_nrs_policy *policy,
1156 struct ptlrpc_nrs_request *nrq)
1158 /** NB: resource control, credits etc can be added here */
1159 if (strncmp(policy->pol_desc->pd_name, NRS_POL_NAME_ORR,
1160 NRS_POL_NAME_MAX) == 0)
1162 "NRS: finished handling %s request for object with FID "
1163 DFID", from OST with index %u, with round "LPU64"\n",
1164 NRS_POL_NAME_ORR, PFID(&nrq->nr_u.orr.or_key.ok_fid),
1165 nrq->nr_u.orr.or_key.ok_idx, nrq->nr_u.orr.or_round);
1168 "NRS: finished handling %s request from OST with index %u,"
1169 " with round "LPU64"\n",
1170 NRS_POL_NAME_TRR, nrq->nr_u.orr.or_key.ok_idx,
1171 nrq->nr_u.orr.or_round);
1181 * This allows to bundle the policy name into the lprocfs_vars::data pointer
1182 * so that lprocfs read/write functions can be used by both the ORR and TRR
1185 struct nrs_lprocfs_orr_data {
1186 struct ptlrpc_service *svc;
1188 } lprocfs_orr_data = {
1189 .name = NRS_POL_NAME_ORR
1190 }, lprocfs_trr_data = {
1191 .name = NRS_POL_NAME_TRR
1195 * Retrieves the value of the Round Robin quantum (i.e. the maximum batch size)
1196 * for ORR/TRR policy instances on both the regular and high-priority NRS head
1197 * of a service, as long as a policy instance is not in the
1198 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state; policy instances in this
1199 * state are skipped later by nrs_orr_ctl().
1201 * Quantum values are in # of RPCs, and the output is in YAML format.
1208 * XXX: the CRR-N version of this, ptlrpc_lprocfs_rd_nrs_crrn_quantum() is
1209 * almost identical; it can be reworked and then reused for ORR/TRR.
1211 static int ptlrpc_lprocfs_rd_nrs_orr_quantum(char *page, char **start,
1212 off_t off, int count, int *eof,
1215 struct nrs_lprocfs_orr_data *orr_data = data;
1216 struct ptlrpc_service *svc = orr_data->svc;
1222 * Perform two separate calls to this as only one of the NRS heads'
1223 * policies may be in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED or
1224 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING state.
1226 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG,
1228 NRS_CTL_ORR_RD_QUANTUM,
1232 rc2 = snprintf(page, count, NRS_LPROCFS_QUANTUM_NAME_REG
1235 * Ignore -ENODEV as the regular NRS head's policy may be in the
1236 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
1238 } else if (rc != -ENODEV) {
1243 * We know the ost_io service which is the only one ORR/TRR policies are
1244 * compatible with, do have an HP NRS head, but it may be best to guard
1245 * against a possible change of this in the future.
1247 if (!nrs_svc_has_hp(svc))
1250 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP,
1251 orr_data->name, NRS_CTL_ORR_RD_QUANTUM,
1255 rc2 += snprintf(page + rc2, count - rc2,
1256 NRS_LPROCFS_QUANTUM_NAME_HP"%-5d\n", quantum);
1258 * Ignore -ENODEV as the high priority NRS head's policy may be
1259 * in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
1261 } else if (rc != -ENODEV) {
1271 * Sets the value of the Round Robin quantum (i.e. the maximum batch size)
1272 * for ORR/TRR policy instances of a service. The user can set the quantum size
1273 * for the regular and high priority NRS head separately by specifying each
1274 * value, or both together in a single invocation.
1278 * lctl set_param ost.OSS.ost_io.nrs_orr_quantum=req_quantum:64, to set the
1279 * request quantum size of the ORR policy instance on the regular NRS head of
1280 * the ost_io service to 64
1282 * lctl set_param ost.OSS.ost_io.nrs_trr_quantum=hp_quantum:8 to set the request
1283 * quantum size of the TRR policy instance on the high priority NRS head of the
1284 * ost_io service to 8
1286 * lctl set_param ost.OSS.ost_io.nrs_orr_quantum=32, to set both the request
1287 * quantum size of the ORR policy instance on both the regular and the high
1288 * priority NRS head of the ost_io service to 32
1290 * policy instances in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state
1291 * are skipped later by nrs_orr_ctl().
1293 * XXX: the CRR-N version of this, ptlrpc_lprocfs_wr_nrs_crrn_quantum() is
1294 * almost identical; it can be reworked and then reused for ORR/TRR.
1296 static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file,
1298 unsigned long count, void *data)
1300 struct nrs_lprocfs_orr_data *orr_data = data;
1301 struct ptlrpc_service *svc = orr_data->svc;
1302 enum ptlrpc_nrs_queue_type queue = 0;
1303 char kernbuf[LPROCFS_NRS_WR_QUANTUM_MAX_CMD];
1307 /** lprocfs_find_named_value() modifies its argument, so keep a copy */
1308 unsigned long count_copy;
1312 if (count > (sizeof(kernbuf) - 1))
1315 if (copy_from_user(kernbuf, buffer, count))
1318 kernbuf[count] = '\0';
1323 * Check if the regular quantum value has been specified
1325 val = lprocfs_find_named_value(kernbuf, NRS_LPROCFS_QUANTUM_NAME_REG,
1327 if (val != kernbuf) {
1328 quantum_reg = simple_strtol(val, NULL, 10);
1330 queue |= PTLRPC_NRS_QUEUE_REG;
1336 * Check if the high priority quantum value has been specified
1338 val = lprocfs_find_named_value(kernbuf, NRS_LPROCFS_QUANTUM_NAME_HP,
1340 if (val != kernbuf) {
1341 if (!nrs_svc_has_hp(svc))
1344 quantum_hp = simple_strtol(val, NULL, 10);
1346 queue |= PTLRPC_NRS_QUEUE_HP;
1350 * If none of the queues has been specified, look for a valid numerical
1354 if (!isdigit(kernbuf[0]))
1357 quantum_reg = simple_strtol(kernbuf, NULL, 10);
1359 queue = PTLRPC_NRS_QUEUE_REG;
1361 if (nrs_svc_has_hp(svc)) {
1362 queue |= PTLRPC_NRS_QUEUE_HP;
1363 quantum_hp = quantum_reg;
1367 if ((((queue & PTLRPC_NRS_QUEUE_REG) != 0) &&
1368 ((quantum_reg > LPROCFS_NRS_QUANTUM_MAX || quantum_reg <= 0))) ||
1369 (((queue & PTLRPC_NRS_QUEUE_HP) != 0) &&
1370 ((quantum_hp > LPROCFS_NRS_QUANTUM_MAX || quantum_hp <= 0))))
1374 * We change the values on regular and HP NRS heads separately, so that
1375 * we do not exit early from ptlrpc_nrs_policy_control() with an error
1376 * returned by nrs_policy_ctl_locked(), in cases where the user has not
1377 * started the policy on either the regular or HP NRS head; i.e. we are
1378 * ignoring -ENODEV within nrs_policy_ctl_locked(). -ENODEV is returned
1379 * only if the operation fails with -ENODEV on all heads that have been
1380 * specified by the command; if at least one operation succeeds,
1381 * success is returned.
1383 if ((queue & PTLRPC_NRS_QUEUE_REG) != 0) {
1384 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG,
1386 NRS_CTL_ORR_WR_QUANTUM, false,
1388 if ((rc < 0 && rc != -ENODEV) ||
1389 (rc == -ENODEV && queue == PTLRPC_NRS_QUEUE_REG))
1393 if ((queue & PTLRPC_NRS_QUEUE_HP) != 0) {
1394 rc2 = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP,
1396 NRS_CTL_ORR_WR_QUANTUM, false,
1398 if ((rc2 < 0 && rc2 != -ENODEV) ||
1399 (rc2 == -ENODEV && queue == PTLRPC_NRS_QUEUE_HP))
1403 return rc == -ENODEV && rc2 == -ENODEV ? -ENODEV : count;
1406 #define LPROCFS_NRS_OFF_NAME_REG "reg_offset_type:"
1407 #define LPROCFS_NRS_OFF_NAME_HP "hp_offset_type:"
1409 #define LPROCFS_NRS_OFF_NAME_PHYSICAL "physical"
1410 #define LPROCFS_NRS_OFF_NAME_LOGICAL "logical"
1413 * Retrieves the offset type used by ORR/TRR policy instances on both the
1414 * regular and high-priority NRS head of a service, as long as a policy
1415 * instance is not in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state;
1416 * policy instances in this state are skipped later by nrs_orr_ctl().
1418 * Offset type information is a (physical|logical) string, and output is
1423 * reg_offset_type:physical
1424 * hp_offset_type:logical
1426 static int ptlrpc_lprocfs_rd_nrs_orr_offset_type(char *page, char **start,
1427 off_t off, int count, int *eof,
1430 struct nrs_lprocfs_orr_data *orr_data = data;
1431 struct ptlrpc_service *svc = orr_data->svc;
1437 * Perform two separate calls to this as only one of the NRS heads'
1438 * policies may be in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED
1439 * or ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING state.
1441 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG,
1442 orr_data->name, NRS_CTL_ORR_RD_OFF_TYPE,
1446 rc2 = snprintf(page, count,
1447 LPROCFS_NRS_OFF_NAME_REG"%s\n",
1448 physical ? LPROCFS_NRS_OFF_NAME_PHYSICAL :
1449 LPROCFS_NRS_OFF_NAME_LOGICAL);
1451 * Ignore -ENODEV as the regular NRS head's policy may be in the
1452 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
1454 } else if (rc != -ENODEV) {
1459 * We know the ost_io service which is the only one ORR/TRR policies are
1460 * compatible with, do have an HP NRS head, but it may be best to guard
1461 * against a possible change of this in the future.
1463 if (!nrs_svc_has_hp(svc))
1466 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP,
1467 orr_data->name, NRS_CTL_ORR_RD_OFF_TYPE,
1471 rc2 += snprintf(page + rc2, count - rc2,
1472 LPROCFS_NRS_OFF_NAME_HP"%s\n",
1473 physical ? LPROCFS_NRS_OFF_NAME_PHYSICAL :
1474 LPROCFS_NRS_OFF_NAME_LOGICAL);
1476 * Ignore -ENODEV as the high priority NRS head's policy may be
1477 * in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
1479 } else if (rc != -ENODEV) {
1489 * Max valid command string is the size of the labels, plus "physical" twice.
1490 * plus a separating ' '
1492 #define LPROCFS_NRS_WR_OFF_TYPE_MAX_CMD \
1493 sizeof(LPROCFS_NRS_OFF_NAME_REG LPROCFS_NRS_OFF_NAME_PHYSICAL " " \
1494 LPROCFS_NRS_OFF_NAME_HP LPROCFS_NRS_OFF_NAME_PHYSICAL)
1497 * Sets the type of offsets used to order RPCs in ORR/TRR policy instances. The
1498 * user can set offset type for the regular or high priority NRS head
1499 * separately by specifying each value, or both together in a single invocation.
1503 * lctl set_param ost.OSS.ost_io.nrs_orr_offset_type=
1504 * reg_offset_type:physical, to enable the ORR policy instance on the regular
1505 * NRS head of the ost_io service to use physical disk offset ordering.
1507 * lctl set_param ost.OSS.ost_io.nrs_trr_offset_type=logical, to enable the TRR
1508 * policy instances on both the regular ang high priority NRS heads of the
1509 * ost_io service to use logical file offset ordering.
1511 * policy instances in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state are
1512 * are skipped later by nrs_orr_ctl().
1514 static int ptlrpc_lprocfs_wr_nrs_orr_offset_type(struct file *file,
1516 unsigned long count,
1519 struct nrs_lprocfs_orr_data *orr_data = data;
1520 struct ptlrpc_service *svc = orr_data->svc;
1521 enum ptlrpc_nrs_queue_type queue = 0;
1522 char kernbuf[LPROCFS_NRS_WR_OFF_TYPE_MAX_CMD];
1527 unsigned long count_copy;
1531 if (count > (sizeof(kernbuf) - 1))
1534 if (copy_from_user(kernbuf, buffer, count))
1537 kernbuf[count] = '\0';
1542 * Check if the regular offset type has been specified
1544 val_reg = lprocfs_find_named_value(kernbuf,
1545 LPROCFS_NRS_OFF_NAME_REG,
1547 if (val_reg != kernbuf)
1548 queue |= PTLRPC_NRS_QUEUE_REG;
1553 * Check if the high priority offset type has been specified
1555 val_hp = lprocfs_find_named_value(kernbuf, LPROCFS_NRS_OFF_NAME_HP,
1557 if (val_hp != kernbuf) {
1558 if (!nrs_svc_has_hp(svc))
1561 queue |= PTLRPC_NRS_QUEUE_HP;
1565 * If none of the queues has been specified, there may be a valid
1566 * command string at the start of the buffer.
1569 queue = PTLRPC_NRS_QUEUE_REG;
1571 if (nrs_svc_has_hp(svc))
1572 queue |= PTLRPC_NRS_QUEUE_HP;
1575 if ((queue & PTLRPC_NRS_QUEUE_REG) != 0) {
1576 if (strncmp(val_reg, LPROCFS_NRS_OFF_NAME_PHYSICAL,
1577 sizeof(LPROCFS_NRS_OFF_NAME_PHYSICAL) - 1) == 0)
1578 physical_reg = true;
1579 else if (strncmp(val_reg, LPROCFS_NRS_OFF_NAME_LOGICAL,
1580 sizeof(LPROCFS_NRS_OFF_NAME_LOGICAL) - 1) == 0)
1581 physical_reg = false;
1586 if ((queue & PTLRPC_NRS_QUEUE_HP) != 0) {
1587 if (strncmp(val_hp, LPROCFS_NRS_OFF_NAME_PHYSICAL,
1588 sizeof(LPROCFS_NRS_OFF_NAME_PHYSICAL) - 1) == 0)
1590 else if (strncmp(val_hp, LPROCFS_NRS_OFF_NAME_LOGICAL,
1591 sizeof(LPROCFS_NRS_OFF_NAME_LOGICAL) - 1) == 0)
1592 physical_hp = false;
1598 * We change the values on regular and HP NRS heads separately, so that
1599 * we do not exit early from ptlrpc_nrs_policy_control() with an error
1600 * returned by nrs_policy_ctl_locked(), in cases where the user has not
1601 * started the policy on either the regular or HP NRS head; i.e. we are
1602 * ignoring -ENODEV within nrs_policy_ctl_locked(). -ENODEV is returned
1603 * only if the operation fails with -ENODEV on all heads that have been
1604 * specified by the command; if at least one operation succeeds,
1605 * success is returned.
1607 if ((queue & PTLRPC_NRS_QUEUE_REG) != 0) {
1608 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG,
1610 NRS_CTL_ORR_WR_OFF_TYPE, false,
1612 if ((rc < 0 && rc != -ENODEV) ||
1613 (rc == -ENODEV && queue == PTLRPC_NRS_QUEUE_REG))
1617 if ((queue & PTLRPC_NRS_QUEUE_HP) != 0) {
1618 rc2 = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP,
1620 NRS_CTL_ORR_WR_OFF_TYPE, false,
1622 if ((rc2 < 0 && rc2 != -ENODEV) ||
1623 (rc2 == -ENODEV && queue == PTLRPC_NRS_QUEUE_HP))
1627 return rc == -ENODEV && rc2 == -ENODEV ? -ENODEV : count;
1630 #define NRS_LPROCFS_REQ_SUPP_NAME_REG "reg_supported:"
1631 #define NRS_LPROCFS_REQ_SUPP_NAME_HP "hp_supported:"
1633 #define LPROCFS_NRS_SUPP_NAME_READS "reads"
1634 #define LPROCFS_NRS_SUPP_NAME_WRITES "writes"
1635 #define LPROCFS_NRS_SUPP_NAME_READWRITES "reads_and_writes"
1638 * Translates enum nrs_orr_supp values to a corresponding string.
1640 static const char *nrs_orr_supp2str(enum nrs_orr_supp supp)
1646 return LPROCFS_NRS_SUPP_NAME_READS;
1648 return LPROCFS_NRS_SUPP_NAME_WRITES;
1650 return LPROCFS_NRS_SUPP_NAME_READWRITES;
1655 * Translates strings to the corresponding enum nrs_orr_supp value
1657 static enum nrs_orr_supp nrs_orr_str2supp(const char *val)
1659 if (strncmp(val, LPROCFS_NRS_SUPP_NAME_READWRITES,
1660 sizeof(LPROCFS_NRS_SUPP_NAME_READWRITES) - 1) == 0)
1662 else if (strncmp(val, LPROCFS_NRS_SUPP_NAME_READS,
1663 sizeof(LPROCFS_NRS_SUPP_NAME_READS) - 1) == 0)
1664 return NOS_OST_READ;
1665 else if (strncmp(val, LPROCFS_NRS_SUPP_NAME_WRITES,
1666 sizeof(LPROCFS_NRS_SUPP_NAME_WRITES) - 1) == 0)
1667 return NOS_OST_WRITE;
1673 * Retrieves the type of RPCs handled at the point of invocation by ORR/TRR
1674 * policy instances on both the regular and high-priority NRS head of a service,
1675 * as long as a policy instance is not in the
1676 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state; policy instances in this
1677 * state are skipped later by nrs_orr_ctl().
1679 * Supported RPC type information is a (reads|writes|reads_and_writes) string,
1680 * and output is in YAML format.
1684 * reg_supported:reads
1685 * hp_supported:reads_and_writes
1687 static int ptlrpc_lprocfs_rd_nrs_orr_supported(char *page, char **start,
1688 off_t off, int count, int *eof,
1691 struct nrs_lprocfs_orr_data *orr_data = data;
1692 struct ptlrpc_service *svc = orr_data->svc;
1693 enum nrs_orr_supp supported;
1698 * Perform two separate calls to this as only one of the NRS heads'
1699 * policies may be in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED
1700 * or ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING state.
1702 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG,
1704 NRS_CTL_ORR_RD_SUPP_REQ, true,
1709 rc2 = snprintf(page, count,
1710 NRS_LPROCFS_REQ_SUPP_NAME_REG"%s\n",
1711 nrs_orr_supp2str(supported));
1713 * Ignore -ENODEV as the regular NRS head's policy may be in the
1714 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
1716 } else if (rc != -ENODEV) {
1721 * We know the ost_io service which is the only one ORR/TRR policies are
1722 * compatible with, do have an HP NRS head, but it may be best to guard
1723 * against a possible change of this in the future.
1725 if (!nrs_svc_has_hp(svc))
1728 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP,
1730 NRS_CTL_ORR_RD_SUPP_REQ, true,
1734 rc2 += snprintf(page + rc2, count - rc2,
1735 NRS_LPROCFS_REQ_SUPP_NAME_HP"%s\n",
1736 nrs_orr_supp2str(supported));
1738 * Ignore -ENODEV as the high priority NRS head's policy may be
1739 * in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
1741 } else if (rc != -ENODEV) {
1751 * Max valid command string is the size of the labels, plus "reads_and_writes"
1752 * twice, plus a separating ' '
1754 #define LPROCFS_NRS_WR_REQ_SUPP_MAX_CMD \
1755 sizeof(NRS_LPROCFS_REQ_SUPP_NAME_REG LPROCFS_NRS_SUPP_NAME_READWRITES \
1756 NRS_LPROCFS_REQ_SUPP_NAME_HP LPROCFS_NRS_SUPP_NAME_READWRITES \
1760 * Sets the type of RPCs handled by ORR/TRR policy instances. The user can
1761 * modify this setting for the regular or high priority NRS heads separately, or
1762 * both together in a single invocation.
1766 * lctl set_param ost.OSS.ost_io.nrs_orr_supported=
1767 * "reg_supported:reads", to enable the ORR policy instance on the regular NRS
1768 * head of the ost_io service to handle OST_READ RPCs.
1770 * lctl set_param ost.OSS.ost_io.nrs_trr_supported=reads_and_writes, to enable
1771 * the TRR policy instances on both the regular ang high priority NRS heads of
1772 * the ost_io service to use handle OST_READ and OST_WRITE RPCs.
1774 * policy instances in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state are
1775 * are skipped later by nrs_orr_ctl().
1777 static int ptlrpc_lprocfs_wr_nrs_orr_supported(struct file *file,
1779 unsigned long count, void *data)
1781 struct nrs_lprocfs_orr_data *orr_data = data;
1782 struct ptlrpc_service *svc = orr_data->svc;
1783 enum ptlrpc_nrs_queue_type queue = 0;
1784 char kernbuf[LPROCFS_NRS_WR_REQ_SUPP_MAX_CMD];
1787 enum nrs_orr_supp supp_reg;
1788 enum nrs_orr_supp supp_hp;
1789 unsigned long count_copy;
1793 if (count > (sizeof(kernbuf) - 1))
1796 if (copy_from_user(kernbuf, buffer, count))
1799 kernbuf[count] = '\0';
1804 * Check if the regular supported requests setting has been specified
1806 val_reg = lprocfs_find_named_value(kernbuf,
1807 NRS_LPROCFS_REQ_SUPP_NAME_REG,
1809 if (val_reg != kernbuf)
1810 queue |= PTLRPC_NRS_QUEUE_REG;
1815 * Check if the high priority supported requests setting has been
1818 val_hp = lprocfs_find_named_value(kernbuf, NRS_LPROCFS_REQ_SUPP_NAME_HP,
1820 if (val_hp != kernbuf) {
1821 if (!nrs_svc_has_hp(svc))
1824 queue |= PTLRPC_NRS_QUEUE_HP;
1828 * If none of the queues has been specified, there may be a valid
1829 * command string at the start of the buffer.
1832 queue = PTLRPC_NRS_QUEUE_REG;
1834 if (nrs_svc_has_hp(svc))
1835 queue |= PTLRPC_NRS_QUEUE_HP;
1838 if ((queue & PTLRPC_NRS_QUEUE_REG) != 0) {
1839 supp_reg = nrs_orr_str2supp(val_reg);
1840 if (supp_reg == -EINVAL)
1844 if ((queue & PTLRPC_NRS_QUEUE_HP) != 0) {
1845 supp_hp = nrs_orr_str2supp(val_hp);
1846 if (supp_hp == -EINVAL)
1851 * We change the values on regular and HP NRS heads separately, so that
1852 * we do not exit early from ptlrpc_nrs_policy_control() with an error
1853 * returned by nrs_policy_ctl_locked(), in cases where the user has not
1854 * started the policy on either the regular or HP NRS head; i.e. we are
1855 * ignoring -ENODEV within nrs_policy_ctl_locked(). -ENODEV is returned
1856 * only if the operation fails with -ENODEV on all heads that have been
1857 * specified by the command; if at least one operation succeeds,
1858 * success is returned.
1860 if ((queue & PTLRPC_NRS_QUEUE_REG) != 0) {
1861 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG,
1863 NRS_CTL_ORR_WR_SUPP_REQ, false,
1865 if ((rc < 0 && rc != -ENODEV) ||
1866 (rc == -ENODEV && queue == PTLRPC_NRS_QUEUE_REG))
1870 if ((queue & PTLRPC_NRS_QUEUE_HP) != 0) {
1871 rc2 = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP,
1873 NRS_CTL_ORR_WR_SUPP_REQ, false,
1875 if ((rc2 < 0 && rc2 != -ENODEV) ||
1876 (rc2 == -ENODEV && queue == PTLRPC_NRS_QUEUE_HP))
1880 return rc == -ENODEV && rc2 == -ENODEV ? -ENODEV : count;
1883 int nrs_orr_lprocfs_init(struct ptlrpc_service *svc)
1888 struct lprocfs_vars nrs_orr_lprocfs_vars[] = {
1889 { .name = "nrs_orr_quantum",
1890 .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_quantum,
1891 .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_quantum },
1892 { .name = "nrs_orr_offset_type",
1893 .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_offset_type,
1894 .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_offset_type },
1895 { .name = "nrs_orr_supported",
1896 .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_supported,
1897 .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_supported },
1901 if (svc->srv_procroot == NULL)
1904 lprocfs_orr_data.svc = svc;
1906 for (i = 0; i < ARRAY_SIZE(nrs_orr_lprocfs_vars); i++)
1907 nrs_orr_lprocfs_vars[i].data = &lprocfs_orr_data;
1909 rc = lprocfs_add_vars(svc->srv_procroot, nrs_orr_lprocfs_vars, NULL);
1914 void nrs_orr_lprocfs_fini(struct ptlrpc_service *svc)
1916 if (svc->srv_procroot == NULL)
1919 lprocfs_remove_proc_entry("nrs_orr_quantum", svc->srv_procroot);
1920 lprocfs_remove_proc_entry("nrs_orr_offset_type", svc->srv_procroot);
1921 lprocfs_remove_proc_entry("nrs_orr_supported", svc->srv_procroot);
1924 #endif /* LPROCFS */
1926 static const struct ptlrpc_nrs_pol_ops nrs_orr_ops = {
1927 .op_policy_init = nrs_orr_init,
1928 .op_policy_start = nrs_orr_start,
1929 .op_policy_stop = nrs_orr_stop,
1930 .op_policy_ctl = nrs_orr_ctl,
1931 .op_res_get = nrs_orr_res_get,
1932 .op_res_put = nrs_orr_res_put,
1933 .op_req_get = nrs_orr_req_get,
1934 .op_req_enqueue = nrs_orr_req_add,
1935 .op_req_dequeue = nrs_orr_req_del,
1936 .op_req_stop = nrs_orr_req_stop,
1938 .op_lprocfs_init = nrs_orr_lprocfs_init,
1939 .op_lprocfs_fini = nrs_orr_lprocfs_fini,
1943 struct ptlrpc_nrs_pol_conf nrs_conf_orr = {
1944 .nc_name = NRS_POL_NAME_ORR,
1945 .nc_ops = &nrs_orr_ops,
1946 .nc_compat = nrs_policy_compat_one,
1947 .nc_compat_svc_name = "ost_io",
1951 * TRR, Target-based Round Robin policy
1953 * TRR reuses much of the functions and data structures of ORR
1958 int nrs_trr_lprocfs_init(struct ptlrpc_service *svc)
1963 struct lprocfs_vars nrs_trr_lprocfs_vars[] = {
1964 { .name = "nrs_trr_quantum",
1965 .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_quantum,
1966 .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_quantum },
1967 { .name = "nrs_trr_offset_type",
1968 .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_offset_type,
1969 .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_offset_type },
1970 { .name = "nrs_trr_supported",
1971 .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_supported,
1972 .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_supported },
1976 if (svc->srv_procroot == NULL)
1979 lprocfs_trr_data.svc = svc;
1981 for (i = 0; i < ARRAY_SIZE(nrs_trr_lprocfs_vars); i++)
1982 nrs_trr_lprocfs_vars[i].data = &lprocfs_trr_data;
1984 rc = lprocfs_add_vars(svc->srv_procroot, nrs_trr_lprocfs_vars, NULL);
1989 void nrs_trr_lprocfs_fini(struct ptlrpc_service *svc)
1991 if (svc->srv_procroot == NULL)
1994 lprocfs_remove_proc_entry("nrs_trr_quantum", svc->srv_procroot);
1995 lprocfs_remove_proc_entry("nrs_trr_offset_type", svc->srv_procroot);
1996 lprocfs_remove_proc_entry("nrs_trr_supported", svc->srv_procroot);
1999 #endif /* LPROCFS */
2002 * Reuse much of the ORR functionality for TRR.
2004 static const struct ptlrpc_nrs_pol_ops nrs_trr_ops = {
2005 .op_policy_init = nrs_orr_init,
2006 .op_policy_start = nrs_orr_start,
2007 .op_policy_stop = nrs_orr_stop,
2008 .op_policy_ctl = nrs_orr_ctl,
2009 .op_res_get = nrs_orr_res_get,
2010 .op_res_put = nrs_orr_res_put,
2011 .op_req_get = nrs_orr_req_get,
2012 .op_req_enqueue = nrs_orr_req_add,
2013 .op_req_dequeue = nrs_orr_req_del,
2014 .op_req_stop = nrs_orr_req_stop,
2016 .op_lprocfs_init = nrs_trr_lprocfs_init,
2017 .op_lprocfs_fini = nrs_trr_lprocfs_fini,
2021 struct ptlrpc_nrs_pol_conf nrs_conf_trr = {
2022 .nc_name = NRS_POL_NAME_TRR,
2023 .nc_ops = &nrs_trr_ops,
2024 .nc_compat = nrs_policy_compat_one,
2025 .nc_compat_svc_name = "ost_io",
2028 /** @} ORR/TRR policy */
2032 #endif /* HAVE_SERVER_SUPPORT */