Serious low memory handler bug (Solved)

This forum is for general developer support questions.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Serious low memory handler bug (freeze)

Post by xenic »

gazelle wrote: I don't think you wasted your time. You found a bug and reported it.

After reading about it, it's just my opinion that the bug is in the low memory handler which solely rely on the MEMHF_RECYCLE flag.
That's true from an OS4 perspective but relying on the MEMHF_RECYCLE in an OS3 program was legitimate and in compliance with the existing system includes and documentation.
Why this flag was removed I don't know. How to solve this for old software, which rely solely on that flag, I also don't know. But just changing exec to treat a MEM_TRY_AGAIN return value the same as a MEM_ALL_DONE is not the solution.
Aside from reinstating the MEMHF_RECYCLE flag, it's the only simple way I can think of to ensure that OS3 programs that have low memory handlers will not freeze the system under low memory conditions.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
Thomas Frieden
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 147
Joined: Fri Dec 10, 2010 3:21 pm

Re: Serious low memory handler bug (freeze)

Post by Thomas Frieden »

xenic wrote:@salass00 & gazelle
I can see that this is a waste of time and am not going to attempt to explain the issue any more. Apparently, the original Amiga developers were dumb and put the MEMHF_RECYCLE flag and the MEM_TRY_AGAIN return value into the OS for no reason and that the PHD author and experienced programmers that wrote DirectoryOpus5 were idiots for using those unnecessary items.
And you honestly think that postings like that will make people more inclined to look into the problems you have ? Honestly ?

I will look into it, yes, can't rwmember how the whole mechanism works since it was written anout ten years ago.

However, I would appreciate if you could refrain from posts like this.
User avatar
tboeckel
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 68
Joined: Mon Jun 20, 2011 8:56 am
Contact:

Re: Serious low memory handler bug (freeze)

Post by tboeckel »

@xenic

I really must second gazelle here. Your lowmemory handler simply assumes that the MEMHF_RECYCLE flag is definitely set at some time. This might sound logical on the first sight, but there is no guarantee that your handler is really called a second time. If the memory allocation succeeded after your handler was called for the first time your handler will NOT be called again (why should it) and Exec MUST clear the flag for the possible next run. If a future memory allocation triggers your handler to be called a second time you would expect the flag to be clear, because otherwise you are mixing up two different low memory situations.

I also searched the old 3.x Autodocs and Includes, but I could not find a single explanation how the MEMHF_RECYCLE flag is really to be treated. Yes, of course the is the comment " 0==First time, 1==recycle", but the 3.x Autodocs don't even mention the return value MEM_TRY_AGAIN. And for me the comment "We did some, try the allocation again" definitely allows the case that a lowmemory handler is NOT called a second time if the memory allocation succeeded because your handler freed up enough memory.
User avatar
gazelle
Posts: 102
Joined: Sun Mar 04, 2012 12:49 pm
Location: Frohnleiten, Austria

Re: Serious low memory handler bug (freeze)

Post by gazelle »

I did take a look at the original code and think the problem was a combination of poor documentation (os side) and missunderstanding (developer side). The developer was aware that calling the handler a second time (for the same allocation) doesn't do any good and included the check for the MEMHF_RECYCLE flag. Why he didn't just change the return value from MEM_TRY_AGAIN to MEM_ALL_DONE to avoid it, we will never know.

For new/updated software this shouldn't be a problem because it can be corrected, for old software, who knows?

@xenic:

BTW, I don't think you need to #ifdef the "data->low_mem_handler.is_Node.ln_Type" for OS4, this will be taken care of by the AddMemHandler() call, if I understand the autodoc correctly.

And your solution for OS4 should work on all systems.
User avatar
Thomas Frieden
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 147
Joined: Fri Dec 10, 2010 3:21 pm

Re: Serious low memory handler bug (freeze)

Post by Thomas Frieden »

Ok, I did have a look at it.

It seems the old system always set this flag whenever it encountered a MEM_TRY_AGAIN. This code got lost when I moved the low memory handler invocation into it's own function.

Added now.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Serious low memory handler bug (freeze)

Post by xenic »

Thomas Frieden wrote:Ok, I did have a look at it.

It seems the old system always set this flag whenever it encountered a MEM_TRY_AGAIN. This code got lost when I moved the low memory handler invocation into it's own function.

Added now.
Sorry for the sarcastic post but it got your attention and the issue resolved.

Apologies to all for inappropriate posts.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
ssolie
Beta Tester
Beta Tester
Posts: 1010
Joined: Mon Dec 20, 2010 8:51 pm
Location: Canada
Contact:

Re: Serious low memory handler bug (freeze)

Post by ssolie »

xenic wrote:Sorry for the sarcastic post but it got your attention and the issue resolved.

Apologies to all for inappropriate posts.
Thank you for that respectful note.

I think I can speak for the dev team that we do appreciate your useful test cases to prove your point. That can necessarily mean ruffling a few feathers from time to time. ;)
ExecSG Team Lead
Post Reply