From: Oleg Nesterov <oleg@redhat.com>
To: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Cc: target-devel <target-devel@vger.kernel.org>,
linux-scsi <linux-scsi@vger.kernel.org>,
Christoph Hellwig <hch@lst.de>, Roland Dreier <roland@kernel.org>,
Kent Overstreet <koverstreet@google.com>,
Asias He <asias@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Or Gerlitz <ogerlitz@mellanox.com>,
Moussa Ba <moussaba@micron.com>, Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux-foundation.org>,
Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH 1/3] Percpu tag allocator
Date: Sat, 8 Jun 2013 17:07:34 +0200 [thread overview]
Message-ID: <20130608150734.GA6818@redhat.com> (raw)
In-Reply-To: <1370659338-23841-2-git-send-email-nab@linux-iscsi.org>
On 06/08, Nicholas A. Bellinger wrote:
>
> +unsigned tag_alloc(struct tag_pool *pool, bool wait)
> +{
> + struct tag_cpu_freelist *tags;
> + unsigned long flags;
> + unsigned ret;
> +retry:
> + preempt_disable();
> + local_irq_save(flags);
> + tags = this_cpu_ptr(pool->tag_cpu);
> +
> + while (!tags->nr_free) {
> + spin_lock(&pool->lock);
> +
> + if (pool->nr_free)
> + move_tags(tags->free, &tags->nr_free,
> + pool->free, &pool->nr_free,
> + min(pool->nr_free, pool->watermark));
> + else if (wait) {
> + struct tag_waiter wait = { .task = current };
> +
> + __set_current_state(TASK_UNINTERRUPTIBLE);
> + list_add(&wait.list, &pool->wait);
> +
> + spin_unlock(&pool->lock);
> + local_irq_restore(flags);
> + preempt_enable();
> +
> + schedule();
> +
> + if (!list_empty_careful(&wait.list)) {
> + spin_lock_irqsave(&pool->lock, flags);
> + list_del_init(&wait.list);
> + spin_unlock_irqrestore(&pool->lock, flags);
> + }
> +
> + goto retry;
> + } else
> + goto fail;
> +
> + spin_unlock(&pool->lock);
> + }
> +
> + ret = tags->free[--tags->nr_free];
> +
> + local_irq_restore(flags);
> + preempt_enable();
> +
> + return ret;
> +fail:
> + local_irq_restore(flags);
> + preempt_enable();
> + return 0;
> +}
I still think this code should use the normal wait_event().
See http://marc.info/?l=linux-kernel&m=136863269729888
> +void tag_free(struct tag_pool *pool, unsigned tag)
> +{
> + struct tag_cpu_freelist *tags;
> + unsigned long flags;
> +
> + preempt_disable();
> + local_irq_save(flags);
> + tags = this_cpu_ptr(pool->tag_cpu);
> +
> + tags->free[tags->nr_free++] = tag;
> +
> + if (tags->nr_free == pool->watermark * 2) {
> + spin_lock(&pool->lock);
> +
> + move_tags(pool->free, &pool->nr_free,
> + tags->free, &tags->nr_free,
> + pool->watermark);
> +
> + while (!list_empty(&pool->wait)) {
> + struct tag_waiter *wait;
> + wait = list_first_entry(&pool->wait,
> + struct tag_waiter, list);
> + list_del_init(&wait->list);
> + wake_up_process(wait->task);
And this still looks racy.
see http://marc.info/?l=linux-kernel&m=136853955229504
And probably the changelog should mention that cpu_down() can
lose the tags.
Oleg.
next prev parent reply other threads:[~2013-06-08 15:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-08 2:42 [PATCH 0/3] target: Per session tag pooling WIP using lib/tags Nicholas A. Bellinger
2013-06-08 2:42 ` [PATCH 1/3] Percpu tag allocator Nicholas A. Bellinger
2013-06-08 15:07 ` Oleg Nesterov [this message]
2013-06-08 2:42 ` [PATCH 2/3] target: Add transport_init_session_tagpool using per-cpu command map Nicholas A. Bellinger
2013-06-08 2:42 ` [PATCH 3/3] vhost/scsi: Convert to generic tag_alloc + tag_free " Nicholas A. Bellinger
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=20130608150734.GA6818@redhat.com \
--to=oleg@redhat.com \
--cc=asias@redhat.com \
--cc=cl@linux-foundation.org \
--cc=hch@lst.de \
--cc=koverstreet@google.com \
--cc=linux-scsi@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=moussaba@micron.com \
--cc=mst@redhat.com \
--cc=nab@linux-iscsi.org \
--cc=ogerlitz@mellanox.com \
--cc=roland@kernel.org \
--cc=target-devel@vger.kernel.org \
--cc=tj@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).