Whamcloud - gitweb
LU-17887 obd: do not update obd_memory from RCU
[fs/lustre-release.git] / lustre / include / lustre_nrs_orr.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * version 2 along with this program; If not, see
17  * http://www.gnu.org/licenses/gpl-2.0.html
18  *
19  * GPL HEADER END
20  */
21 /*
22  * Copyright (c) 2014, Intel Corporation.
23  *
24  * Copyright 2012 Xyratex Technology Limited
25  */
26 /*
27  *
28  * Network Request Scheduler (NRS) Object-based Round Robin and Target-based
29  * Round Robin (ORR and TRR) policies
30  *
31  */
32
33 #ifndef _LUSTRE_NRS_ORR_H
34 #define _LUSTRE_NRS_ORR_H
35
36 #ifdef HAVE_XARRAY_SUPPORT
37 #include <linux/xarray.h>
38 #else
39 #include <libcfs/linux/xarray.h>
40 #endif
41
42 /**
43  * ORR policy operations
44  */
45 #define NRS_CTL_ORR_RD_QUANTUM PTLRPC_NRS_CTL_POL_SPEC_01
46 #define NRS_CTL_ORR_WR_QUANTUM PTLRPC_NRS_CTL_POL_SPEC_02
47 #define NRS_CTL_ORR_RD_OFF_TYPE PTLRPC_NRS_CTL_POL_SPEC_03
48 #define NRS_CTL_ORR_WR_OFF_TYPE PTLRPC_NRS_CTL_POL_SPEC_04
49 #define NRS_CTL_ORR_RD_SUPP_REQ PTLRPC_NRS_CTL_POL_SPEC_05
50 #define NRS_CTL_ORR_WR_SUPP_REQ PTLRPC_NRS_CTL_POL_SPEC_06
51
52 /**
53  * \name ORR/TRR
54  *
55  * ORR/TRR (Object-based Round Robin/Target-based Round Robin) NRS policies
56  * @{
57  */
58
59 /**
60  * Lower and upper byte offsets of a brw RPC
61  */
62 struct nrs_orr_req_range {
63         __u64           or_start;
64         __u64           or_end;
65 };
66
67 /**
68  * RPC types supported by the ORR/TRR policies
69  */
70 enum nrs_orr_supp {
71         NOS_OST_READ    = BIT(0),
72         NOS_OST_WRITE   = BIT(1),
73         NOS_OST_RW      = (NOS_OST_READ | NOS_OST_WRITE),
74         /**
75          * Default value for policies.
76          */
77         NOS_DFLT        = NOS_OST_READ
78 };
79
80 /**
81  * As unique keys for grouping RPCs together, we use the object's OST FID for
82  * the ORR policy, and the OST index for the TRR policy.
83  *
84  * XXX: We waste some space for TRR policy instances by using a union, but it
85  *      allows to consolidate some of the code between ORR and TRR, and these
86  *      policies will probably eventually merge into one anyway.
87  */
88 struct nrs_orr_key {
89         union {
90                 /** object FID for ORR */
91                 struct lu_fid   ok_fid;
92                 /** OST index for TRR */
93                 __u32           ok_idx;
94         };
95 };
96
97 /**
98  * The largest base string for unique hash/slab object names is
99  * "nrs_orr_reg_", so 13 characters. We add 3 to this to be used for the CPT
100  * id number, so this _should_ be more than enough for the maximum number of
101  * CPTs on any system. If it does happen that this statement is incorrect,
102  * nrs_orr_genobjname() will inevitably yield a non-unique name and cause
103  * kmem_cache_create() to complain (on Linux), so the erroneous situation
104  * will hopefully not go unnoticed.
105  */
106 #define NRS_ORR_OBJ_NAME_MAX    (sizeof("nrs_orr_reg_") + 3)
107
108 /**
109  * private data structure for ORR and TRR NRS
110  */
111 struct nrs_orr_data {
112         struct ptlrpc_nrs_resource      od_res;
113         struct binheap                 *od_binheap;
114         struct rhashtable               od_obj_hash;
115         struct xarray                   od_trr_objs;
116         struct kmem_cache              *od_cache;
117         /**
118          * Used when a new scheduling round commences, in order to synchronize
119          * all object or OST batches with the new round number.
120          */
121         __u64                           od_round;
122         /**
123          * Determines the relevant ordering amongst request batches within a
124          * scheduling round.
125          */
126         __u64                           od_sequence;
127         /**
128          * RPC types that are currently supported.
129          */
130         enum nrs_orr_supp               od_supp;
131         /**
132          * Round Robin quantum; the maxium number of RPCs that each request
133          * batch for each object or OST can have in a scheduling round.
134          */
135         __u16                           od_quantum;
136         /**
137          * Whether to use physical disk offsets or logical file offsets.
138          */
139         bool                            od_physical;
140         /**
141          * XXX: We need to provide a persistently allocated string to hold
142          * unique object names for this policy, since in currently supported
143          * versions of Linux by Lustre, kmem_cache_create() just sets a pointer
144          * to the name string provided. kstrdup() is used in the version of
145          * kmeme_cache_create() in current Linux mainline, so we may be able to
146          * remove this in the future.
147          */
148         char                            od_objname[NRS_ORR_OBJ_NAME_MAX];
149 };
150
151 /**
152  * Represents a backend-fs object or OST in the ORR and TRR policies
153  * respectively
154  */
155 struct nrs_orr_object {
156         struct ptlrpc_nrs_resource      oo_res;
157         struct rhash_head               oo_rhead;
158         /**
159          * The round number against which requests are being scheduled for this
160          * object or OST
161          */
162         __u64                           oo_round;
163         /**
164          * The sequence number used for requests scheduled for this object or
165          * OST during the current round number.
166          */
167         __u64                           oo_sequence;
168         /**
169          * The key of the object or OST for which this structure
170          * instance is scheduling RPCs
171          */
172         struct nrs_orr_key      oo_key;
173         /**
174          * The reference count of this object. Once it hits zero free
175          * it from the hash table.
176          */
177         refcount_t                      oo_ref;
178         /**
179          * Round Robin quantum; the maximum number of RPCs that are allowed to
180          * be scheduled for the object or OST in a single batch of each round.
181          */
182         __u16                           oo_quantum;
183         /**
184          * # of pending requests for this object or OST, on all existing rounds
185          */
186         __u16                           oo_active;
187         /**
188          * Needed to free this structure from the RCU.
189          */
190         struct rcu_head                 oo_rcu_head;
191 };
192
193 /**
194  * ORR/TRR NRS request definition
195  */
196 struct nrs_orr_req {
197         /**
198          * The offset range this request covers
199          */
200         struct nrs_orr_req_range        or_range;
201         /**
202          * Round number for this request; shared with all other requests in the
203          * same batch.
204          */
205         __u64                           or_round;
206         /**
207          * Sequence number for this request; shared with all other requests in
208          * the same batch.
209          */
210         __u64                           or_sequence;
211         /**
212          * For debugging purposes.
213          */
214         struct nrs_orr_key              or_key;
215         /**
216          * An ORR policy instance has filled in request information while
217          * enqueueing the request on the service partition's regular NRS head.
218          */
219         unsigned int                    or_orr_set:1;
220         /**
221          * A TRR policy instance has filled in request information while
222          * enqueueing the request on the service partition's regular NRS head.
223          */
224         unsigned int                    or_trr_set:1;
225         /**
226          * Request offset ranges have been filled in with logical offset
227          * values.
228          */
229         unsigned int                    or_logical_set:1;
230         /**
231          * Request offset ranges have been filled in with physical offset
232          * values.
233          */
234         unsigned int                    or_physical_set:1;
235 };
236
237 /** @} ORR/TRR */
238 #endif