From: "Zheng, Jeff" <jeff.zheng@intel.com>
To: <linux-kernel@vger.kernel.org>
Subject: Is it a bug (about share memory)?
Date: Fri, 22 Aug 2003 16:15:18 +0800 [thread overview]
Message-ID: <37FBBA5F3A361C41AB7CE44558C3448E011958E9@pdsmsx403.ccr.corp.intel.com> (raw)
[-- 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;
}
next reply other threads:[~2003-08-22 8:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-22 8:15 Zheng, Jeff [this message]
2003-08-24 9:48 ` Is it a bug (about share memory)? Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=37FBBA5F3A361C41AB7CE44558C3448E011958E9@pdsmsx403.ccr.corp.intel.com \
--to=jeff.zheng@intel.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).