From: yajun.deng@linux.dev
To: "Peter Zijlstra" <peterz@infradead.org>
Cc: will@kernel.org, boqun.feng@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] refcount: introduce refcount_is_one() helper function
Date: Thu, 18 Nov 2021 08:12:56 +0000 [thread overview]
Message-ID: <a4b7401c06d3baa5d3d0a43d7aa6c62c@linux.dev> (raw)
In-Reply-To: <20211118074200.GF174703@worktop.programming.kicks-ass.net>
November 18, 2021 3:42 PM, "Peter Zijlstra" <peterz@infradead.org> wrote:
> On Thu, Nov 18, 2021 at 11:53:28AM +0800, Yajun Deng wrote:
>
>> There are many cases where it is necessary to determine if refcount is one,
>> introduce refcount_is_one() helper function for these cases.
>
> Give me one that is not racy?
The following determine refcount is one, 35 count.
linux (next-20211117) $ grep "refcount_read.*== 1" ./ -RnI
./tools/lib/perf/mmap.c: 101: if (refcount_read(&map->refcnt) == 1 && perf_mmap__empty(map))
./tools/perf/tests/cpumap.c: 72: TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1);
./tools/perf/tests/thread-map.c: 42: refcount_read(&map->refcnt) == 1);
./tools/perf/tests/thread-map.c: 57: refcount_read(&map->refcnt) == 1);
./tools/perf/tests/thread-map.c: 84: refcount_read(&threads->refcnt) == 1);
./tools/perf/tests/maps.c: 28: TEST_ASSERT_VAL("wrong map refcnt", refcount_read(&map->refcnt) == 1);
./include/linux/skbuff.h: 1078: if (likely(refcount_read(&skb->users) == 1))
./include/net/sock.h: 726: WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
./include/net/sock.h: 748: WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
./net/core/neighbour.c: 214: if (refcount_read(&n->refcnt) == 1) {
./net/core/neighbour.c: 264: if (refcount_read(&n->refcnt) == 1) {
./net/core/neighbour.c: 965: if (refcount_read(&n->refcnt) == 1 &&
./net/core/dev.c: 3017: if (likely(refcount_read(&skb->users) == 1)) {
./net/core/skbuff.c: 710: if (refcount_read(&fclones->fclone_ref) == 1)
./net/core/skbuff.c: 1514: refcount_read(&fclones->fclone_ref) == 1) {
./net/core/skbuff.c: 6278: if (refcount_read(&old->refcnt) == 1)
./net/core/skbuff.c: 6402: refcount_read(&ext->refcnt) == 1) {
./net/core/skbuff.c: 6417: if (refcount_read(&ext->refcnt) == 1)
./net/netlink/af_netlink.c: 614: WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
./net/tipc/socket.c: 3032: WARN_ON(refcount_read(&sk->sk_refcnt) == 1);
./net/netfilter/ipvs/ip_vs_conn.c: 480: (refcount_read(&cp->refcnt) == 1) &&
./net/sctp/auth.c:998: refcount_read(&key->refcnt) == 1) {
./drivers/tty/serial/sb1250-duart.c: 698: if (refcount_read(&duart->map_guard) == 1) {
./drivers/infiniband/core/cm.c: 1048: WARN_ON(refcount_read(&cm_id_priv->refcount) == 1);
./drivers/infiniband/hw/irdma/utils.c:513: refcount_read(&cqp_request->refcnt) == 1, 1000);
./drivers/crypto/caam/qi.c: 306: if (refcount_read(&drv_ctx->refcnt) == 1)
./drivers/net/ethernet/mellanox/mlx5/core/fs_core.c:1633: if (refcount_read(&handle->rule[i]->node.refcount) == 1) {
./drivers/net/vxlan.c: 1537: if (family == AF_INET && sock4 && refcount_read(&sock4->refcnt) == 1)
./drivers/net/vxlan.c: 1541: if (family == AF_INET6 && sock6 && refcount_read(&sock6->refcnt) == 1)
./kernel/events/core.c: 12861: wait_var_event(&ctx->refcount, refcount_read(&ctx->refcount) == 1);
./fs/nfs/nfs4proc.c: 9127: if (refcount_read(&clp->cl_count) == 1)
./fs/lockd/mon.c: 195: if (refcount_read(&nsm->sm_count) == 1
./fs/btrfs/transaction.c: 2061: ASSERT(refcount_read(&trans->use_count) == 1);
./fs/btrfs/block-group.c: 3960: ASSERT(refcount_read(&block_group->refs) == 1);
./fs/afs/write.c: 921: if (refcount_read(&wbk->usage) == 1)
The following determine refcount isn't one, 19 count.
linux (next-20211117) $ grep "refcount_read.*!= 1" ./ -RnI
./include/linux/skbuff.h: 1762: return refcount_read(&skb->users) != 1;
./include/net/sock.h: 1297: if (refcount_read(&sk->sk_refcnt) != 1)
./crypto/algapi.c: 461: BUG_ON(refcount_read(&alg->cra_refcnt) != 1);
./crypto/algapi.c: 560: BUG_ON(refcount_read(&inst->alg.cra_refcnt) != 1);
./net/sunrpc/auth.c: 690: if (refcount_read(&cred->cr_count) != 1 ||
./net/llc/llc_conn.c: 977: if (refcount_read(&sk->sk_refcnt) != 1) {
./net/ceph/osd_client.c: 5297: WARN_ON(refcount_read(&osdc->homeless_osd.o_ref) != 1);
./net/ipv6/ip6_fib.c: 1037: if (refcount_read(&rt->fib6_ref) != 1) {
./net/core/neighbour.c: 349: if (refcount_read(&n->refcnt) != 1) {
./net/core/pktgen.c: 3430: while (refcount_read(&(pkt_dev->skb->users)) != 1) {
./drivers/crypto/marvell/octeontx/otx_cptvf_algs.c: 1584: if (refcount_read(&otx_cpt_skciphers[i].base.cra_refcnt) != 1)
./drivers/crypto/marvell/octeontx/otx_cptvf_algs.c: 1587: if (refcount_read(&otx_cpt_aeads[i].base.cra_refcnt) != 1)
./drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c:406: refcount_read(&lkey_id->refcnt) != 1, lkey_id->id,
./drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c:435: refcount_read(&lkey_id->refcnt) != 1,
./drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c:464: refcount_read(&lkey_id->refcnt) != 1, lkey_id->id,
./drivers/block/nbd.c: 2541: if (refcount_read(&nbd->refs) != 1)
./fs/exec.c: 1182: if (refcount_read(&oldsighand->count) != 1) {
./fs/btrfs/tests/extent-map-tests.c: 24: if (refcount_read(&em->refs) != 1) {
./arch/s390/mm/extmem.c: 472: if (refcount_read(&seg->ref_count) != 1) {
next prev parent reply other threads:[~2021-11-18 8:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 3:53 [PATCH] refcount: introduce refcount_is_one() helper function Yajun Deng
2021-11-18 7:42 ` Peter Zijlstra
2021-11-18 8:12 ` yajun.deng [this message]
2021-11-18 8:44 ` Peter Zijlstra
2021-11-18 10:34 ` yajun.deng
2021-11-18 10:49 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a4b7401c06d3baa5d3d0a43d7aa6c62c@linux.dev \
--to=yajun.deng@linux.dev \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.