@@ -1544,7 +1544,6 @@ static void io_dismantle_req(struct io_kiocb *req)
1544
1544
kfree (req -> io );
1545
1545
if (req -> file )
1546
1546
io_put_file (req , req -> file , (req -> flags & REQ_F_FIXED_FILE ));
1547
- __io_put_req_task (req );
1548
1547
io_req_clean_work (req );
1549
1548
1550
1549
if (req -> flags & REQ_F_INFLIGHT ) {
@@ -1564,6 +1563,7 @@ static void __io_free_req(struct io_kiocb *req)
1564
1563
struct io_ring_ctx * ctx ;
1565
1564
1566
1565
io_dismantle_req (req );
1566
+ __io_put_req_task (req );
1567
1567
ctx = req -> ctx ;
1568
1568
if (likely (!io_is_fallback_req (req )))
1569
1569
kmem_cache_free (req_cachep , req );
@@ -1807,8 +1807,18 @@ static void io_free_req(struct io_kiocb *req)
1807
1807
struct req_batch {
1808
1808
void * reqs [IO_IOPOLL_BATCH ];
1809
1809
int to_free ;
1810
+
1811
+ struct task_struct * task ;
1812
+ int task_refs ;
1810
1813
};
1811
1814
1815
+ static inline void io_init_req_batch (struct req_batch * rb )
1816
+ {
1817
+ rb -> to_free = 0 ;
1818
+ rb -> task_refs = 0 ;
1819
+ rb -> task = NULL ;
1820
+ }
1821
+
1812
1822
static void __io_req_free_batch_flush (struct io_ring_ctx * ctx ,
1813
1823
struct req_batch * rb )
1814
1824
{
@@ -1822,6 +1832,10 @@ static void io_req_free_batch_finish(struct io_ring_ctx *ctx,
1822
1832
{
1823
1833
if (rb -> to_free )
1824
1834
__io_req_free_batch_flush (ctx , rb );
1835
+ if (rb -> task ) {
1836
+ put_task_struct_many (rb -> task , rb -> task_refs );
1837
+ rb -> task = NULL ;
1838
+ }
1825
1839
}
1826
1840
1827
1841
static void io_req_free_batch (struct req_batch * rb , struct io_kiocb * req )
@@ -1833,6 +1847,17 @@ static void io_req_free_batch(struct req_batch *rb, struct io_kiocb *req)
1833
1847
if (req -> flags & REQ_F_LINK_HEAD )
1834
1848
io_queue_next (req );
1835
1849
1850
+ if (req -> flags & REQ_F_TASK_PINNED ) {
1851
+ if (req -> task != rb -> task ) {
1852
+ if (rb -> task )
1853
+ put_task_struct_many (rb -> task , rb -> task_refs );
1854
+ rb -> task = req -> task ;
1855
+ rb -> task_refs = 0 ;
1856
+ }
1857
+ rb -> task_refs ++ ;
1858
+ req -> flags &= ~REQ_F_TASK_PINNED ;
1859
+ }
1860
+
1836
1861
io_dismantle_req (req );
1837
1862
rb -> reqs [rb -> to_free ++ ] = req ;
1838
1863
if (unlikely (rb -> to_free == ARRAY_SIZE (rb -> reqs )))
@@ -1978,7 +2003,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
1978
2003
/* order with ->result store in io_complete_rw_iopoll() */
1979
2004
smp_rmb ();
1980
2005
1981
- rb . to_free = 0 ;
2006
+ io_init_req_batch ( & rb ) ;
1982
2007
while (!list_empty (done )) {
1983
2008
int cflags = 0 ;
1984
2009
0 commit comments