Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
e418bbc9
Commit
e418bbc9
authored
May 25, 2022
by
Jens Axboe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io_uring: move our reference counting into a header
Signed-off-by:
Jens Axboe
<
axboe@kernel.dk
>
parent
36404b09
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
42 deletions
+49
-42
io_uring/io_uring.c
io_uring/io_uring.c
+1
-42
io_uring/refs.h
io_uring/refs.h
+48
-0
No files found.
io_uring/io_uring.c
View file @
e418bbc9
...
...
@@ -91,6 +91,7 @@
#include "io_uring_types.h"
#include "io_uring.h"
#include "refs.h"
#include "xattr.h"
#include "nop.h"
...
...
@@ -611,54 +612,12 @@ static inline void io_tw_lock(struct io_ring_ctx *ctx, bool *locked)
#define io_for_each_link(pos, head) \
for (pos = (head); pos; pos = pos->link)
/*
* Shamelessly stolen from the mm implementation of page reference checking,
* see commit f958d7b528b1 for details.
*/
#define req_ref_zero_or_close_to_overflow(req) \
((unsigned int) atomic_read(&(req->refs)) + 127u <= 127u)
static
inline
bool
req_ref_inc_not_zero
(
struct
io_kiocb
*
req
)
{
WARN_ON_ONCE
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
));
return
atomic_inc_not_zero
(
&
req
->
refs
);
}
static
inline
bool
req_ref_put_and_test
(
struct
io_kiocb
*
req
)
{
if
(
likely
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
)))
return
true
;
WARN_ON_ONCE
(
req_ref_zero_or_close_to_overflow
(
req
));
return
atomic_dec_and_test
(
&
req
->
refs
);
}
static
inline
void
req_ref_get
(
struct
io_kiocb
*
req
)
{
WARN_ON_ONCE
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
));
WARN_ON_ONCE
(
req_ref_zero_or_close_to_overflow
(
req
));
atomic_inc
(
&
req
->
refs
);
}
static
inline
void
io_submit_flush_completions
(
struct
io_ring_ctx
*
ctx
)
{
if
(
!
wq_list_empty
(
&
ctx
->
submit_state
.
compl_reqs
))
__io_submit_flush_completions
(
ctx
);
}
static
inline
void
__io_req_set_refcount
(
struct
io_kiocb
*
req
,
int
nr
)
{
if
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
))
{
req
->
flags
|=
REQ_F_REFCOUNT
;
atomic_set
(
&
req
->
refs
,
nr
);
}
}
static
inline
void
io_req_set_refcount
(
struct
io_kiocb
*
req
)
{
__io_req_set_refcount
(
req
,
1
);
}
#define IO_RSRC_REF_BATCH 100
static
void
io_rsrc_put_node
(
struct
io_rsrc_node
*
node
,
int
nr
)
...
...
io_uring/refs.h
0 → 100644
View file @
e418bbc9
#ifndef IOU_REQ_REF_H
#define IOU_REQ_REF_H
#include <linux/atomic.h>
#include "io_uring_types.h"
/*
* Shamelessly stolen from the mm implementation of page reference checking,
* see commit f958d7b528b1 for details.
*/
#define req_ref_zero_or_close_to_overflow(req) \
((unsigned int) atomic_read(&(req->refs)) + 127u <= 127u)
static
inline
bool
req_ref_inc_not_zero
(
struct
io_kiocb
*
req
)
{
WARN_ON_ONCE
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
));
return
atomic_inc_not_zero
(
&
req
->
refs
);
}
static
inline
bool
req_ref_put_and_test
(
struct
io_kiocb
*
req
)
{
if
(
likely
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
)))
return
true
;
WARN_ON_ONCE
(
req_ref_zero_or_close_to_overflow
(
req
));
return
atomic_dec_and_test
(
&
req
->
refs
);
}
static
inline
void
req_ref_get
(
struct
io_kiocb
*
req
)
{
WARN_ON_ONCE
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
));
WARN_ON_ONCE
(
req_ref_zero_or_close_to_overflow
(
req
));
atomic_inc
(
&
req
->
refs
);
}
static
inline
void
__io_req_set_refcount
(
struct
io_kiocb
*
req
,
int
nr
)
{
if
(
!
(
req
->
flags
&
REQ_F_REFCOUNT
))
{
req
->
flags
|=
REQ_F_REFCOUNT
;
atomic_set
(
&
req
->
refs
,
nr
);
}
}
static
inline
void
io_req_set_refcount
(
struct
io_kiocb
*
req
)
{
__io_req_set_refcount
(
req
,
1
);
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment