このページを編集する際は、[[編集に関する方針]]に従ってください。
*概要 [#k40a073f]
-対象:8.1.4
-言語:C
-宣言・定義:[[postgresql-8.1.4/src/backend/port/sysv_shmem.c]]
-(概要を書いてください。)
*引数 [#sdf52378]
-IpcMemoryKey memKey --
-Size size --
*実装 [#f010cb85]
static void *
InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
-[[IpcMemoryKey/postgresql-8.1.4]] -- key_tの別名
-[[Size/postgresql-8.1.4]] -- size_tの別名
{
IpcMemoryId shmid;
-[[IpcMemoryId/postgresql-8.1.4]] -- intの別名
void *memAddress;
shmid = shmget(memKey, size, IPC_CREAT | IPC_EXCL | IPCProtection);
-shmget(), IPC_CREAT, IPC_EXCL -- sys/ipc.h または sys/shm.h で定義。下記説明は、http://www.linux.or.jp/JM/html/LDP_man-pages/man2/semget.2.htmlより引用(赤字部分を追記)。
-- &color(red){(shmget()は)}; セマフォ集合の識別子を取得する関数。
--IPC_CREAT が指定されていて、 key &color(red){(memKey)}; に対応するセマフォ集合が存在しない場合、 nsems &color(red){(size)}; 個のセマフォからなる新しい集合が作成される。
--IPC_CREAT と IPC_EXCL の両方が指定された場合、 key &color(red){(memKey)}; に対応するセマフォ集合が既に存在すると、 semget() は失敗し、 errno に EEXIST が設定される 。
-[[IPCProtection/postgresql-8.1.4]] -- 定数0600。
if (shmid < 0)
{
/*
* Fail quietly if error indicates a collision with existing segment.
* One would expect EEXIST, given that we said IPC_EXCL, but perhaps
* we could get a permission violation instead? Also, EIDRM might
* occur if an old seg is slated for destruction but not gone yet.
*/
if (errno == EEXIST || errno == EACCES
#ifdef EIDRM
|| errno == EIDRM
-errno, EEXIST, EACCES, EIDRM -- errnoはUNIXで標準的に提供されている、直近に発生したエラーを格納するグローバル変数([[ソースコードの中に定義がない:errno/解読日記]]を参照)。下記説明は、http://www.linux.or.jp/JM/html/LDP_man-pages/man3/errno.3.htmlより引用。
--EACCES 許可がない (POSIX.1)
--EEXIST ファイルが存在する (POSIX.1)
--EIDRM 識別子が削除された (POSIX.1)
#endif
)
return NULL;
/*
* Else complain and abort
*/
ereport(FATAL,
-[[ereport()/postgresql-8.1.4]]
(errmsg("could not create shared memory segment: %m"),
errdetail("Failed system call was shmget(key=%lu, size=%lu, 0%o).",
(unsigned long) memKey, (unsigned long) size,
IPC_CREAT | IPC_EXCL | IPCProtection),
(errno == EINVAL) ?
errhint("This error usually means that PostgreSQL's request for a shared memory "
"segment exceeded your kernel's SHMMAX parameter. You can either "
"reduce the request size or reconfigure the kernel with larger SHMMAX. "
"To reduce the request size (currently %lu bytes), reduce "
"PostgreSQL's shared_buffers parameter (currently %d) and/or "
"its max_connections parameter (currently %d).\n"
"If the request size is already small, it's possible that it is less than "
"your kernel's SHMMIN parameter, in which case raising the request size or "
"reconfiguring SHMMIN is called for.\n"
"The PostgreSQL documentation contains more information about shared "
"memory configuration.",
(unsigned long) size, NBuffers, MaxBackends) : 0,
(errno == ENOMEM) ?
errhint("This error usually means that PostgreSQL's request for a shared "
"memory segment exceeded available memory or swap space. "
"To reduce the request size (currently %lu bytes), reduce "
"PostgreSQL's shared_buffers parameter (currently %d) and/or "
"its max_connections parameter (currently %d).\n"
"The PostgreSQL documentation contains more information about shared "
"memory configuration.",
(unsigned long) size, NBuffers, MaxBackends) : 0,
(errno == ENOSPC) ?
errhint("This error does *not* mean that you have run out of disk space. "
"It occurs either if all available shared memory IDs have been taken, "
"in which case you need to raise the SHMMNI parameter in your kernel, "
"or because the system's overall limit for shared memory has been "
"reached. If you cannot increase the shared memory limit, "
"reduce PostgreSQL's shared memory request (currently %lu bytes), "
"by reducing its shared_buffers parameter (currently %d) and/or "
"its max_connections parameter (currently %d).\n"
"The PostgreSQL documentation contains more information about shared "
"memory configuration.",
(unsigned long) size, NBuffers, MaxBackends) : 0));
}
/* Register on-exit routine to delete the new segment */
on_shmem_exit(IpcMemoryDelete, Int32GetDatum(shmid));
/* OK, should be able to attach to the segment */
memAddress = shmat(shmid, NULL, PG_SHMAT_FLAGS);
if (memAddress == (void *) -1)
elog(FATAL, "shmat(id=%d) failed: %m", shmid);
/* Register on-exit routine to detach new segment before deleting */
on_shmem_exit(IpcMemoryDetach, PointerGetDatum(memAddress));
/* Record key and ID in lockfile for data directory. */
RecordSharedMemoryInLockFile((unsigned long) memKey,
(unsigned long) shmid);
return memAddress;
}
*呼出元 [#t44d5d2a]
-[[PGSharedMemoryCreate()/postgresql-8.1.4]]
*備考 [#m3fc44bf]
/*
* InternalIpcMemoryCreate(memKey, size)
*
* Attempt to create a new shared memory segment with the specified key.
* Will fail (return NULL) if such a segment already exists. If successful,
* attach the segment to the current process and return its attached address.
* On success, callbacks are registered with on_shmem_exit to detach and
* delete the segment when on_shmem_exit is called.
*
* If we fail with a failure code other than collision-with-existing-segment,
* print out an error and abort. Other types of errors are not recoverable.
*/
*履歴 [#h7a3a129]
-作者:[[/ページ作者]]
-日付:????/?/?
|更新日|更新者|更新内容|
||||