2009-12-04 06:12:03     bss allocation while execution

Document created by Aaronwu Employee on Aug 19, 2013
Version 1Show Document
  • View in full screen mode

2009-12-04 06:12:03     bss allocation while execution

Jayakar Nalthooru (INDIA)

Message: 83085   

 

Dear All,

 

I am using a application loader to load different applciations in the system on runtime. Lets say a Application 1 is having 5 uninitalized global arrays with 2MB each. Then BSS size of this application is 10MB. Lets say applciation 2 is having 5 unititalized arrays of 3MB. Then BSS size of applicaiton 2 is 15MB. At frist time I can able to run application 1 and when I try to run application 2 then system fails to load the 15MB of BSS memory eventhough system is having 40MB of free memory. Here system is trying to allocation 15MB of single chunk of memory for BSS while loading the application 2.

 

My questions are -

 

1. How to make system to allocate memroy to individual arrays rather than allocating for full BSS in single chunk of memory segment while runing the application? In the case of application 2, in stead of allocating 15MB in one shot system can allocate in 5 X 3MB of saparate memory segment. How this can be done?

 

2. I am able to run the application2 on frist time. But I face problem after runing application1. That shows that memory is fragmented into smaller chunks. How to release the memory fragments back to system?

 

Thanks in advance,

 

Jay

QuoteReplyEditDelete

 

 

2009-12-04 06:18:34     Re: bss allocation while execution

Mike Frysinger (UNITED STATES)

Message: 83086   

 

1) use malloc

 

2) it is impossible to defragment with nommu

QuoteReplyEditDelete

 

 

2009-12-04 06:38:52     Re: bss allocation while execution

Jayakar Nalthooru (INDIA)

Message: 83088   

 

Thanks Mike. But I am currently runing 4 applications (one at a time) and planing to add 3 more applications into the system. It is little difficult for me replace all global variable with dynamic memory. Sometime these arrays are spread accross libraries, we don't get the source for the same from the customer. Is it possible instruct the loader to not allocate bss memory in single memory segment? Or do you suggest me in some other way?

 

Thanks in advance

 

Jay

QuoteReplyEditDelete

 

 

2009-12-04 06:45:07     Re: bss allocation while execution

Mike Frysinger (UNITED STATES)

Message: 83089   

 

the loader has no idea how things are laid out.  it merely does what it is told via the ELF PHDRs, and those are locked at link time.

 

it might be possible to use magic linker flags to split the PHDRs, but i'm not aware of these sort of methods off the top of my head.  converting variables to malloc is trivial to do -- use a constructor to allocate the memory so that it's automatically available before anything else is run.

 

as for running multiple applications, dont do that if you're going to be constantly allocating and freeing huge contiguous chunks.  architect the system in such a way that large allocations are done once and not freed.  it might suck, but this is the penalty you pay for not having virtual memory.

Attachments

    Outcomes