Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1577951 > unrolled thread

[PATCH -tip 0/4] ipc/shm: moar updates for v4.11

Started byDavidlohr Bueso <dave@stgolabs.net>
First post2017-02-09 22:00 +0100
Last post2017-02-09 22:00 +0100
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH -tip 0/4] ipc/shm: moar updates for v4.11 Davidlohr Bueso <dave@stgolabs.net> - 2017-02-09 22:00 +0100
    [PATCH 2/4] ipc/shm: some shmat cleanups Davidlohr Bueso <dave@stgolabs.net> - 2017-02-09 22:00 +0100
    [PATCH 3/4] sysv,ipc: cacheline align kern_ipc_perm Davidlohr Bueso <dave@stgolabs.net> - 2017-02-09 22:00 +0100

#1577951 — [PATCH -tip 0/4] ipc/shm: moar updates for v4.11

FromDavidlohr Bueso <dave@stgolabs.net>
Date2017-02-09 22:00 +0100
Subject[PATCH -tip 0/4] ipc/shm: moar updates for v4.11
Message-ID<t93YS-2u7-13@gated-at.bofh.it>
Hi,

Here are some more updates and fixes I noticed while going through
more sysv shm code after the recent shmat(2) fix.

I know it's a bit late in the game, but please consider for v4.11.

Passes ltp tests.

Thanks!

Davidlohr Bueso (4):
  ipc/shm: do not check for MAP_POPULATE
  ipc/shm: some shmat cleanups
  sysv,ipc: cacheline align kern_ipc_perm
  mm,hugetlb: compute page_size_log properly

 include/linux/ipc.h |  7 +++----
 include/linux/sem.h |  3 +--
 ipc/shm.c           | 18 +++++++-----------
 mm/mmap.c           |  2 +-
 4 files changed, 12 insertions(+), 18 deletions(-)

-- 
2.6.6

[toc] | [next] | [standalone]


#1577952 — [PATCH 2/4] ipc/shm: some shmat cleanups

FromDavidlohr Bueso <dave@stgolabs.net>
Date2017-02-09 22:00 +0100
Subject[PATCH 2/4] ipc/shm: some shmat cleanups
Message-ID<t93YS-2u7-29@gated-at.bofh.it>
In reply to#1577951
... cleans up early flag and address minutia.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
 ipc/shm.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 6b3769967789..9c960241e214 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1095,11 +1095,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
 	      ulong *raddr, unsigned long shmlba)
 {
 	struct shmid_kernel *shp;
-	unsigned long addr;
+	unsigned long addr = (unsigned long)shmaddr;
 	unsigned long size;
 	struct file *file;
 	int    err;
-	unsigned long flags;
+	unsigned long flags = MAP_SHARED;
 	unsigned long prot;
 	int acc_mode;
 	struct ipc_namespace *ns;
@@ -1111,7 +1111,8 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
 	err = -EINVAL;
 	if (shmid < 0)
 		goto out;
-	else if ((addr = (ulong)shmaddr)) {
+
+	if (addr) {
 		if (addr & (shmlba - 1)) {
 			/*
 			 * Round down to the nearest multiple of shmlba.
@@ -1126,13 +1127,10 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
 #endif
 					goto out;
 		}
-		flags = MAP_SHARED | MAP_FIXED;
-	} else {
-		if ((shmflg & SHM_REMAP))
-			goto out;
 
-		flags = MAP_SHARED;
-	}
+		flags |= MAP_FIXED;
+	} else if ((shmflg & SHM_REMAP))
+		goto out;
 
 	if (shmflg & SHM_RDONLY) {
 		prot = PROT_READ;
-- 
2.6.6

[toc] | [prev] | [next] | [standalone]


#1577955 — [PATCH 3/4] sysv,ipc: cacheline align kern_ipc_perm

FromDavidlohr Bueso <dave@stgolabs.net>
Date2017-02-09 22:00 +0100
Subject[PATCH 3/4] sysv,ipc: cacheline align kern_ipc_perm
Message-ID<t93YS-2u7-35@gated-at.bofh.it>
In reply to#1577951
Assign 'struct kern_ipc_perm' its own cacheline to avoid false
sharing with sysv ipc calls. While the structure itself is rather
read-mostly throughout the lifespan of ipc, the spinlock causes
most of the invalidations. One example is 31a7c4746e9 (ipc/sem.c:
cacheline align the ipc spinlock for semaphores). Therefore,
extend this to all ipc.

The effect of cacheline alignment on sems can be seen in sembench,
which deals mostly with semtimedop wait/wakes is seen to improve raw
throughput (worker loops) between 8 to 12% on a 24-core x86 with
over 4 threads.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
 include/linux/ipc.h | 7 +++----
 include/linux/sem.h | 3 +--
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/include/linux/ipc.h b/include/linux/ipc.h
index 9d84942ae2e5..71fd92d81b26 100644
--- a/include/linux/ipc.h
+++ b/include/linux/ipc.h
@@ -8,8 +8,7 @@
 #define IPCMNI 32768  /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
 
 /* used by in-kernel data structures */
-struct kern_ipc_perm
-{
+struct kern_ipc_perm {
 	spinlock_t	lock;
 	bool		deleted;
 	int		id;
@@ -18,9 +17,9 @@ struct kern_ipc_perm
 	kgid_t		gid;
 	kuid_t		cuid;
 	kgid_t		cgid;
-	umode_t		mode; 
+	umode_t		mode;
 	unsigned long	seq;
 	void		*security;
-};
+} ____cacheline_aligned_in_smp;
 
 #endif /* _LINUX_IPC_H */
diff --git a/include/linux/sem.h b/include/linux/sem.h
index 4fc222f8755d..9edec926e9d9 100644
--- a/include/linux/sem.h
+++ b/include/linux/sem.h
@@ -10,8 +10,7 @@ struct task_struct;
 
 /* One sem_array data structure for each set of semaphores in the system. */
 struct sem_array {
-	struct kern_ipc_perm	____cacheline_aligned_in_smp
-				sem_perm;	/* permissions .. see ipc.h */
+	struct kern_ipc_perm	sem_perm;	/* permissions .. see ipc.h */
 	time_t			sem_ctime;	/* last change time */
 	struct sem		*sem_base;	/* ptr to first semaphore in array */
 	struct list_head	pending_alter;	/* pending operations */
-- 
2.6.6

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web