>From a2e04d4d855f85faa913399f4fadedf45d09142a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 6 Dec 2021 11:11:00 -0700 Subject: [PATCH 2/4] io_uring: convert to using atomic-ref Signed-off-by: Jens Axboe --- fs/io_uring.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 59fd8b785262..2ce076fd85dc 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -81,6 +81,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -1170,17 +1171,10 @@ 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); + return atomic_ref_inc_not_zero(&req->refs); } static inline bool req_ref_put_and_test(struct io_kiocb *req) @@ -1188,21 +1182,19 @@ 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); + return atomic_ref_put_and_test(&req->refs); } static inline void req_ref_put(struct io_kiocb *req) { WARN_ON_ONCE(!(req->flags & REQ_F_REFCOUNT)); - WARN_ON_ONCE(req_ref_put_and_test(req)); + atomic_ref_put(&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); + atomic_ref_get(&req->refs); } static inline void io_submit_flush_completions(struct io_ring_ctx *ctx) -- 2.34.1