shm cleanups
Subsystems (3)
PATCH 1/1 shm cleanups
Hi Linus,
Here is a patch against 2.3.25 which
1) avoids vmalloc in the shm coding.
2) cleans a lot of cruft out of the shm headers
3) makes shm sysctl'able
I did test it a lot on SMP/HIGHMEM. Since 2.3.25 with and without this breaks on swapping shm and other high memory load conditions I could not verify everything. But I would like to see this in the mainstream kernel. I will then proceed debugging the swapping issues.
Greetings
Christoph
--Multipart_Wed_Nov__3_20:17:09_1999-1
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="patch-25-shm3"
Content-Transfer-Encoding: 7bit
arch/i386/kernel/sys_i386.c +64 -79
@@ -116,86 +116,71 @@ version = call >>16 ;/* hack for backward compatibility */ call &=0xffff ; -if (call <=SEMCTL ) -switch (call) { -case SEMOP : -return sys_semop (first, (struct sembuf *)ptr, second); -case SEMGET : -return sys_semget (first, second, third); -case SEMCTL : { -union semun fourth; -if (!ptr) -return -EINVAL ; -if (get_user (fourth.__pad, (void **) ptr)) -return -EFAULT ; -return sys_semctl (first, second, third, fourth); - } -default : -return -EINVAL ; - } +switch (call) { +case SEMOP : +return sys_semop (first, (struct sembuf *)ptr, second); +case SEMGET : +return sys_semget (first, second, third); +case SEMCTL : { +union semun fourth; +if (!ptr) +return -EINVAL ; +if (get_user (fourth.__pad, (void **) ptr)) +return -EFAULT ; +return sys_semctl (first, second, third, fourth); + } -if (call <=MSGCTL ) -switch (call) { -case MSGSND : -return sys_msgsnd (first, (struct msgbuf *) ptr, - second, third); -case MSGRCV : -switch (version) { -case 0 : { -struct ipc_kludge tmp; -if (!ptr) -return -EINVAL ; - -if (copy_from_user (&tmp, - (struct ipc_kludge *) ptr, -sizeof (tmp))) -return -EFAULT ; -return sys_msgrcv (first, tmp.msgp, second, - tmp.msgtyp, third); - } -default : -return sys_msgrcv (first, - (struct msgbuf *) ptr, - second, fifth, third); - } -case MSGGET : -return sys_msgget ((key_t ) first, second); -case MSGCTL : -return sys_msgctl (first, second, - (struct msqid_ds *) ptr); -default : -return -EINVAL ; - } -if (call <=SHMCTL ) -switch (call) { -case SHMAT : -switch (version) { -default : { -ulong raddr; - ret =sys_shmat (first, (char *) ptr, - second, &raddr); -if (ret) -return ret; -return put_user (raddr, (ulong *) third); - } -case 1 :/* iBCS2 emulator entry point */ -if (!segment_eq (get_fs (),get_ds ())) -return -EINVAL ; -return sys_shmat (first, (char *) ptr, - second, (ulong *) third); - } -case SHMDT : -return sys_shmdt ((char *)ptr); -case SHMGET : -return sys_shmget (first, second, third); -case SHMCTL : -return sys_shmctl (first, second, - (struct shmid_ds *) ptr); -default : -return -EINVAL ; - } - -return -EINVAL ; +case MSGSND : +return sys_msgsnd (first, (struct msgbuf *) ptr, + second, third); +case MSGRCV : +switch (version) { +case 0 : { +struct ipc_kludge tmp; +if (!ptr) +return -EINVAL ; + +if (copy_from_user (&tmp, + (struct ipc_kludge *) ptr, +sizeof (tmp))) +return -EFAULT ; +return sys_msgrcv (first, tmp.msgp, second, + tmp.msgtyp, third); + } +default : +return sys_msgrcv (first, + (struct msgbuf *) ptr, + second, fifth, third); + } +case MSGGET : +return sys_msgget ((key_t ) first, second); +case MSGCTL : +return sys_msgctl (first, second, (struct msqid_ds *) ptr); + +case SHMAT : +switch (version) { +default : { +ulong raddr; + ret =sys_shmat (first, (char *) ptr, second, &raddr); +if (ret) +return ret; +return put_user (raddr, (ulong *) third); + } +case 1 :/* iBCS2 emulator entry point */ +if (!segment_eq (get_fs (),get_ds ())) +return -EINVAL ; +return sys_shmat (first, (char *) ptr, second, (ulong *) third); + } +case SHMDT : +return sys_shmdt ((char *)ptr); +case SHMGET : +return sys_shmget (first, second, third); +case SHMCTL : +return sys_shmctl (first, second, + (struct shmid_ds *) ptr); +default : +return -EINVAL ; + } }/*
include/asm-alpha/shmparam.h +1 -42
48 lines not on this page · raw message
include/asm-arm/proc-armo/shmparam.h +1 -3
@@ -9,9 +9,7 @@#ifndef __ASM_PROC_SHMPARAM_H#define __ASM_PROC_SHMPARAM_H -#ifndef SHM_RANGE_START -#define SHM_RANGE_START 0x00a00000 -#define SHM_RANGE_END 0x00c00000 +#ifndef SHMMAX #define SHMMAX 0x003fa000#endif
include/asm-arm/proc-armv/shmparam.h +1 -3
@@ -10,9 +10,7 @@#ifndef __ASM_PROC_SHMPARAM_H#define __ASM_PROC_SHMPARAM_H -#ifndef SHM_RANGE_START -#define SHM_RANGE_START 0x50000000 -#define SHM_RANGE_END 0x60000000 +#ifndef SHMMAX #define SHMMAX 0x01000000#endif
include/asm-arm/shmparam.h +1 -34
@@ -3,39 +3,6 @@#include <asm/proc/shmparam.h> -/* -* Format of a swap-entry for shared memory pages currently out in -* swap space (see also mm/swap.c). -* -* SWP_TYPE = SHM_SWP_TYPE -* SWP_OFFSET is used as follows: -* -* bits 0..6 : id of shared memory segment page belongs to (SHM_ID) -* bits 7..21: index of page within shared memory segment (SHM_IDX) -* (actually fewer bits get used since SHMMAX is so low) -*/ - -/* -* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and -* there is a static array of size SHMMNI. -*/ -#define _SHM_ID_BITS 7 -#define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1) - -#define SHM_IDX_SHIFT (_SHM_ID_BITS) -#define _SHM_IDX_BITS 15 -#define SHM_IDX_MASK ((1<<_SHM_IDX_BITS)-1) - -/* -* _SHM_ID_BITS + _SHM_IDX_BITS must be <= 24 on the i386 and -* SHMMAX <= (PAGE_SIZE << _SHM_IDX_BITS). -*/ - -#define SHMMIN 1/* really PAGE_SIZE */ /* min shared seg size (bytes) */ -#define SHMMNI (1<<_SHM_ID_BITS)/* max num of segs system wide */ -#define SHMALL /* max shm system wide (pages) */ \ - (1<<(_SHM_IDX_BITS+_SHM_ID_BITS)) -#define SHMLBA PAGE_SIZE/* attach addr a multiple of this */ -#define SHMSEG SHMMNI/* max shared segs per process */ +#define SHMLBA PAGE_SIZE/* attach addr a multiple of this */ #endif /* _ASMARM_SHMPARAM_H */
include/asm-i386/shmparam.h +1 -41
47 lines not on this page · raw message
include/asm-m68k/shmparam.h +1 -44
50 lines not on this page · raw message
include/asm-mips/shmparam.h +0 -40
@@ -1,49 +1,9 @@#ifndef __ASM_MIPS_SHMPARAM_H#define __ASM_MIPS_SHMPARAM_H -/* address range for shared memory attaches if no address passed to shmat() */ -#define SHM_RANGE_START 0x50000000 -#define SHM_RANGE_END 0x60000000 - -/* -* Format of a swap-entry for shared memory pages currently out in -* swap space (see also mm/swap.c). -* -* SWP_TYPE = SHM_SWP_TYPE -* SWP_OFFSET is used as follows: -* -* bits 0..6 : id of shared memory segment page belongs to (SHM_ID) -* bits 7..21: index of page within shared memory segment (SHM_IDX) -* (actually fewer bits get used since SHMMAX is so low) -*/ - -/* -* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and -* there is a static array of size SHMMNI. -*/ -#define _SHM_ID_BITS 7 -#define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1) - -#define SHM_IDX_SHIFT (_SHM_ID_BITS) -#define _SHM_IDX_BITS 15 -#define SHM_IDX_MASK ((1<<_SHM_IDX_BITS)-1) - -/* -* _SHM_ID_BITS + _SHM_IDX_BITS must be <= 24 on the i386 and -* SHMMAX <= (PAGE_SIZE << _SHM_IDX_BITS). -*/ - -#define SHMMAX 0x2000000/* max shared seg size (bytes) */ -/* Try not to change the default shipped SHMMAX - people rely on it */ - -#define SHMMIN 1/* really PAGE_SIZE */ /* min shared seg size (bytes) */ -#define SHMMNI (1<<_SHM_ID_BITS)/* max num of segs system wide */ -#define SHMALL /* max shm system wide (pages) */ \ - (1<<(_SHM_IDX_BITS+_SHM_ID_BITS))/* * This constant is very large but the ABI in it's wisdom says ... */ #define SHMLBA 0x40000/* attach addr a multiple of this */ -#define SHMSEG SHMMNI/* max shared segs per process */ #endif /* __ASM_MIPS_SHMPARAM_H */
include/asm-ppc/shmparam.h +1 -39
@@ -1,44 +1,6 @@#ifndef _PPC_SHMPARAM_H#define _PPC_SHMPARAM_H -/* address range for shared memory attaches if no address passed to shmat() */ -#define SHM_RANGE_START 0x50000000 -#define SHM_RANGE_END 0x60000000 - -/* -* Format of a swap-entry for shared memory pages currently out in -* swap space (see also mm/swap.c). -* -* SWP_TYPE = SHM_SWP_TYPE -* SWP_OFFSET is used as follows: -* -* bits 0..6 : id of shared memory segment page belongs to (SHM_ID) -* bits 7..21: index of page within shared memory segment (SHM_IDX) -* (actually fewer bits get used since SHMMAX is so low) -*/ - -/* -* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and -* there is a static array of size SHMMNI. -*/ -#define _SHM_ID_BITS 7 -#define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1) - -#define SHM_IDX_SHIFT (_SHM_ID_BITS) -#define _SHM_IDX_BITS 15 -#define SHM_IDX_MASK ((1<<_SHM_IDX_BITS)-1) - -/* -* _SHM_ID_BITS + _SHM_IDX_BITS must be <= 24 on the i386 and -* SHMMAX <= (PAGE_SIZE << _SHM_IDX_BITS). -*/ - -#define SHMMAX 0x2000000/* max shared seg size (bytes) */ -#define SHMMIN 1/* really PAGE_SIZE */ /* min shared seg size (bytes) */ -#define SHMMNI (1<<_SHM_ID_BITS)/* max num of segs system wide */ -#define SHMALL /* max shm system wide (pages) */ \ - (1<<(_SHM_IDX_BITS+_SHM_ID_BITS)) -#define SHMLBA PAGE_SIZE/* attach addr a multiple of this */ -#define SHMSEG SHMMNI/* max shared segs per process */ +#define SHMLBA PAGE_SIZE/* attach addr a multiple of this */ #endif /* _PPC_SHMPARAM_H */
include/asm-sh/shmparam.h +1 -41
47 lines not on this page · raw message
include/asm-sparc/shmparam.h +1 -39
@@ -2,44 +2,6 @@#ifndef _ASMSPARC_SHMPARAM_H#define _ASMSPARC_SHMPARAM_H -/* address range for shared memory attaches if no address passed to shmat() */ -#define SHM_RANGE_START 0x10000000 -#define SHM_RANGE_END 0x20000000 - -/* -* Format of a swap-entry for shared memory pages currently out in -* swap space (see also mm/swap.c). -* -* SWP_TYPE = SHM_SWP_TYPE -* SWP_OFFSET is used as follows: -* -* bits 0..6 : id of shared memory segment page belongs to (SHM_ID) -* bits 7..21: index of page within shared memory segment (SHM_IDX) -* (actually fewer bits get used since SHMMAX is so low) -*/ - -/* -* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and -* there is a static array of size SHMMNI. -*/ -#define _SHM_ID_BITS 7 -#define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1) - -#define SHM_IDX_SHIFT (_SHM_ID_BITS) -#define _SHM_IDX_BITS 15 -#define SHM_IDX_MASK ((1<<_SHM_IDX_BITS)-1) - -/* -* _SHM_ID_BITS + _SHM_IDX_BITS must be <= 24 on the i386 and -* SHMMAX <= (PAGE_SIZE << _SHM_IDX_BITS). -*/ - -#define SHMMAX 0x1000000/* max shared seg size (bytes) */ -#define SHMMIN 1/* really PAGE_SIZE */ /* min shared seg size (bytes) */ -#define SHMMNI (1<<_SHM_ID_BITS)/* max num of segs system wide */ -#define SHMALL /* max shm system wide (pages) */ \ - (1<<(_SHM_IDX_BITS+_SHM_ID_BITS)) -#define SHMLBA PAGE_SIZE/* attach addr a multiple of this */ -#define SHMSEG SHMMNI/* max shared segs per process */ +#define SHMLBA PAGE_SIZE/* attach addr a multiple of this */ #endif /* _ASMSPARC_SHMPARAM_H */
include/asm-sparc64/shmparam.h +0 -40
@@ -2,46 +2,6 @@#ifndef _ASMSPARC64_SHMPARAM_H#define _ASMSPARC64_SHMPARAM_H -/* XXX Redo most of this... */ - -/* address range for shared memory attaches if no address passed to shmat() */ -#define SHM_RANGE_START 0x10000000 -#define SHM_RANGE_END 0x20000000 - -/* -* Format of a swap-entry for shared memory pages currently out in -* swap space (see also mm/swap.c). -* -* SWP_TYPE = SHM_SWP_TYPE -* SWP_OFFSET is used as follows: -* -* bits 0..6 : id of shared memory segment page belongs to (SHM_ID) -* bits 7..21: index of page within shared memory segment (SHM_IDX) -* (actually fewer bits get used since SHMMAX is so low) -*/ - -/* -* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and -* there is a static array of size SHMMNI. -*/ -#define _SHM_ID_BITS 7 -#define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1) - -#define SHM_IDX_SHIFT (_SHM_ID_BITS) -#define _SHM_IDX_BITS 15 -#define SHM_IDX_MASK ((1<<_SHM_IDX_BITS)-1) - -/* -* _SHM_ID_BITS + _SHM_IDX_BITS must be <= 24 on the i386 and -* SHMMAX <= (PAGE_SIZE << _SHM_IDX_BITS). -*/ - -#define SHMMAX 0x1000000/* max shared seg size (bytes) */ -#define SHMMIN 1/* really PAGE_SIZE */ /* min shared seg size (bytes) */ -#define SHMMNI (1<<_SHM_ID_BITS)/* max num of segs system wide */ -#define SHMALL /* max shm system wide (pages) */ \ - (1<<(_SHM_IDX_BITS+_SHM_ID_BITS))#define SHMLBA (PAGE_SIZE<<1)/* attach addr a multiple of this */ -#define SHMSEG SHMMNI/* max shared segs per process */ #endif /* _ASMSPARC64_SHMPARAM_H */
include/linux/shm.h +11 -9
@@ -3,6 +3,17 @@#include <linux/ipc.h> +/* +* SHMMAX, SHMMNI and SHMALL are upper limits are defaults which can +* be increased by sysctl +*/ + +#define SHMMAX 0x2000000/* max shared seg size (bytes) */ +#define SHMMIN 1/* really PAGE_SIZE */ /* min shared seg size (bytes) */ +#define SHMMNI 128/* max num of segs system wide */ +#define SHMALL (SHMMAX/PAGE_SIZE*SHMMNI)/* max shm system wide (pages) */ +#define SHMSEG SHMMNI/* max shared segs per process */ +#include <asm/shmparam.h> struct shmid_ds {
@@ -17,15 +28,6 @@unsigned short shm_unused;/* compatibility */ void *shm_unused2;/* ditto - used by DIPC */ void *shm_unused3;/* unused */ -}; - -struct shmid_kernel -{ -struct shmid_ds u; -/* the following are private */ -unsigned long shm_npages;/* size of segment (pages) */ -pte_t *shm_pages;/* array of ptrs to frames -> SHMMAX */ -struct vm_area_struct *attaches;/* descriptors for attaches */ };/* permission flag for shmget */
include/linux/swap.h +0 -11
@@ -122,17 +122,6 @@asmlinkage long sys_swapoff (const char *);asmlinkage long sys_swapon (const char *,int ); -/* -* vm_ops not present page codes for shared memory. -* -* Will go away eventually.. -*/ -#define SHM_SWP_TYPE 0x20 - -/* -* swap cache stuff (in linux/mm/swap_state.c) -*/ -#define SWAP_CACHE_INFO #ifdef SWAP_CACHE_INFO
include/linux/sysctl.h +1 -2
@@ -103,8 +103,7 @@KERN_MSGPOOL =37 ,/* int: Maximum system message pool size */ KERN_SYSRQ =38 ,/* int: Sysreq enable */ KERN_MAX_THREADS =39 ,/* int: Maximum nr of threads in the system */ -KERN_RANDOM =40 ,/* Random driver */ - KERN_SHMALL=41 /* int: Maximum size of shared memory */ + KERN_RANDOM=40 /* Random driver */ };
ipc/shm.c +189 -75
537 lines not on this page · raw message
ipc/util.c +2 -0
@@ -14,6 +14,8 @@#include <linux/init.h> #include <linux/msg.h> +#include "util.h" +#if defined(CONFIG_SYSVIPC )extern void sem_init (void ),msg_init (void ),shm_init (void );
ipc/util.h +12 -0
@@ -0,0 +1,12 @@ +/* +* linux/ipc/util.h +* Copyright (C) 1999 Christoph Rohland +*/ + +/* +* IPCMNI is the absolute maximum for ipc identifier. This is used to +* detect stale identifiers +*/ +#define IPCMNI (1<<15) + +extern int ipcperms (struct ipc_perm *ipcp,short shmflg);
kernel/sysctl.c +2 -2
@@ -49,7 +49,7 @@extern int sg_big_buff;#endif #ifdef CONFIG_SYSVIPC -extern size_t shmmax; +extern size_t shm_prm[];#endif #ifdef __sparc__
@@ -213,7 +213,7 @@ {KERN_RTSIGMAX ,"rtsig-max" , &max_queued_signals,sizeof (int ), 0644, NULL, &proc_dointvec}, #ifdef CONFIG_SYSVIPC - {KERN_SHMMAX, "shmmax", &shmmax, sizeof (size_t), + {KERN_SHMMAX, "shmmax", &shm_prm, 3*sizeof (size_t), 0644, NULL, &proc_doulongvec_minmax}, #endif #ifdef CONFIG_MAGIC_SYSRQ
mm/swap_state.c +0 -4
@@ -68,8 +68,6 @@if (!entry.val) goto out; type =SWP_TYPE (entry); -if (type &SHM_SWP_TYPE ) - goto out;if (type >= nr_swapfiles) goto bad_file; p = type + swap_info;
@@ -115,8 +113,6 @@if (!entry.val) goto bad_entry; type =SWP_TYPE (entry); -if (type &SHM_SWP_TYPE ) - goto out;if (type >= nr_swapfiles) goto bad_file; p = type + swap_info;
mm/swapfile.c +0 -4
@@ -135,8 +135,6 @@ goto out; type =SWP_TYPE (entry); -if (type &SHM_SWP_TYPE ) - goto out;if (type >= nr_swapfiles) goto bad_nofile; p = & swap_info[type];
@@ -190,8 +188,6 @@ goto new_swap_entry; entry.val = page->index; type =SWP_TYPE (entry); -if (type &SHM_SWP_TYPE ) - goto new_swap_entry;if (type >= nr_swapfiles) goto new_swap_entry; p = type + swap_info;
--Multipart_Wed_Nov__3_20:17:09_1999-1--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/