summaryrefslogtreecommitdiff
path: root/io_uring/rsrc.c
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2022-07-14 18:33:01 +0200
committerJens Axboe <axboe@kernel.dk>2022-07-24 18:39:18 -0600
commit4ccc6db0900fe337212b61650663a5dcedb69f25 (patch)
tree48c46809c46a9461f9f33c3b1e12f6602fa168ba /io_uring/rsrc.c
parent9bb66906f23e50d6db1e11f7498b72dfca1982a2 (diff)
downloadlwn-4ccc6db0900fe337212b61650663a5dcedb69f25.tar.gz
lwn-4ccc6db0900fe337212b61650663a5dcedb69f25.zip
io_uring: Use atomic_long_try_cmpxchg in __io_account_mem
Use atomic_long_try_cmpxchg instead of atomic_long_cmpxchg (*ptr, old, new) == old in __io_account_mem. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). Also, atomic_long_try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg fails, enabling further code simplifications. No functional change intended. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/rsrc.c')
-rw-r--r--io_uring/rsrc.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 0250c13ae1cd..7f66b0e25674 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -56,14 +56,13 @@ static inline int __io_account_mem(struct user_struct *user,
/* Don't allow more pages than we can safely lock */
page_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
+ cur_pages = atomic_long_read(&user->locked_vm);
do {
- cur_pages = atomic_long_read(&user->locked_vm);
new_pages = cur_pages + nr_pages;
if (new_pages > page_limit)
return -ENOMEM;
- } while (atomic_long_cmpxchg(&user->locked_vm, cur_pages,
- new_pages) != cur_pages);
-
+ } while (!atomic_long_try_cmpxchg(&user->locked_vm,
+ &cur_pages, new_pages));
return 0;
}