Skip to contentSkip to conversation

ipc/sem.c: fix lockup, restore FIFO behavior

PATCH Superseded Manfred Spraul 2 participants 3 messages May 25, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipc/sem.c: fix lockup, restore FIFO behavior

Hi Rik,

I came up with a completely different approach:

The patch
a) fixes a lockup due to a missing restart.
b) makes the code again FIFO.

Changes:
- the wait-for-zero operations are moved into seperate lists. Thus they can be checked seperately, without rescanning the whole queue.
- If a complex operating arrives, then all pending change operations are moved into the global queue. This allows to keep everything FIFO.

Advantage:
- Fewer restarts in update_queue(), because pending wait-for-zero do not force a restart anymore.
- Efficient handling of wait-for-zero semops, both simple and complex.
- FIFO. Dropping FIFO is a user visible change, and I'm a coward.
- simpler check_restart logic.

Disadvantage:
When one complex operation arrives, then the semaphore array goes into a complex_present mode that always acquires the global lock. Even when the complex operations have completed, pending simple decrease operations prevent the array from switching back. The switch happens when there are only simple wait-for-zero semops (or no semops at all).

But: Let's wait if this really exists: An application that does rarely complex operations (and that doesn't prefer FIFO semantics).

Other changes:
- try_atomic_semop() also performs the semop. Thus rename the function.

It passes tests with qemu, but not boot-tested due to EFI problems.

---

include/linux/sem.h +6 -2
index 53d4265..3f2c6c8 100644
@@ -15,10 +15,14 @@ struct sem_array {
 	time_t			sem_otime;	/* last semop time */
 	time_t			sem_ctime;	/* last change time */
 	struct sem		*sem_base;	/* ptr to first semaphore in array */
-	struct list_head	sem_pending;	/* pending operations to be processed */
+	struct list_head	pending_alter;	/* pending operations */
+						/* that alter the array */
+	struct list_head	pending_const;	/* pending complex operations */
+						/* that do not alter semvals */
 	struct list_head	list_id;	/* undo requests on this array */
 	int			sem_nsems;	/* no. of semaphores in array */
-	int			complex_count;	/* pending complex operations */
+	int			complex_present;
+						/* pending complex semops? */
 };
 
 #ifdef CONFIG_SYSVIPC
ipc/sem.c +267 -115

584 lines not on this page · raw message

#1 lore raw
Quoted 28 lines · Manfred Spraul

Hi Rik,

I came up with a completely different approach:

The patch
a) fixes a lockup due to a missing restart.
b) makes the code again FIFO.

Changes:
- the wait-for-zero operations are moved into seperate lists. Thus they can be checked seperately, without rescanning the whole queue.
- If a complex operating arrives, then all pending change operations are moved into the global queue. This allows to keep everything FIFO.

Advantage:
- Fewer restarts in update_queue(), because pending wait-for-zero do not force a restart anymore.
- Efficient handling of wait-for-zero semops, both simple and complex.
- FIFO. Dropping FIFO is a user visible change, and I'm a coward.
- simpler check_restart logic.

Disadvantage:
When one complex operation arrives, then the semaphore array goes into a complex_present mode that always acquires the global lock. Even when the complex operations have completed, pending simple decrease operations prevent the array from switching back. The switch happens when there are only simple wait-for-zero semops (or no semops at all).

Quoted 2 lines

But: Let's wait if this really exists: An application that does rarely complex operations (and that doesn't prefer FIFO semantics).

I do not like that downside at all.

The danger of staying in "too slow to be useful" mode forever is really not a risk I want to take.

Signature · 1 line
All rights reversed
#2 lore raw

Hi Rik,

Quoted 10 lines · Rik van Riel
Quoted 3 lines · Manfred Spraul

But: Let's wait if this really exists: An application that does rarely complex operations (and that doesn't prefer FIFO semantics).

I do not like that downside at all.

The danger of staying in "too slow to be useful" mode forever is really not a risk I want to take.

I've modified the patch so that it leaves the mode as soon as possible. Are you aware of any real-life apps that use multiple semops?

--
Manfred