@@ -153,17 +153,10 @@ static void io_rsrc_put_work_one(struct io_rsrc_data *rsrc_data,
153
153
static void __io_rsrc_put_work (struct io_rsrc_node * ref_node )
154
154
{
155
155
struct io_rsrc_data * rsrc_data = ref_node -> rsrc_data ;
156
- struct io_rsrc_put * prsrc , * tmp ;
157
156
158
- if (ref_node -> inline_items )
157
+ if (likely ( ref_node -> inline_items ) )
159
158
io_rsrc_put_work_one (rsrc_data , & ref_node -> item );
160
159
161
- list_for_each_entry_safe (prsrc , tmp , & ref_node -> item_list , list ) {
162
- list_del (& prsrc -> list );
163
- io_rsrc_put_work_one (rsrc_data , prsrc );
164
- kfree (prsrc );
165
- }
166
-
167
160
io_rsrc_node_destroy (rsrc_data -> ctx , ref_node );
168
161
}
169
162
@@ -206,53 +199,29 @@ struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)
206
199
}
207
200
208
201
ref_node -> rsrc_data = NULL ;
209
- ref_node -> refs = 1 ;
210
- INIT_LIST_HEAD (& ref_node -> node );
211
- INIT_LIST_HEAD (& ref_node -> item_list );
212
202
ref_node -> inline_items = 0 ;
203
+ ref_node -> refs = 1 ;
213
204
return ref_node ;
214
205
}
215
206
216
- void io_rsrc_node_switch (struct io_ring_ctx * ctx ,
217
- struct io_rsrc_data * data_to_kill )
218
- __must_hold (& ctx - > uring_lock )
219
- {
220
- struct io_rsrc_node * node = ctx -> rsrc_node ;
221
- struct io_rsrc_node * backup = io_rsrc_node_alloc (ctx );
222
-
223
- if (WARN_ON_ONCE (!backup ))
224
- return ;
225
-
226
- node -> rsrc_data = data_to_kill ;
227
- list_add_tail (& node -> node , & ctx -> rsrc_ref_list );
228
- /* put master ref */
229
- io_put_rsrc_node (ctx , node );
230
- ctx -> rsrc_node = backup ;
231
- }
232
-
233
- int __io_rsrc_node_switch_start (struct io_ring_ctx * ctx )
234
- {
235
- struct io_rsrc_node * node = kzalloc (sizeof (* node ), GFP_KERNEL );
236
-
237
- if (!node )
238
- return - ENOMEM ;
239
- io_alloc_cache_put (& ctx -> rsrc_node_cache , & node -> cache );
240
- return 0 ;
241
- }
242
-
243
207
__cold static int io_rsrc_ref_quiesce (struct io_rsrc_data * data ,
244
208
struct io_ring_ctx * ctx )
245
209
{
210
+ struct io_rsrc_node * backup ;
246
211
DEFINE_WAIT (we );
247
212
int ret ;
248
213
249
- /* As we may drop ->uring_lock, other task may have started quiesce */
214
+ /* As We may drop ->uring_lock, other task may have started quiesce */
250
215
if (data -> quiesce )
251
216
return - ENXIO ;
252
- ret = io_rsrc_node_switch_start (ctx );
253
- if (ret )
254
- return ret ;
255
- io_rsrc_node_switch (ctx , data );
217
+
218
+ backup = io_rsrc_node_alloc (ctx );
219
+ if (!backup )
220
+ return - ENOMEM ;
221
+ ctx -> rsrc_node -> rsrc_data = data ;
222
+ list_add_tail (& ctx -> rsrc_node -> node , & ctx -> rsrc_ref_list );
223
+ io_put_rsrc_node (ctx , ctx -> rsrc_node );
224
+ ctx -> rsrc_node = backup ;
256
225
257
226
if (list_empty (& ctx -> rsrc_ref_list ))
258
227
return 0 ;
@@ -382,7 +351,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
382
351
struct file * file ;
383
352
int fd , i , err = 0 ;
384
353
unsigned int done ;
385
- bool needs_switch = false;
386
354
387
355
if (!ctx -> file_data )
388
356
return - ENXIO ;
@@ -414,7 +382,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
414
382
break ;
415
383
file_slot -> file_ptr = 0 ;
416
384
io_file_bitmap_clear (& ctx -> file_table , i );
417
- needs_switch = true;
418
385
}
419
386
if (fd != -1 ) {
420
387
file = fget (fd );
@@ -445,9 +412,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
445
412
io_file_bitmap_set (& ctx -> file_table , i );
446
413
}
447
414
}
448
-
449
- if (needs_switch )
450
- io_rsrc_node_switch (ctx , data );
451
415
return done ? done : err ;
452
416
}
453
417
@@ -458,7 +422,6 @@ static int __io_sqe_buffers_update(struct io_ring_ctx *ctx,
458
422
u64 __user * tags = u64_to_user_ptr (up -> tags );
459
423
struct iovec iov , __user * iovs = u64_to_user_ptr (up -> data );
460
424
struct page * last_hpage = NULL ;
461
- bool needs_switch = false;
462
425
__u32 done ;
463
426
int i , err ;
464
427
@@ -498,15 +461,11 @@ static int __io_sqe_buffers_update(struct io_ring_ctx *ctx,
498
461
break ;
499
462
}
500
463
ctx -> user_bufs [i ] = ctx -> dummy_ubuf ;
501
- needs_switch = true;
502
464
}
503
465
504
466
ctx -> user_bufs [i ] = imu ;
505
467
* io_get_tag_slot (ctx -> buf_data , i ) = tag ;
506
468
}
507
-
508
- if (needs_switch )
509
- io_rsrc_node_switch (ctx , ctx -> buf_data );
510
469
return done ? done : err ;
511
470
}
512
471
@@ -515,15 +474,11 @@ static int __io_register_rsrc_update(struct io_ring_ctx *ctx, unsigned type,
515
474
unsigned nr_args )
516
475
{
517
476
__u32 tmp ;
518
- int err ;
519
477
520
478
lockdep_assert_held (& ctx -> uring_lock );
521
479
522
480
if (check_add_overflow (up -> offset , nr_args , & tmp ))
523
481
return - EOVERFLOW ;
524
- err = io_rsrc_node_switch_start (ctx );
525
- if (err )
526
- return err ;
527
482
528
483
switch (type ) {
529
484
case IORING_RSRC_FILE :
@@ -685,21 +640,21 @@ int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx, void *rsrc)
685
640
struct io_ring_ctx * ctx = data -> ctx ;
686
641
struct io_rsrc_node * node = ctx -> rsrc_node ;
687
642
u64 * tag_slot = io_get_tag_slot (data , idx );
688
- struct io_rsrc_put * prsrc ;
689
643
690
- if (!node -> inline_items ) {
691
- prsrc = & node -> item ;
692
- node -> inline_items ++ ;
693
- } else {
694
- prsrc = kzalloc (sizeof (* prsrc ), GFP_KERNEL );
695
- if (!prsrc )
696
- return - ENOMEM ;
697
- list_add (& prsrc -> list , & node -> item_list );
644
+ ctx -> rsrc_node = io_rsrc_node_alloc (ctx );
645
+ if (unlikely (!ctx -> rsrc_node )) {
646
+ ctx -> rsrc_node = node ;
647
+ return - ENOMEM ;
698
648
}
699
649
700
- prsrc -> tag = * tag_slot ;
650
+ node -> item .rsrc = rsrc ;
651
+ node -> item .tag = * tag_slot ;
652
+ node -> inline_items = 1 ;
701
653
* tag_slot = 0 ;
702
- prsrc -> rsrc = rsrc ;
654
+
655
+ node -> rsrc_data = data ;
656
+ list_add_tail (& node -> node , & ctx -> rsrc_ref_list );
657
+ io_put_rsrc_node (ctx , node );
703
658
return 0 ;
704
659
}
705
660
0 commit comments