Skip to content

Commit 6546c78

Browse files
committed
Merge tag 'rxrpc-rewrite-20160824-2' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
David Howells says: ==================== rxrpc: Add better client conn management strategy These two patches add a better client connection management strategy. They need to be applied on top of the just-posted fixes. (1) Duplicate the connection list and separate out procfs iteration from garbage collection. This is necessary for the next patch as with that client connections no longer appear on a single list and may not appear on a list at all - and really don't want to be exposed to the old garbage collector. (Note that client conns aren't left dangling, they're also in a tree rooted in the local endpoint so that they can be found by a user wanting to make a new client call. Service conns do not appear in this tree.) (2) Implement a better lifetime management and garbage collection strategy for client connections. In this, a client connection can be in one of five cache states (inactive, waiting, active, culled and idle). Limits are set on the number of client conns that may be active at any one time and makes users wait if they want to start a new call when there isn't capacity available. To make capacity available, active and idle connections can be culled, after a short delay (to allow for retransmission). The delay is reduced if the capacity exceeds a tunable threshold. If there is spare capacity, client conns are permitted to hang around a fair bit longer (tunable) so as to allow reuse of negotiated security contexts. After this patch, the client conn strategy is separate from that of service conns (which continues to use the old code for the moment). This difference in strategy is because the client side retains control over when it allows a connection to become active, whereas the service side has no control over when it sees a new connection or a new call on an old connection. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents d3c10db + 45025bc commit 6546c78

9 files changed

Lines changed: 943 additions & 160 deletions

File tree

‎net/rxrpc/ar-internal.h‎

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ enum rxrpc_conn_flag {
255255
RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */
256256
RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */
257257
RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */
258+
RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */
259+
RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */
260+
RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */
258261
};
259262

260263
/*
@@ -264,6 +267,17 @@ enum rxrpc_conn_event {
264267
RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */
265268
};
266269

270+
/*
271+
* The connection cache state.
272+
*/
273+
enum rxrpc_conn_cache_state {
274+
RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */
275+
RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */
276+
RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */
277+
RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */
278+
RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */
279+
};
280+
267281
/*
268282
* The connection protocol state.
269283
*/
@@ -276,6 +290,7 @@ enum rxrpc_conn_proto_state {
276290
RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */
277291
RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */
278292
RXRPC_CONN_NETWORK_ERROR, /* Conn terminated by network error */
293+
RXRPC_CONN_LOCAL_ERROR, /* Conn terminated by local error */
279294
RXRPC_CONN__NR_STATES
280295
};
281296

@@ -288,8 +303,14 @@ struct rxrpc_connection {
288303
struct rxrpc_conn_proto proto;
289304
struct rxrpc_conn_parameters params;
290305

291-
spinlock_t channel_lock;
306+
atomic_t usage;
307+
struct rcu_head rcu;
308+
struct list_head cache_link;
292309

310+
spinlock_t channel_lock;
311+
unsigned char active_chans; /* Mask of active channels */
312+
#define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1)
313+
struct list_head waiting_calls; /* Calls waiting for channels */
293314
struct rxrpc_channel {
294315
struct rxrpc_call __rcu *call; /* Active call */
295316
u32 call_id; /* ID of current call */
@@ -302,14 +323,13 @@ struct rxrpc_connection {
302323
u32 last_abort;
303324
};
304325
} channels[RXRPC_MAXCALLS];
305-
wait_queue_head_t channel_wq; /* queue to wait for channel to become available */
306326

307-
struct rcu_head rcu;
308327
struct work_struct processor; /* connection event processor */
309328
union {
310329
struct rb_node client_node; /* Node in local->client_conns */
311330
struct rb_node service_node; /* Node in peer->service_conns */
312331
};
332+
struct list_head proc_link; /* link in procfs list */
313333
struct list_head link; /* link in master connection list */
314334
struct sk_buff_head rx_queue; /* received conn-level packets */
315335
const struct rxrpc_security *security; /* applied security module */
@@ -320,15 +340,14 @@ struct rxrpc_connection {
320340
unsigned long events;
321341
unsigned long idle_timestamp; /* Time at which last became idle */
322342
spinlock_t state_lock; /* state-change lock */
323-
atomic_t usage;
343+
enum rxrpc_conn_cache_state cache_state : 8;
324344
enum rxrpc_conn_proto_state state : 8; /* current state of connection */
325345
u32 local_abort; /* local abort code */
326346
u32 remote_abort; /* remote abort code */
327347
int error; /* local error incurred */
328348
int debug_id; /* debug ID for printks */
329349
atomic_t serial; /* packet serial number counter */
330350
unsigned int hi_serial; /* highest serial number received */
331-
atomic_t avail_chans; /* number of channels available */
332351
u8 size_align; /* data size alignment (for security) */
333352
u8 header_size; /* rxrpc + security header size */
334353
u8 security_size; /* security header size */
@@ -350,6 +369,7 @@ enum rxrpc_call_flag {
350369
RXRPC_CALL_HAS_USERID, /* has a user ID attached */
351370
RXRPC_CALL_EXPECT_OOS, /* expect out of sequence packets */
352371
RXRPC_CALL_IS_SERVICE, /* Call is service call */
372+
RXRPC_CALL_EXPOSED, /* The call was exposed to the world */
353373
};
354374

355375
/*
@@ -416,13 +436,14 @@ struct rxrpc_call {
416436
struct work_struct destroyer; /* call destroyer */
417437
struct work_struct processor; /* packet processor and ACK generator */
418438
struct list_head link; /* link in master call list */
439+
struct list_head chan_wait_link; /* Link in conn->waiting_calls */
419440
struct hlist_node error_link; /* link in error distribution list */
420441
struct list_head accept_link; /* calls awaiting acceptance */
421442
struct rb_node sock_node; /* node in socket call tree */
422443
struct sk_buff_head rx_queue; /* received packets */
423444
struct sk_buff_head rx_oos_queue; /* packets received out of sequence */
424445
struct sk_buff *tx_pending; /* Tx socket buffer being filled */
425-
wait_queue_head_t tx_waitq; /* wait for Tx window space to become available */
446+
wait_queue_head_t waitq; /* Wait queue for channel or Tx */
426447
__be32 crypto_buf[2]; /* Temporary packet crypto buffer */
427448
unsigned long user_call_ID; /* user-defined call ID */
428449
unsigned long creation_jif; /* time of call creation */
@@ -545,12 +566,19 @@ static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
545566
/*
546567
* conn_client.c
547568
*/
569+
extern unsigned int rxrpc_max_client_connections;
570+
extern unsigned int rxrpc_reap_client_connections;
571+
extern unsigned int rxrpc_conn_idle_client_expiry;
572+
extern unsigned int rxrpc_conn_idle_client_fast_expiry;
548573
extern struct idr rxrpc_client_conn_ids;
549574

550575
void rxrpc_destroy_client_conn_ids(void);
551576
int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
552577
struct sockaddr_rxrpc *, gfp_t);
553-
void rxrpc_unpublish_client_conn(struct rxrpc_connection *);
578+
void rxrpc_expose_client_call(struct rxrpc_call *);
579+
void rxrpc_disconnect_client_call(struct rxrpc_call *);
580+
void rxrpc_put_client_conn(struct rxrpc_connection *);
581+
void __exit rxrpc_destroy_all_client_connections(void);
554582

555583
/*
556584
* conn_event.c
@@ -564,14 +592,16 @@ void rxrpc_reject_packets(struct rxrpc_local *);
564592
*/
565593
extern unsigned int rxrpc_connection_expiry;
566594
extern struct list_head rxrpc_connections;
595+
extern struct list_head rxrpc_connection_proc_list;
567596
extern rwlock_t rxrpc_connection_lock;
568597

569598
int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
570599
struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
571600
struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
572601
struct sk_buff *);
573-
void __rxrpc_disconnect_call(struct rxrpc_call *);
602+
void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
574603
void rxrpc_disconnect_call(struct rxrpc_call *);
604+
void rxrpc_kill_connection(struct rxrpc_connection *);
575605
void __rxrpc_put_connection(struct rxrpc_connection *);
576606
void __exit rxrpc_destroy_all_connections(void);
577607

@@ -598,8 +628,16 @@ struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *con
598628

599629
static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
600630
{
601-
if (conn && atomic_dec_return(&conn->usage) == 1)
602-
__rxrpc_put_connection(conn);
631+
if (!conn)
632+
return;
633+
634+
if (rxrpc_conn_is_client(conn)) {
635+
if (atomic_dec_and_test(&conn->usage))
636+
rxrpc_put_client_conn(conn);
637+
} else {
638+
if (atomic_dec_return(&conn->usage) == 1)
639+
__rxrpc_put_connection(conn);
640+
}
603641
}
604642

605643

‎net/rxrpc/call_event.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ static void rxrpc_resend(struct rxrpc_call *call)
193193
stop = true;
194194
sp->resend_at = jiffies + 3;
195195
} else {
196+
if (rxrpc_is_client_call(call))
197+
rxrpc_expose_client_call(call);
196198
sp->resend_at =
197199
jiffies + rxrpc_resend_timeout;
198200
}
@@ -378,7 +380,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
378380
call->acks_hard++;
379381
}
380382

381-
wake_up(&call->tx_waitq);
383+
wake_up(&call->waitq);
382384
}
383385

384386
/*

‎net/rxrpc/call_object.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
127127
INIT_WORK(&call->destroyer, &rxrpc_destroy_call);
128128
INIT_WORK(&call->processor, &rxrpc_process_call);
129129
INIT_LIST_HEAD(&call->link);
130+
INIT_LIST_HEAD(&call->chan_wait_link);
130131
INIT_LIST_HEAD(&call->accept_link);
131132
skb_queue_head_init(&call->rx_queue);
132133
skb_queue_head_init(&call->rx_oos_queue);
133-
init_waitqueue_head(&call->tx_waitq);
134+
init_waitqueue_head(&call->waitq);
134135
spin_lock_init(&call->lock);
135136
rwlock_init(&call->state_lock);
136137
atomic_set(&call->usage, 1);
@@ -358,7 +359,7 @@ struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx,
358359
call->debug_id, rxrpc_call_states[call->state]);
359360

360361
if (call->state >= RXRPC_CALL_COMPLETE) {
361-
__rxrpc_disconnect_call(call);
362+
__rxrpc_disconnect_call(conn, call);
362363
} else {
363364
spin_unlock(&conn->channel_lock);
364365
kmem_cache_free(rxrpc_call_jar, candidate);

0 commit comments

Comments
 (0)