net: mm_account_pinned_pages() optimization
authorEric Dumazet <edumazet@google.com>
Tue, 15 Nov 2022 09:10:56 +0000 (09:10 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 16 Nov 2022 12:42:00 +0000 (12:42 +0000)
Adopt atomic_long_try_cmpxchg() in mm_account_pinned_pages()
as it is slightly more efficient.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/skbuff.c

index 90d0852..4bf95e3 100644 (file)
@@ -1267,13 +1267,12 @@ int mm_account_pinned_pages(struct mmpin *mmp, size_t size)
        max_pg = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
        user = mmp->user ? : current_user();
 
+       old_pg = atomic_long_read(&user->locked_vm);
        do {
-               old_pg = atomic_long_read(&user->locked_vm);
                new_pg = old_pg + num_pg;
                if (new_pg > max_pg)
                        return -ENOBUFS;
-       } while (atomic_long_cmpxchg(&user->locked_vm, old_pg, new_pg) !=
-                old_pg);
+       } while (!atomic_long_try_cmpxchg(&user->locked_vm, &old_pg, new_pg));
 
        if (!mmp->user) {
                mmp->user = get_uid(user);