Thursday, November 24. 2005How much memory can a process use?Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Normally, yes. Here: Well, not really.
The program is designed to allocate memory until it fails. Usually, it fails not within the malloc(), but within the memset(). Linux will overcommit, meaning it promises more memory to the process than it can deliver, and the memset() makes sure that each byte of promised memory is being used by writing to it. The Linux OOM killer will then kill this process, and this happens usually within the memset() where the REAL allocation goes on.
faberman is right. if you want it to fail during the memset properly you need to check malloc () else memset might fail because you're passing it NULL as a destination address. the loop would look better this way:
while ((waste = malloc(STEP*MB)) != NULL) { memset(waste,1,STEP*MB); counter+=STEP; printf("%i MB wasted\n",counter); } That way the loop would terminate if malloc() fails. Because if malloc fails, memset will fail, but it won't fail because of the OOM killer. It will fail because you called it improperly. chances are the OOM killer will kill on a memset before this happens, but it is entirely possible, so for the code to work right every time, you need to check malloc () Also the cast to (char *) is redundant. |
QuicksearchComments
about Wed, 31.10.2012 13:46
My friendly Offtopic Channel
in IRC has horror stories
about this, it is Halloween,
after all.
"Well, I do
have [...]
about Mon, 15.10.2012 09:41
What if we use SSDs. Can we
then assume memory limits
are not as significant
because SSDs can handle
random access [...]
about Fri, 05.10.2012 07:46
In fact, I am pretty certain
that this also breaks
mysql_upgrade or has the
potential to do so.
about Fri, 05.10.2012 06:44
It is quite a bit worse than
that: Right now, the default
RPM as distributed by Oracle
will fail to install if it
[...]
about Thu, 04.10.2012 18:52
> MyISAM in mysql.* has to go
before GTID can be
sucessfully deployed.
I
think you meant to say
before it can b [...]
about Thu, 04.10.2012 18:36
Sorry, it wasn't clear given
that none of this is
actually mentioned.
about Thu, 04.10.2012 13:47
You can turn it on with FLUSH
PRIVILEGES once the tables
exist.
about Thu, 04.10.2012 11:34
I think I have to install a
comment voting plugin just
so that i can +1 what Justin
just wrote.
Categories
Blog AdministrationDisclaimerAll examples, code-snippets, advice, trivia, etc. are supplied in the hope that they are useful, but no warranty of any kind is given. Use of trademarks is not intended as a challenge to them.
ImpressumCopyright 2005-2012 bei den jeweiligen Autorinnen der Beiträge. Die Infrastruktur von MySQL-dump wird betrieben von:
Azundris, Immanuelkirchstraße 18, 10405 Berlin, Germany
|