* Is it a bug (about share memory)?
@ 2003-08-22 8:15 Zheng, Jeff
2003-08-24 9:48 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Zheng, Jeff @ 2003-08-22 8:15 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1236 bytes --]
Hi,
I tried to use share memory to check vm overcommit by check Committed_AS in /proc/meminfo. It seems that attach of share momory will add the value of Committed_AS but detach of share memory does not reduce the value of Committed_AS. Below is the result (attached file is source of the command)
[root@hpi overcommit_basic]# ./shm 5000000 m
The value of Committed_AS is 100436 KB before attach
The value of Committed_AS is 105384 KB After attach
[root@hpi overcommit_basic]# ./shm 5000000 m
The value of Committed_AS is 105520 KB before attach
The value of Committed_AS is 105520 KB After attach
[root@hpi overcommit_basic]# ./shm 5000000 n
The value of Committed_AS is 105416 KB before attach
The value of Committed_AS is 110364 KB After attach
the first parm is size of share memory, the second parm is proj of API ftok. When I allocate 5M, Committed_AS add 5M. The issue is: when I detach the share memory, and there is no other process attach to the share memory, Committed_AS does not reduce 5M.
Inactive of /proc/meminfo also changed.
My kernel is 2.5.70. And it seems that all kernel is the same.
Thanks
Jeff Jeff.Zheng@intel.com
BTW, I speak for myself, not for Intel Corp.
[-- Attachment #2: shm.c --]
[-- Type: application/octet-stream, Size: 1733 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define SHM_SIZE 1024 /* make it a 1K shared memory segment */
int GetValue(char *n) {
char s[200],*p;
FILE *f;
int value,len;
f=fopen("/proc/meminfo", "r");
while ((p=fgets(s, 200, f)) != NULL) {
len=strlen(n);
if (strncmp(n, p, len)==0) {
p+=len+1;
while (isspace(*p)) p++;
value=atol(p);
fclose(f);
return(value);
}
}
fclose(f);
return 0;
}
int main(int argc, char *argv[])
{
key_t key;
int shmid;
char *data,*p;
int mode;
int memsize,committed_as;
int i;
if (argc > 3) {
fprintf(stderr, "usage: shmdemo [data_to_write] [proj_of_ftok]\n");
exit(1);
}
committed_as=GetValue("Committed_AS");
printf("The value of Committed_AS is %d KB before attach\n", committed_as);
memsize = atol(argv[1]);
/* make the key: */
if ((key = ftok("/tmp/shm.tmp", *argv[2])) == -1) {
perror("ftok");
exit(1);
}
/* connect to (and possibly create) the segment: */
if ((shmid = shmget(key, memsize, 0644 | IPC_CREAT)) == -1) {
perror("shmget");
exit(1);
}
/* attach to the segment to get a pointer to it: */
p = data = shmat(shmid, (void *)0, 0);
if (data == (char *)(-1)) {
perror("shmat");
exit(1);
}
for (i=0; i< memsize-10; i++)
*p++ = 'a';
committed_as=GetValue("Committed_AS");
printf("The value of Committed_AS is %d KB After attach\n", committed_as);
/* detach from the segment: */
if (shmdt(data) == -1) {
perror("shmdt");
exit(1);
}
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Is it a bug (about share memory)?
2003-08-22 8:15 Is it a bug (about share memory)? Zheng, Jeff
@ 2003-08-24 9:48 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2003-08-24 9:48 UTC (permalink / raw)
To: Zheng, Jeff; +Cc: linux-kernel
"Zheng, Jeff" <jeff.zheng@intel.com> wrote:
>
> I tried to use share memory to check vm overcommit by check Committed_AS
> in /proc/meminfo. It seems that attach of share momory will add the value
> of Committed_AS but detach of share memory does not reduce the value of
> Committed_AS.
shmdt() will not release resources. Run `ipcs' after your test app and you
will see the shm segment is still there.
Release it with ipcrm and Committed_AS falls back as expected.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-08-24 9:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-22 8:15 Is it a bug (about share memory)? Zheng, Jeff
2003-08-24 9:48 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).