ipc/shm: moar updates for v4.11
Subsystems (2)
cover ipc/shm: moar updates for v4.11
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(-)
Signature · 1 line
2.6.6
PATCH 1/4 ipc/shm: do not check for MAP_POPULATE
We do not support prefaulting functionality in sysv shm, nor MAP_NONBLOCK for that matter. Drop the pointless check for populate in do_shmat().
--- ipc/shm.c | 2 -- 1 file changed, 2 deletions(-)
ipc/shm.c +0 -2
@@ -1234,8 +1234,6 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, err = (long )addr; invalid:up_write (¤t->mm->mmap_sem); -if (populate) -mm_populate (addr, populate); out_fput:fput (file);
Signature · 1 line
2.6.6
Re: [PATCH 1/4] ipc/shm: do not check for MAP_POPULATE
Quoted 3 lines · Davidlohr Bueso
We do not support prefaulting functionality in sysv shm, nor
MAP_NONBLOCKfor that matter. Drop the pointless check for populate indo_shmat().
I haven't checked, but are you sure that "populated" does nothing when the attacher had previously called mlockall(MCL_FUTURE)?
Hugh
Quoted 21 lines
Signed-off-by Davidlohr Bueso <[email protected]>--- ipc/shm.c | 2 -- 1 file changed, 2 deletions(-)ipc/shm.c +0
-2@@ -1234,8 +1234,6 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, err = (long )addr; invalid:up_write (¤t->mm->mmap_sem); -if (populate) -mm_populate (addr, populate); out_fput:fput (file);Signature · 1 line
2.6.6
Re: [PATCH 1/4] ipc/shm: do not check for MAP_POPULATE
Quoted 2 lines · Hugh Dickins
I haven't checked, but are you sure that "populated" does nothing when the attacher had previously called
mlockall(MCL_FUTURE)?
I checked and you are certainly right. Andrew, please do not consider this patch, it's bogus.
Thanks,
Davidlohr
PATCH 2/4 ipc/shm: some shmat cleanups
In reply to Davidlohr Bueso... cleans up early flag and address minutia.
--- ipc/shm.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
ipc/shm.c +7 -9
@@ -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 ;
Signature · 1 line
2.6.6
PATCH 3/4 sysv,ipc: cacheline align kern_ipc_perm
In reply to Davidlohr BuesoAssign '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.
--- include/linux/ipc.h | 7 +++---- include/linux/sem.h | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-)
include/linux/ipc.h +3 -4
@@ -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_permkgid_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 */
include/linux/sem.h +1 -2
@@ -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 */
Signature · 1 line
2.6.6
PATCH 4/4 mm,hugetlb: compute page_size_log properly
In reply to Davidlohr BuesoThe SHM_HUGE_* stuff was introduced in:
42d7395feb5 (mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB)
It unnecessarily adds another layer, specific to sysv shm, without anything special about it: the macros are identical to the MAP_HUGE_* stuff, which in turn does correctly describe the hugepage subsystem.
One example of the problems with extra layers what this patch fixes:mmap_pgoff() should never be using SHM_HUGE_* logic. It is obviously harmless but it would still be grand to get rid of it -- although now in the manpages I don't see that happening.
--- mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mmap.c +1 -1
@@ -1479,7 +1479,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,struct user_struct *user =NULL ;struct hstate *hs; - hs =hstate_sizelog ((flags >>MAP_HUGE_SHIFT ) &SHM_HUGE_MASK ); + hs =hstate_sizelog ((flags >>MAP_HUGE_SHIFT ) &MAP_HUGE_MASK );if (!hs)return -EINVAL ;
Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 4/4] mm,hugetlb: compute page_size_log properly
Quoted 4 lines · Davidlohr Bueso
The SHM_HUGE_* stuff was introduced in:
42d7395feb5(mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB)
Quoted 8 lines
It unnecessarily adds another layer, specific to sysv shm, without anything special about it: the macros are identical to the MAP_HUGE_* stuff, which in turn does correctly describe the hugepage subsystem.
One example of the problems with extra layers what this patch fixes:
mmap_pgoff()should never be using SHM_HUGE_* logic. It is obviously harmless but it would still be grand to get rid of it -- although now in the manpages I don't see that happening.
Can we just drop SHM_HUGE_MASK altogether? It is not exported in uapi headers AFAICS.
Quoted 28 lines
Signed-off-by Davidlohr Bueso <[email protected]>--- mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/mmap.c +1
-1@@ -1479,7 +1479,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,struct user_struct *user =NULL ;struct hstate *hs; - hs =hstate_sizelog ((flags >>MAP_HUGE_SHIFT ) &SHM_HUGE_MASK ); + hs =hstate_sizelog ((flags >>MAP_HUGE_SHIFT ) &MAP_HUGE_MASK );if (!hs)return -EINVAL ;Signature · 7 lines
2.6.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 4/4] mm,hugetlb: compute page_size_log properly
Quoted 9 lines · Michal Hocko
Quoted 8 lines · Davidlohr Bueso
The SHM_HUGE_* stuff was introduced in:
42d7395feb5(mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB)It unnecessarily adds another layer, specific to sysv shm, without anything special about it: the macros are identical to the MAP_HUGE_* stuff, which in turn does correctly describe the hugepage subsystem.
Quoted 7 lines
Quoted 4 lines
One example of the problems with extra layers what this patch fixes:
mmap_pgoff()should never be using SHM_HUGE_* logic. It is obviously harmless but it would still be grand to get rid of it -- although now in the manpages I don't see that happening.Can we just drop
SHM_HUGE_MASKaltogether? It is not exported in uapi headers AFAICS.
Yeah that was my original idea, however I noticed that shmget.2 mentions kernel internals as part of SHM_HUGE_{2MB,1GB}, ie: SHM_HUGE_SHIFT. So dropping _MASK doesn't make sense if we are going to keep _SHIFT.
Thanks,
Davidlohr
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 4/4] mm,hugetlb: compute page_size_log properly
Sorry for a late reply, I wasn't online last week
Quoted 16 lines · Davidlohr Bueso
Quoted 14 lines · Michal Hocko
Quoted 12 lines · Davidlohr Bueso
The SHM_HUGE_* stuff was introduced in:
42d7395feb5(mm: support more pagesizes for MAP_HUGETLB/SHM_HUGETLB)It unnecessarily adds another layer, specific to sysv shm, without anything special about it: the macros are identical to the MAP_HUGE_* stuff, which in turn does correctly describe the hugepage subsystem.
One example of the problems with extra layers what this patch fixes:
mmap_pgoff()should never be using SHM_HUGE_* logic. It is obviously harmless but it would still be grand to get rid of it -- although now in the manpages I don't see that happening.
Quoted 6 lines
Quoted 2 lines
Can we just drop
SHM_HUGE_MASKaltogether? It is not exported in uapi headers AFAICS.Yeah that was my original idea, however I noticed that shmget.2 mentions kernel internals as part of SHM_HUGE_{2MB,1GB}, ie:
SHM_HUGE_SHIFT. So dropping_MASKdoesn't make sense if we are going to keep_SHIFT.
I am not sure I understand.
$ git grep SHM_HUGE_ include/uapi/ $
So there doesn't seem to be any user visible constant. The man page mentiones is but I do not really see how is the userspace supposed to use it.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 4/4] mm,hugetlb: compute page_size_log properly
Quoted 7 lines · Michal Hocko
I am not sure I understand.
$ git grep SHM_HUGE_ include/uapi/ $So there doesn't seem to be any user visible constant. The man page mentiones is but I do not really see how is the userspace supposed to use it.
Yeah, userspace is not supposed to use it, it's just there because the manpage describes kernel internals. I'm not really a big fan of touching manpages (and ipc is already full of corner cases), but I guess nobody can really complain if we rip out all the SHM_HUGE_ stuff.
Thanks,
Davidlohr
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 4/4] mm,hugetlb: compute page_size_log properly
Quoted 6 lines · Davidlohr Bueso
Quoted 4 lines · Michal Hocko
I am not sure I understand.
$ git grep SHM_HUGE_ include/uapi/ $
Quoted 6 lines
Quoted 3 lines
So there doesn't seem to be any user visible constant. The man page mentiones is but I do not really see how is the userspace supposed to use it.
Yeah, userspace is not supposed to use it, it's just there because the manpage describes kernel internals.
Which is wrong!
Quoted 4 lines
I'm not really a big fan
of touching manpages (and ipc is already full of corner cases), but I guess nobody can really complain if we rip out all theSHM_HUGE_stuff.
yeah, let's just get rid of it.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>