473,809 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

/var/adm/wtmp, malloc, and ENOMEM

Greetings,

/var/adm/wtmp files were getting out of hand
and I wanted to filter the file rather than zeroing it out.
I found some code that would only keep the last x days
but it required creating a temporary file in /tmp
and then copying it back to /var/adm. I rewrote the code
to load the contents of the wtmp file into memory and then
write the filtered records in memory directly back to /var/adm/wtmp,
eliminating the need for a temporary file.

This worked great until I encountered a wtmp file that was
370 MB. malloc fails setting errno to ENOMEM (not enough
storage space). My system has 16GB of memory and 9GB of paging
(33% used). So, I should have plenty of memory.

My question: is there a workaround for this type of malloc error.
Thanks,
Maja

Nov 14 '05 #1
6 4164

"Maja" <ma********@yah oo.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
<snip>
This worked great until I encountered a wtmp file that was
370 MB. malloc fails setting errno to ENOMEM (not enough
storage space). My system has 16GB of memory and 9GB of paging
(33% used). So, I should have plenty of memory.


Hmmm... By the sound of it (you do not provide the actual call to malloc
which fails), i'd say you're right and this is a bug somewhere. However, in
order to make a specific diagnosis, i'd need to know which implementation of
'malloc' you are using (there are quite a few around) and check it out.
Something i'm not planning to do.

The call *should* succeed, AFAICT, so if it doesn't, it's an implementation
issue,you can best pass on to the vendor of your compiler or ask this
question again on a newsgroup that is dedicated to your OS/compiler.

HTH (a tiny bit)

regards,

dandelion.
Nov 14 '05 #2
Maja wrote:
Greetings,

/var/adm/wtmp files were getting out of hand
and I wanted to filter the file rather than zeroing it out.
I found some code that would only keep the last x days
but it required creating a temporary file in /tmp
and then copying it back to /var/adm. I rewrote the code
to load the contents of the wtmp file into memory and then
write the filtered records in memory directly back to /var/adm/wtmp,
eliminating the need for a temporary file.

This worked great until I encountered a wtmp file that was
370 MB. malloc fails setting errno to ENOMEM (not enough
storage space). My system has 16GB of memory and 9GB of paging
(33% used). So, I should have plenty of memory.

My question: is there a workaround for this type of malloc error.
Thanks,
Maja


Your answer is system specific. You probably would get a better answer
in (looking at what you have) comp.unix.progr ammer. That said, I think
the temporary file is good, because you may some day hit a file big
enough (say, > 2 or 4 GB) that you'd likely have problems with, at least
on a 32 bit machine.

[OT] -- I can reproduce the behavior on linux if I set "ulimit -v" to
something less than the amount I'm trying to malloc. Perhaps
you have some limits imposed that way... If that doesn't help,
perhaps you have some issues in your standard library malloc...

-David
Nov 14 '05 #3
On Fri, 10 Dec 2004 06:56:55 -0800, Maja wrote:
Greetings,

/var/adm/wtmp files were getting out of hand
and I wanted to filter the file rather than zeroing it out.
I found some code that would only keep the last x days
but it required creating a temporary file in /tmp
and then copying it back to /var/adm. I rewrote the code
to load the contents of the wtmp file into memory and then
write the filtered records in memory directly back to /var/adm/wtmp,
eliminating the need for a temporary file.

This worked great until I encountered a wtmp file that was
370 MB. malloc fails setting errno to ENOMEM (not enough
storage space). My system has 16GB of memory and 9GB of paging
(33% used). So, I should have plenty of memory.
The limitations on what malloc() can allocate are down to your platform,
well beyond the scope of the C language itself. Perhaps there are
configurable per-process limits etc. Also, if you are only storing
filtered records in memory the memory used would most likely be less,
perhaps a lot less, than 370MB. Perhaps you have a bug in your code and
you are requesting much more memory than you thought. That's easy to log.
My question: is there a workaround for this type of malloc error.


Request less memory or configure your system to allow more memory to be
requested.

However I question the whole approach of storing the data in memory. If
your program has a problem after it starts to write data back to wtmp the
data not written will be lost. Writing to a temporary file is a much
better approach. Just write to a temporary file in /var/adm and rename the
file back to wtmp when complete. This could well be MORE efficient than
storing large amounts of data in memory before writing, if efficiency is
your concern.

Lawrence

Nov 14 '05 #4
"Maja" <ma********@yah oo.com> writes:
[...]
This worked great until I encountered a wtmp file that was
370 MB. malloc fails setting errno to ENOMEM (not enough
storage space). My system has 16GB of memory and 9GB of paging
(33% used). So, I should have plenty of memory.


The amount of memory available on your system isn't necessarily the
same as the amount of memory available to your program.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
It should have occured to me I might be up against
a system limit. There's a -bmaxdata compile flag
I used to allow the program to allocate memory over
256 meg.

Many thanks for pointing me in the right direction.
Maja

Nov 14 '05 #6

In article <41************ ***********@dre ader16.news.xs4 all.nl>, "dandelion" <da*******@mead ow.net> writes:

"Maja" <ma********@yah oo.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
This worked great until I encountered a wtmp file that was
370 MB. malloc fails setting errno to ENOMEM (not enough
storage space). My system has 16GB of memory and 9GB of paging
(33% used). So, I should have plenty of memory.
Hmmm... By the sound of it (you do not provide the actual call to malloc
which fails), i'd say you're right and this is a bug somewhere.


Nonsense. malloc is allowed to fail for any reason. Assuming a bug
here is like assuming that someone stole your car if you can't find
your keys.

Off topic: The reference to wtmp implies this is a POSIX system. Most
POSIX systems (maybe all; I'm not going to check the standard to see
if this is required) provide a mechanism to limit how much memory a
process can allocate. This is a Good Thing, and has been part of Unix
for a long time. Consult the documentation for the setrlimit system
call and the ulimit command (really commands, since various shells
provide various flavors of ulimit builtins).
The call *should* succeed, AFAICT,
You can't tell. None of us can; we don't have nearly enough
information. Certainly the amount of physical and virtual memory in
the system doesn't suffice. (In fact, depending on the OS, it may
not even be relevant.)

And, once again, we have an excellent demonstration why answering OT
questions here is a bad idea.
so if it doesn't, it's an implementation issue,
Or it isn't, since this is a hosted implementation, and it may just
be reporting - correctly - that the hosting OS has denied its request.
you can best pass on to the vendor of your compiler or ask this
question again on a newsgroup that is dedicated to your OS/compiler.


Indeed.

--
Michael Wojcik mi************@ microfocus.com

The antics which have been drawn together in this book are huddled here
for mutual protection like sheep. If they had half a wit apiece each
would bound off in many directions, to unsimplify the target. -- Walt Kelly
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

231
23258
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought (perhaps mistakenly) that the purpose of a void pointer was to cast into a legitimate date type. Is this wrong? Why, and what is considered to be correct form?
25
5081
by: H.A. Sujith | last post by:
If malloc fails what should I do? 1. Exit imediately. 2. Print an error message (or put a log entry) and exit. 3. Print an error message (or put a log entry) and continue execution (after possibly recovering from the error). Printing an error message might be difficult in a graphical environment. --
27
4281
by: Chess Saurus | last post by:
I'm getting a little bit tired of writing if (a = malloc(...) == NULL) { // error code } I mean, is it really possible that a malloc call could fail, except in the case of running out of virtual memory? -Chess
7
2219
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ http://www.eskimo.com/~scs/C-faq/faq.html but it doesn't seem to answer my questions... So, I've made an example behind, with some included questions...
68
15722
by: James Dow Allen | last post by:
The gcc compiler treats malloc() specially! I have no particular question, but it might be fun to hear from anyone who knows about gcc's special behavior. Some may find this post interesting; some may find it off-topic or confusing. Disclaimers at end. The code samples are intended to be nearly minimal demonstrations. They are *not* related to any actual application code.
58
4698
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is the overhead of automatic variable sized arrays, I suspect it is smaller than that of malloc), although I'm not too worried about it. I was thinking that, with C99's variable length arrays, malloc shouldn't be needed most of the time. But I'm...
71
19146
by: desktop | last post by:
I have read in Bjarne Stroustrup that using malloc and free should be avoided in C++ because they deal with uninitialized memory and one should instead use new and delete. But why is that a problem? I cannot see why using malloc instead of new does not give the same result.
34
13419
by: niranjan.singh | last post by:
This is regarding to test an SDK memory stuff. In what situation malloc gets fail. any comment/reply pls.... regards
173
8207
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc. OTOH, if you're allocating a gigabyte for a large array, this might fail, so you should definitely check for a NULL return.
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10633
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10375
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.