820 likes | 1.06k Views
System Config IPC. Iris Zhu iris.zhu@sun.com. Agenda. IPC Overview System V IPC Posix IPC Tools for performance analysis System configuration Hands On Lab. Process overview. Concept Execution of program Fundamental abstraction of unix system Basic unit Process
E N D
System Config IPC • Iris Zhu • iris.zhu@sun.com
Agenda • IPC Overview • System V IPC • Posix IPC • Tools for performance analysis • System configuration • Hands On Lab
Process overview Concept Execution of program Fundamental abstraction of unix system Basic unit Process Virtual memory environment Resource for Process Memory Open file list Thread
IPC history Message passing Pipe,named pipe(FIFO) System V message queue Posix message queue(1003.1b-1993) RPC Data synchronization System V semaphore,System V shared memory Posix semaphore
Inter Process Communication Function Sharing of data shared memory Exchange Information and data Pipe,FIFO,message queues Synchronization of access to shared resources semaphore,mutex,lock, Remote procedure call Sun RPC,Solaris Door
IPC object persistence Process-persistent Pipe FIFO Kernel persistent System V Shared memory System V Message queue System V Semaphore Filesystem persistent
Pipe • Special type of file that do not hold data but can be opened by 2 different processed so that data can be passed between them. • API • Int pipe(int fd[2]); • Fd[0] – read Fd[1] – write //For example: • Feature • Half duplex. • Atomic operation. • Usable between processes with the same parent.
Named pipe - FIFO • Provide a bidirectional communication path between processed on the same system. • API • Int mkfifo(const char *pathname,mode_t mode); • fopen/fclose //For example: • Features • Half duplex • Automatic block • SIGPIPE is generated if a process write to a pipe and read is terminated • Atomic operation
Other commands to get system variables • limit(csh)/unlimit(sh/bash/ksh) • Sysdef • lists all hardware devices, as well as pseudo devices, system devices, loadable modules, and the values of selected kernel tunable parameters. • For example,sysdef(1M) //For exercise: • Getconf • get configuration values • For example,getconf(1) • getconf OPEN_MAX //For exercise:
Doors • Provide a facility for processes to issue procedure calls to functions in other processes running on the same system. //Sun Solaris OS • Overview
Agenda • IPC Overview • System V IPC* • Posix IPC • Tools for performance analysis • System configuration • Hands On Lab
Types System V shared memory System V message queues System V semaphore API System V IPC Overview
System V IPC overview key_t and ftok #include <sys/ipc.h> key_t ftok (const char * pathname,int id); Create and open IPC key=id(8bit)+st_dev(12bit)+st_ino(12bit)
Data structure in kernel for IPC • ipc_perm data structure in /usr/include/sys/ipc.h
System V shared memory Concept sharing the same physical(RAM) memory pages by multi processes Feature Extremely efficient(*) Dynamically loaded when required,eg.modload Unload when system reboot or by command modunload Kernel resource consumption Shmid actual shared RAM pages data structure about the shared segment
System V shared memory - API • Header file and system calls #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> int shmget(key_t key, size_t size, int shmflg); void *shmat(int shmid, const void *shmaddr, int shmflg); int shmctl(int shmid, int cmd, struct shmid_ds *buf); int shmdt(char *shmaddr);
Data structure Struct shmid_ds{ struct ipc_perm shm_perm /* operation permission structure */ size_t shm_segsz /* size of segment in bytes */ pid_t shm_lpid /* process ID of last shared memory operation */ pid_t shm_cpid /* process ID of creator */ shmatt_t shm_nattch /* number of current attaches */ time_t shm_atime /* time of last shmat() */ time_t shm_dtime /* time of last shmdt() */ time_t shm_ctime /* time of last change by shmctl() */ }
System overheads with shared memory User level Quantity of created shared memory Size Kernel level System memory Quantity of identifiers Max size for shared memory segment Translation table of shared memory Swap space
System tunable parameters System profile(before Solaris 10) /etc/system
Caveat Static mechanism Values specified are read and applied when system boot. Any changes are not applied until the system reboot Values specified in /etc/system are global and affect all processes on the system The obsolete tunable settings are ignored from Solaris 10.
Resource control available Dynamically resource control Prctl(1) get or set the resource controls of running processes, tasks, and projects rctladm(1M) display or modify global state of system resource controls Man resource_controls(5) Setrctl(2) API,set or get resource control values Man rctlblk_get_local_action(3C)
Dynamic resource control Settings in Solaris 10
Optimization of shared memory - ISM Concept ISM - Intimate shared memory Sharing of the translation tables involved in virtual-to-physical address translation No need to share the actual physical memory pages Contrast Non-ISM per-processes mapping for shared memory pages
Background introduction – memory basic MMU • - Virtual memory management unit • Management and translation of the virtual view of memory(address space) to physical memory. HAT • - Hardware address translation layer • Management mapping of virtual to physical memory TLB • - Translation lookaside buffer • Hardware cache of recent address translation information
ISM Sharing the memory translation table
Feature Avoid generate redundant mappings to physical pages Intimate shared memory is an important optimization that makes more efficient use of the kernel and hardware resources involved in the implementation of virtual memory and provides a means of keeping heavily used shared pages locked in memory. Large page size automatically enabled ISM
Example - ISM used for Database Without ISM 400 database processes 2GB shared segment ~262144 8KB pages 8Bytes for each page mapping-->2M 2M*400 800Mbytes for mapping! With ISM 2Mbytes only.
System V message queues Concept For process to send and receive messages in various size in an asynchronous fashion. Feature Dramatical loadable module Depends on /kernel/sys/msgsys /kernel/misc/ipc Kernel resource consumption Kernel memory Resource map
System V IPC - message queue API Header file and system calls #include <sys/msg.h> int msgget(key_t key, int msgflg); int msgctl(int msqid, int cmd, struct msqid_ds *buf); int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); size_t msgrcv(int msqid, void *msgp, size_t msgsz, long int msgtyp, int msgflg); More available from man page e,g, man msg
Data Structure Struct msqid_ds{ Struct ipc_perm msg_perm; /*read-write perms*/ Struct msg msg_first; /ptr to first message on queue*/ Struct msg *msg_last; /ptr to last message on queue*/ msglen_t msg_cbytes;/*current #bytes on queue*/ msgqnum_t msg_qnum; /*current #of messages on queue*/ msglen_t msg_qbytes;/*max # of bytes allowed on queue*/ pid_t msg_lspid; /*pid of last msgsnd()*/ pid_t msg_lrpid; /*pid of last msgrcv()*/ time_t msg_stime; /*time of last msgsnd()*/ time_t msg_rtime; /*time of last msgrcv()*/ time_t msg_ctime; /*pid of last msgctl()*/ }
System overhead with message queues Kernel memory check first,no greater than 25% available kernel memory Resource map Identifier msqid_ds sys/msg.h Struct msg
System tunable parameter /etc/system
Available resource control process.max-msg-messages msginfo_msgtql(obsolete) maximum number of messages on a message queue process.max-msg-qbytes msginfo_msgmnb(obsolete) maximum number of bytes of messages on a message queue project.max-msg-ids msginfo_msgmni(obsolete) maximum number of message queue Ids allowed for a project
System V Semaphore Concept mechanical signaling device or a means of doing visual signaling. A method of synchronizing to a sharable resource by multi processes. Feature P – try or attempt; V – increase Semaphore sets available Kernel resource consumption Kernel memory Resource map
System V IPC semaphore -API • Header file and system calls #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> int semget(key_t key, int nsems, int semflg); int semctl(int semid, int semnum, int cmd, ...); int semop(int semid, struct sembuf *sops, size_t nsops); • More available from man page • Man sem • e,g.semget(2)
System V semaphore Binary semaphore 0 or 1,like mutex Counting semaphore 0~system limitation ,P/V Set of counting semaphores One or more,each set has a limitation
Data structures for semaphore Struct semid_ds Struct sem_buf
System overhead with semaphore Kernel memory Must less than 25% of kernel memory Resource map allocation Sem structure based on semmns Identifier semid_ds Undo structure pointer Undo structure themselves Kernel mutex lock
System tunable parameter /etc/system(part)