diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-04-17 15:44:12 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-11-03 13:46:29 +0100 |
commit | 9480792609c779516ac465ac5a038101032be77d (patch) | |
tree | 4be080b62123227c4e6f1bf7ee400af3455e8801 /libpager/seqnos.c | |
parent | 282e4ae275dc1b9b0b5bba6eb1b145cd1e80fa33 (diff) |
libpager: use a fixed number of threads
Previously, libpager used an unbounded number of threads to receive
messages from the pager bucket. It used sequence barriers to execute
the requests to order requests to each object.
The sequence barriers are implemented in seqnos.c. A server function
uses _pager_wait_for_seqno to wait for its sequence number and
_pager_release_seqno to release it, or it uses _pager_update_seqno to
do both operations in one step.
These sequence barriers divide each server function in three parts: A,
B, and C. A_i happens "before" the sequence barrier i, B_i happens
"in order", C_i happens "after" the sequence barrier. This partial
order < has the following properties:
* This order is *per object*. Requests to different objects are not
ordered.
* A_i < B_i, B_i < C_i (due to the structure of the code)
* B_i < B_{i+1} (this is due to the sequence barriers)
* Note that only the B parts are ordered by the sequence numbers, we
are free to execute C_i and C_{i+1} in any possible order. The same
argument applies to the A parts.
The sequence barriers are implemented using a very simple ticket
algorithm. Every request, even the invalid ones, is processed by a
thread, and waits until the ticket count reaches its seqno, does some
work in-order, then increments the ticket and awakes all threads that
have piled up up to this moment. All of them except one will then
discover that it's not their turn yet and go to sleep again.
Creating one thread per request has proven to be problematic as
memory_object requests often arrive in large batches.
This patch does two things:
* Use a single thread to receive messages from the port bucket. All
incoming request are put into a queue.
* Use a fixed-number of threads (though even one is actually enough)
to execute the the server functions. If multiple threads are used,
a work-delegation mechanism ensures that the per object order < is
preserved.
For reference, I used the following command to create workloads that
highlight the problem this patch is addressing:
% settrans t .../ext2fs --sync=30 /dev/sd2s1
...
% /usr/bin/time zsh -c 'for ((i=0; i < 1500; i++)); do
dd if=/dev/zero of=t/src/$i bs=4k count=290 2>/dev/null
echo -n .
if ((i % 100 == 0)) ; then echo -n $i; fi
done'
* libpager/queue.h: New file.
* libpager/demuxer.c: Manage a queue of requests received from the
port bucket.
(pager_demuxer): Just decode the server function and enqueue the
request.
(worker_func): New function that consumes and executes the requests
from the queue.
(service_paging_requests): New function.
(pager_start_workers): Likewise.
* libpager/data-request.c: Remove the seqno barriers.
* libpager/data-return.c: Likewise.
* libpager/data-unlock.c: Likewise.
* libpager/chg-compl.c: Likewise.
* libpager/lock-completed.c: Likewise.
* libpager/no-senders.c: Likewise.
* libpager/notify-stubs.c: Likewise.
* libpager/object-init.c: Likewise.
* libpager/object-terminate.c: Likewise.
* libpager/seqnos.c: Remove file.
* libpager/stubs.c: Likewise.
* libpager/pager.h (pager_demuxer): Drop declaration.
(pager_start_workers): New declaration.
* libpager/priv.h: Remove the _pager_seqno declarations.
* libpager/Makefile (SRCS): Drop seqnos.c.
* console/pager.c (user_pager_init): Call pager_start_workers.
* libdiskfs/disk-pager.c: Likewise.
* storeio/pager.c: Likewise.
* ext2fs/pager.c (service_paging_requests): Remove function.
(create_disk_pager): Start separate file pager using
`pager_start_workers'.
* fatfs/pager.c (service_paging_requests): Remove function.
(create_fat_pager): Start separate file pager using
`pager_start_workers'.
Diffstat (limited to 'libpager/seqnos.c')
-rw-r--r-- | libpager/seqnos.c | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/libpager/seqnos.c b/libpager/seqnos.c deleted file mode 100644 index cab2f33d..00000000 --- a/libpager/seqnos.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Sequence number synchronization routines for pager library - Copyright (C) 1994, 2011 Free Software Foundation - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "priv.h" -#include <assert.h> - -/* The message with seqno SEQNO has just been dequeued for pager P; - wait until all preceding messages have had a chance and then - return. */ -void -_pager_wait_for_seqno (struct pager *p, - mach_port_seqno_t seqno) -{ - while (seqno != p->seqno + 1) - { - p->waitingforseqno = 1; - pthread_cond_wait (&p->wakeup, &p->interlock); - } -} - - -/* Allow the next message for pager P (potentially blocked in - _pager_wait_for_seqno) to be handled. */ -void -_pager_release_seqno (struct pager *p, - mach_port_seqno_t seqno) -{ - assert (seqno == p->seqno + 1); - p->seqno = seqno; - if (p->waitingforseqno) - { - p->waitingforseqno = 0; - pthread_cond_broadcast (&p->wakeup); - } -} - - -/* Just update the seqno. */ -void -_pager_update_seqno (mach_port_t object, - mach_port_seqno_t seqno) -{ - struct pager *p; - - p = ports_lookup_port (0, object, _pager_class); - _pager_update_seqno_p (p, seqno); - if (p) - ports_port_deref (p); -} - - -/* Just update the seqno, pointer version. */ -void -_pager_update_seqno_p (struct pager *p, - mach_port_seqno_t seqno) -{ - if (p - && p->port.class == _pager_class) - { - pthread_mutex_lock (&p->interlock); - _pager_wait_for_seqno (p, seqno); - _pager_release_seqno (p, seqno); - pthread_mutex_unlock (&p->interlock); - } -} |