提交 4cc1b4cf 编写于 作者: M Mikulas Patocka 提交者: Alasdair G Kergon

dm kcopyd: remove superfluous page allocation spinlock

Remove the spinlock protecting the pages allocation.  The spinlock is only
taken on initialization or from single-threaded workqueue.  Therefore, the
spinlock is useless.

The spinlock is taken in kcopyd_get_pages and kcopyd_put_pages.

kcopyd_get_pages is only called from run_pages_job, which is only
called from process_jobs called from do_work.

kcopyd_put_pages is called from client_alloc_pages (which is initialization
function) or from run_complete_job. run_complete_job is only called from
process_jobs called from do_work.

Another spinlock, kc->job_lock is taken each time someone pushes or pops
some work for the worker thread.  Once we take kc->job_lock, we
guarantee that any written memory is visible to the other CPUs.
Signed-off-by: NMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: NAlasdair G Kergon <agk@redhat.com>
上级 c6ea41fb
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
* pages for kcopyd io. * pages for kcopyd io.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
struct dm_kcopyd_client { struct dm_kcopyd_client {
spinlock_t lock;
struct page_list *pages; struct page_list *pages;
unsigned int nr_pages; unsigned int nr_pages;
unsigned int nr_free_pages; unsigned int nr_free_pages;
...@@ -99,11 +98,8 @@ static int kcopyd_get_pages(struct dm_kcopyd_client *kc, ...@@ -99,11 +98,8 @@ static int kcopyd_get_pages(struct dm_kcopyd_client *kc,
{ {
struct page_list *pl; struct page_list *pl;
spin_lock(&kc->lock); if (kc->nr_free_pages < nr)
if (kc->nr_free_pages < nr) {
spin_unlock(&kc->lock);
return -ENOMEM; return -ENOMEM;
}
kc->nr_free_pages -= nr; kc->nr_free_pages -= nr;
for (*pages = pl = kc->pages; --nr; pl = pl->next) for (*pages = pl = kc->pages; --nr; pl = pl->next)
...@@ -112,8 +108,6 @@ static int kcopyd_get_pages(struct dm_kcopyd_client *kc, ...@@ -112,8 +108,6 @@ static int kcopyd_get_pages(struct dm_kcopyd_client *kc,
kc->pages = pl->next; kc->pages = pl->next;
pl->next = NULL; pl->next = NULL;
spin_unlock(&kc->lock);
return 0; return 0;
} }
...@@ -121,14 +115,12 @@ static void kcopyd_put_pages(struct dm_kcopyd_client *kc, struct page_list *pl) ...@@ -121,14 +115,12 @@ static void kcopyd_put_pages(struct dm_kcopyd_client *kc, struct page_list *pl)
{ {
struct page_list *cursor; struct page_list *cursor;
spin_lock(&kc->lock);
for (cursor = pl; cursor->next; cursor = cursor->next) for (cursor = pl; cursor->next; cursor = cursor->next)
kc->nr_free_pages++; kc->nr_free_pages++;
kc->nr_free_pages++; kc->nr_free_pages++;
cursor->next = kc->pages; cursor->next = kc->pages;
kc->pages = pl; kc->pages = pl;
spin_unlock(&kc->lock);
} }
/* /*
...@@ -625,7 +617,6 @@ int dm_kcopyd_client_create(unsigned int nr_pages, ...@@ -625,7 +617,6 @@ int dm_kcopyd_client_create(unsigned int nr_pages,
if (!kc) if (!kc)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&kc->lock);
spin_lock_init(&kc->job_lock); spin_lock_init(&kc->job_lock);
INIT_LIST_HEAD(&kc->complete_jobs); INIT_LIST_HEAD(&kc->complete_jobs);
INIT_LIST_HEAD(&kc->io_jobs); INIT_LIST_HEAD(&kc->io_jobs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册