malloc_simple: Add simple malloc free function
PATCH 1/1 malloc_simple: Add simple malloc free function
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of gd->malloc_ptr that we stored.
--- common/dlmalloc.c | 6 ++++-- common/malloc_simple.c | 34 ++++++++++++++++++++++++++++++++++ include/asm-generic/global_data.h | 2 ++ include/malloc.h | 3 ++- 4 files changed, 42 insertions(+), 3 deletions(-)
common/dlmalloc.c +4 -2
@@ -1523,9 +1523,11 @@ void fREe(mem) Void_t* mem;int islr;/* track whether merging with last_remainder */ #ifdef CONFIG_SYS_MALLOC_F_LEN -/* free() is a no-op - all the memory will be freed on relocation */ -if (!(gd->flags &GD_FLG_FULL_MALLOC_INIT )) +/* Invoke free_simple. All the memory will be freed on relocation */ +if (!(gd->flags &GD_FLG_FULL_MALLOC_INIT )) { +free_simple (mem);return ; + }#endif if (mem ==NULL )/* free(0) has no effect */
common/malloc_simple.c +34 -0
@@ -26,6 +26,18 @@ void *malloc_simple(size_t bytes)return NULL ; } ptr =map_sysmem (gd->malloc_base + gd->malloc_ptr, bytes); + +/* implement a simple free mechanism which stored last 2 usage */ +if (gd->malloc_free_addr[0 ] !=0 ) { +/* shifting as we are storing depth of 2 */ + gd->malloc_free_addr[1 ] = gd->malloc_free_addr[0 ]; + gd->malloc_free_ptr[1 ] = gd->malloc_free_ptr[0 ]; + } +/* saving last malloc address for malloc free */ + gd->malloc_free_addr[0 ] = ptr; +/* saving last malloc_ptr prior allocation for malloc free */ + gd->malloc_free_ptr[0 ] = gd->malloc_ptr; + gd->malloc_ptr =ALIGN (new_ptr,sizeof (new_ptr));debug ("%lx\n" , (ulong )ptr);
@@ -42,6 +54,18 @@ void *memalign_simple(size_t align, size_t bytes)if (new_ptr > gd->malloc_limit)return NULL ; ptr =map_sysmem (addr, bytes); + +/* implement a simple free mechanism which stored last 2 usage */ +if (gd->malloc_free_addr[0 ] !=0 ) { +/* shifting as we are storing depth of 2 */ + gd->malloc_free_addr[1 ] = gd->malloc_free_addr[0 ]; + gd->malloc_free_ptr[1 ] = gd->malloc_free_ptr[0 ]; + } +/* saving last malloc address for malloc free */ + gd->malloc_free_addr[0 ] = ptr; +/* saving last malloc_ptr prior allocation for malloc free */ + gd->malloc_free_ptr[0 ] = gd->malloc_ptr; + gd->malloc_ptr =ALIGN (new_ptr,sizeof (new_ptr));return ptr;
@@ -59,3 +83,13 @@ void *calloc(size_t nmemb, size_t elem_size) return ptr; }#endif + +void free_simple (Void_t * mem) +{ +if (mem == gd->malloc_free_addr[0 ]) { + gd->malloc_ptr = gd->malloc_free_ptr[0 ]; +/* shifting as we are storing depth of 2 */ + gd->malloc_free_addr[0 ] = gd->malloc_free_addr[1 ]; + gd->malloc_free_ptr[0 ] = gd->malloc_free_ptr[1 ]; + } +}
include/asm-generic/global_data.h +2 -0
@@ -90,6 +90,8 @@ typedef struct global_data {unsigned long malloc_base;/* base address of early malloc() */ unsigned long malloc_limit;/* limit address */ unsigned long malloc_ptr;/* current address */ +void *malloc_free_addr[2 ];/* Last malloc pointer address*/ +unsigned long malloc_free_ptr[2 ];/* Last malloc_ptr */ #endif #ifdef CONFIG_PCI struct pci_controller *hose;/* PCI hose for early use */
include/malloc.h +2 -1
@@ -876,7 +876,7 @@ extern Void_t* sbrk();#define malloc malloc_simple#define realloc realloc_simple#define memalign memalign_simple -static inline void free (void *ptr) {} +#define free free_simplevoid *calloc (size_t nmemb,size_t size);void *memalign_simple (size_t alignment,size_t bytes);void *realloc_simple (void *ptr,size_t size);
@@ -913,6 +913,7 @@ int initf_malloc(void);/* Simple versions which can be used when space is tight */ void *malloc_simple (size_t size); +void free_simple (Void_t * mem);#pragma GCC visibility push(hidden)# if __STD_C
Signature · 1 line
2.2.2
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 8 lines · Chin Liang See
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of
gd->malloc_ptrthat we stored.
This looks unnecessarily convoluted and fragile design. What problem do you observe and on what platform ?
Quoted 122 lines
Signed-off-by Chin Liang See <[email protected]>Cc Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Dinh Nguyen <[email protected]>Cc Tien Fong Chee <[email protected]>--- common/dlmalloc.c | 6 ++++-- common/malloc_simple.c | 34 ++++++++++++++++++++++++++++++++++ include/asm-generic/global_data.h | 2 ++ include/malloc.h | 3 ++- 4 files changed, 42 insertions(+), 3 deletions(-)common/dlmalloc.c +4
-2@@ -1523,9 +1523,11 @@ void fREe(mem) Void_t* mem;int islr;/* track whether merging with last_remainder */ #ifdef CONFIG_SYS_MALLOC_F_LEN -/* free() is a no-op - all the memory will be freed on relocation */ -if (!(gd->flags &GD_FLG_FULL_MALLOC_INIT )) +/* Invoke free_simple. All the memory will be freed on relocation */ +if (!(gd->flags &GD_FLG_FULL_MALLOC_INIT )) { +free_simple (mem);return ; + }#endif if (mem ==NULL )/* free(0) has no effect */ common/malloc_simple.c +34
-0@@ -26,6 +26,18 @@ void *malloc_simple(size_t bytes)return NULL ; } ptr =map_sysmem (gd->malloc_base + gd->malloc_ptr, bytes); + +/* implement a simple free mechanism which stored last 2 usage */ +if (gd->malloc_free_addr[0 ] !=0 ) { +/* shifting as we are storing depth of 2 */ + gd->malloc_free_addr[1 ] = gd->malloc_free_addr[0 ]; + gd->malloc_free_ptr[1 ] = gd->malloc_free_ptr[0 ]; + } +/* saving last malloc address for malloc free */ + gd->malloc_free_addr[0 ] = ptr; +/* saving last malloc_ptr prior allocation for malloc free */ + gd->malloc_free_ptr[0 ] = gd->malloc_ptr; + gd->malloc_ptr =ALIGN (new_ptr,sizeof (new_ptr));debug ("%lx\n" , (ulong )ptr);@@ -42,6 +54,18 @@ void *memalign_simple(size_t align, size_t bytes)if (new_ptr > gd->malloc_limit)return NULL ; ptr =map_sysmem (addr, bytes); + +/* implement a simple free mechanism which stored last 2 usage */ +if (gd->malloc_free_addr[0 ] !=0 ) { +/* shifting as we are storing depth of 2 */ + gd->malloc_free_addr[1 ] = gd->malloc_free_addr[0 ]; + gd->malloc_free_ptr[1 ] = gd->malloc_free_ptr[0 ]; + } +/* saving last malloc address for malloc free */ + gd->malloc_free_addr[0 ] = ptr; +/* saving last malloc_ptr prior allocation for malloc free */ + gd->malloc_free_ptr[0 ] = gd->malloc_ptr; + gd->malloc_ptr =ALIGN (new_ptr,sizeof (new_ptr));return ptr;@@ -59,3 +83,13 @@ void *calloc(size_t nmemb, size_t elem_size) return ptr; }#endif + +void free_simple (Void_t * mem) +{ +if (mem == gd->malloc_free_addr[0 ]) { + gd->malloc_ptr = gd->malloc_free_ptr[0 ]; +/* shifting as we are storing depth of 2 */ + gd->malloc_free_addr[0 ] = gd->malloc_free_addr[1 ]; + gd->malloc_free_ptr[0 ] = gd->malloc_free_ptr[1 ]; + } +}include/asm-generic/global_data.h +2
-0@@ -90,6 +90,8 @@ typedef struct global_data {unsigned long malloc_base;/* base address of early malloc() */ unsigned long malloc_limit;/* limit address */ unsigned long malloc_ptr;/* current address */ +void *malloc_free_addr[2 ];/* Last malloc pointer address*/ +unsigned long malloc_free_ptr[2 ];/* Last malloc_ptr */ #endif #ifdef CONFIG_PCI struct pci_controller *hose;/* PCI hose for early use */ include/malloc.h +2
-1@@ -876,7 +876,7 @@ extern Void_t* sbrk();#define malloc malloc_simple#define realloc realloc_simple#define memalign memalign_simple -static inline void free (void *ptr) {} +#define free free_simplevoid *calloc (size_t nmemb,size_t size);void *memalign_simple (size_t alignment,size_t bytes);void *realloc_simple (void *ptr,size_t size);@@ -913,6 +913,7 @@ int initf_malloc(void);/* Simple versions which can be used when space is tight */ void *malloc_simple (size_t size); +void free_simple (Void_t * mem);#pragma GCC visibility push(hidden)# if __STD_C
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 malloc_simple: Add simple malloc free function
Hi Marek,
Quoted 6 lines · Marek Vasut
Quoted 5 lines · Chin Liang See
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
Quoted 6 lines
Quoted 3 lines
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of
gd->malloc_ptrthat we stored.This looks unnecessarily convoluted and fragile design. What problem do you observe and on what platform ?
Actually this for our Arria10 SoC device. In order to get DDR working, we need to program FPGA. To improve the usability, we put the FPGA programming file (RBF) into FAT partition.
In that sense, we would need to use FAT driver prior relocation / DDR available. Due to that, the malloc usage is high and memory available is limited prior DDR available.
The simple malloc helps but without the free, its consumed way too much memory than saving. Hence this simple malloc free patch help. So I believe this would benefits those who are executing complex operation prior relocation :)
Thanks
Chin Liang
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 1 line · Chin Liang See
Hi Marek,
Hi,
Quoted 14 lines · Marek Vasut
Quoted 6 lines · Chin Liang See
Quoted 5 lines
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
Quoted 6 lines
Quoted 3 lines
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of
gd->malloc_ptrthat we stored.This looks unnecessarily convoluted and fragile design. What problem do you observe and on what platform ?
Quoted 7 lines
Actually this for our Arria10 SoC device. In order to get DDR working, we need to program FPGA. To improve the usability, we put the FPGA programming file (RBF) into FAT partition.
In that sense, we would need to use FAT driver prior relocation / DDR available. Due to that, the malloc usage is high and memory available is limited prior DDR available.
I was under the impression that you have 256kiB of SRAM on the A10. SPL should consume about 64 kiB tops, including support for loading from VFAT. So you have 192 kiB available, how is that not enough ?
Quoted 4 lines
The simple malloc helps but without the free, its consumed way too much memory than saving. Hence this simple malloc free patch help. So I believe this would benefits those who are executing complex operation prior relocation :)
I believe you need to identify who is calling malloc() to obtain big buffers without recycling them.
Your design breaks in the scenario where someone does big malloc followed by two small mallocs if I understand it correctly. This doesn't scale and is a hack.
Quoted 3 lines
Thanks
Chin Liang
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 30 lines · Marek Vasut
Quoted 1 line · Chin Liang See
Hi Marek,
Hi,
Quoted 19 lines · Marek Vasut
Quoted 6 lines · Chin Liang See
Quoted 5 lines
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
Quoted 6 lines
Quoted 3 lines
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of
gd->malloc_ptrthat we stored.This looks unnecessarily convoluted and fragile design. What problem do you observe and on what platform ?
Actually this for our Arria10 SoC device. In order to get DDR working,
we need to program FPGA. To improve the usability, we put the FPGA programming file (RBF) into FAT partition.Quoted 5 lines
In that sense, we would need to use FAT driver prior relocation / DDR
available. Due to that, the malloc usage is high and memory available
is limited prior DDR available.
Quoted 3 lines
I was under the impression that you have 256kiB of SRAM on the A10. SPL should consume about 64 kiB tops, including support for loading from VFAT. So you have 192 kiB available, how is that not enough ?
But I presume we won't want to limit that minimum 256MB of internal memory needed for simple malloc usage, right?
Quoted 11 lines
Quoted 7 lines
The simple malloc helps but without the free, its consumed way too much
memory than saving. Hence this simple malloc free patch help. So I believe this would benefits those who are executing complex operation
prior relocation :)I believe you need to identify who is calling
malloc()to obtain big buffers without recycling them.
It's the fat driver which is utilizing the malloc.
Quoted 4 lines
Your design breaks in the scenario where someone does big malloc followed by two small mallocs if I understand it correctly. This doesn't scale and is a hack.
Actually the proposed free is a simple implementation which acts as stack push and pop with depth of 2. This is to enhance existing implementation which don't handle the pop. This get worst especially dealing with fat driver.
Thanks
Chin Liang
Quoted 5 lines
Quoted 3 lines
Thanks
Chin Liang
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 31 lines · Chin Liang See
Quoted 30 lines · Marek Vasut
Quoted 1 line · Chin Liang See
Hi Marek,
Hi,
Quoted 24 lines · Marek Vasut
Quoted 6 lines · Chin Liang See
Quoted 5 lines
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
Quoted 6 lines
Quoted 3 lines
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of
gd->malloc_ptrthat we stored.This looks unnecessarily convoluted and fragile design. What problem do you observe and on what platform ?
Actually this for our Arria10 SoC device. In order to get DDR working,
we need to program FPGA. To improve the usability, we put the FPGA programming file (RBF) into FAT partition.In that sense, we would need to use FAT driver prior relocation / DDR
available. Due to that, the malloc usage is high and memory available
is limited prior DDR available.
Quoted 6 lines
Quoted 3 lines
I was under the impression that you have 256kiB of SRAM on the A10. SPL should consume about 64 kiB tops, including support for loading from VFAT. So you have 192 kiB available, how is that not enough ?
But I presume we won't want to limit that minimum 256MB of internal memory needed for simple malloc usage, right?
Err, 256 MiB ? I think 192k of malloc area must be _plenty_ for SPL either way you slice it.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
The simple malloc helps but without the free, its consumed way too much
memory than saving. Hence this simple malloc free patch help. So I believe this would benefits those who are executing complex operation
prior relocation :)
Quoted 5 lines
Quoted 3 lines
I believe you need to identify who is calling
malloc()to obtain big buffers without recycling them.It's the fat driver which is utilizing the malloc.
So fat is allocating stuff without freeing it ? I wonder if we should either fix fat or use full malloc in SPL on A10 . I am not really fond of adding more stuff into simple malloc (to keep it small and simple).
Quoted 9 lines
Quoted 4 lines
Your design breaks in the scenario where someone does big malloc followed by two small mallocs if I understand it correctly. This doesn't scale and is a hack.
Actually the proposed free is a simple implementation which acts as stack push and pop with depth of 2. This is to enhance existing implementation which don't handle the pop. This get worst especially dealing with fat driver.
Well, how does it handle my example? It doesn't and it fails to help in such case, right ?
Quoted 8 lines
Thanks
Chin LiangQuoted 5 lines
Quoted 3 lines
Thanks
Chin Liang
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 64 lines · Marek Vasut
Quoted 42 lines · Chin Liang See
Quoted 34 lines · Marek Vasut
Quoted 1 line · Chin Liang See
Hi Marek,
Hi,
Quoted 22 lines · Marek Vasut
Quoted 6 lines · Chin Liang See
Quoted 5 lines
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
Quoted 8 lines
Quoted 5 lines
This implementation will stored last 2 usage of malloc. When
free is invoked and the free address matched, we shall revert
to previous value ofgd->malloc_ptrthat we stored.This looks unnecessarily convoluted and fragile design. What problem do you observe and on what platform ?
Actually this for our Arria10 SoC device. In order to get DDR working,
we need to program FPGA. To improve the usability, we put the FPGA
programming file (RBF) into FAT partition.Quoted 6 lines
In that sense, we would need to use FAT driver prior relocation /
DDR
available. Due to that, the malloc usage is high and memory available
is limited prior DDR available.Quoted 6 lines
I was under the impression that you have 256kiB of SRAM on the A10.
SPL should consume about 64 kiB tops, including support for loading
from VFAT. So you have 192 kiB available, how is that not enough ?Quoted 2 lines
But I presume we won't want to limit that minimum 256MB of internal memory needed for simple malloc usage, right?
Err, 256 MiB ? I think 192k of malloc area must be _plenty_ for SPL either way you slice it.
Quoted 15 lines
Quoted 14 lines
Quoted 9 lines
The simple malloc helps but without the free, its consumed way too
much
memory than saving. Hence this simple malloc free patch help. So I
believe this would benefits those who are executing complex operation
prior relocation :)I believe you need to identify who is calling
malloc()to obtain big
buffers without recycling them.
Quoted 7 lines
Quoted 1 line
It's the fat driver which is utilizing the malloc.
So fat is allocating stuff without freeing it ? I wonder if we should either fix fat or use full malloc in SPL on A10 . I am not really fond
of adding more stuff into simple malloc (to keep it small and simple).
Actually fat driver is good where it invoke malloc and free during the operation. Just that with existing malloc, there is no free implementation and memory keep "push" every time malloc invoked.
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
Your design breaks in the scenario where someone does big malloc followed by two small mallocs if I understand it correctly. This doesn't scale and is a hack.
Actually the proposed free is a simple implementation which acts as stack push and pop with depth of 2. This is to enhance existing implementation which don't handle the pop. This get worst especially
dealing with fat driver.
Quoted 3 lines
Well, how does it handle my example? It doesn't and it fails to help in
such case, right ?
I was thinking what is the correct depth while trying to keep things simple. From the FAT access testing with SD and eMMC, depth of 2 works well by cutting lot of memory consumption by simple malloc implementation. Any thoughts whether should have more flexibility?
Thanks
Chin Liang
Quoted 11 lines
Quoted 9 lines
Thanks
Chin LiangQuoted 5 lines
Quoted 3 lines
Thanks
Chin Liang
PATCH 1/1 malloc_simple: Add simple malloc free function
On 08/03/2016 05:22 PM, Chin Liang See wrote:
Hi,
[...]
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
It's the fat driver which is utilizing the malloc.
So fat is allocating stuff without freeing it ? I wonder if we should either fix fat or use full malloc in SPL on A10 . I am not really fond
of adding more stuff into simple malloc (to keep it small and simple).Actually fat driver is good where it invoke malloc and free during the operation. Just that with existing malloc, there is no free implementation and memory keep "push" every time malloc invoked.
And I agree with Simon that we should look into the FAT driver and fix it. Is that not possible ?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Your design breaks in the scenario where someone does big malloc followed by two small mallocs if I understand it correctly. This doesn't scale and is a hack.
Actually the proposed free is a simple implementation which acts as stack push and pop with depth of 2. This is to enhance existing implementation which don't handle the pop. This get worst especially
dealing with fat driver.
Quoted 8 lines
Quoted 3 lines
Well, how does it handle my example? It doesn't and it fails to help in
such case, right ?I was thinking what is the correct depth while trying to keep things simple. From the FAT access testing with SD and eMMC, depth of 2 works well by cutting lot of memory consumption by simple malloc implementation. Any thoughts whether should have more flexibility?
You still didn't answer my question -- how will this handle my example usecase ?
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 3 lines · Marek Vasut
On 08/03/2016 05:22 PM, Chin Liang See wrote:
Hi,
Hi Marek,
Quoted 11 lines
[...]
Quoted 9 lines
Quoted 8 lines
Quoted 1 line
It's the fat driver which is utilizing the malloc.
So fat is allocating stuff without freeing it ? I wonder if we should
either fix fat or use full malloc in SPL on A10 . I am not really fond
of adding more stuff into simple malloc (to keep it small and simple).
Quoted 8 lines
Quoted 4 lines
Actually fat driver is good where it invoke malloc and free during the
operation. Just that with existing malloc, there is no free implementation and memory keep "push" every time malloc invoked.And I agree with Simon that we should look into the FAT driver and fix
it. Is that not possible ?
Definitely as seems everyone believe this should be the right way to go.
Quoted 27 lines
Quoted 20 lines
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Your design breaks in the scenario where someone does big malloc
followed by two small mallocs if I understand it correctly. This
doesn't scale and is a hack.Quoted 6 lines
Actually the proposed free is a simple implementation which acts as
stack push and pop with depth of 2. This is to enhance existing implementation which don't handle the pop. This get worst especially
dealing with fat driver.Quoted 4 lines
Well, how does it handle my example? It doesn't and it fails to help
in
such case, right ?Quoted 6 lines
I was thinking what is the correct depth while trying to keep things
simple. From the FAT access testing with SD and eMMC, depth of 2 works
well by cutting lot of memory consumption by simple malloc implementation. Any thoughts whether should have more flexibility?
Quoted 4 lines
You still didn't answer my question -- how will this handle my example
usecase ?
I did and wonder my email server having issue again. For this case, yah, it will not being handle as we try to keep it simple by having depth of 2. FYI, the 2 is being derived from my experiment of FAT driver access with SD and eMMC devices. We can enhance that but probably that might not a good idea per Simon suggested.
Thanks
Chin Liang
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 23 lines · Chin Liang See
Quoted 3 lines · Marek Vasut
On 08/03/2016 05:22 PM, Chin Liang See wrote:
Hi,
Hi Marek,
Quoted 16 lines
[...]
Quoted 13 lines
Quoted 8 lines
Quoted 1 line
It's the fat driver which is utilizing the malloc.
So fat is allocating stuff without freeing it ? I wonder if we should
either fix fat or use full malloc in SPL on A10 . I am not really fond
of adding more stuff into simple malloc (to keep it small and simple).Actually fat driver is good where it invoke malloc and free during the
operation. Just that with existing malloc, there is no free implementation and memory keep "push" every time malloc invoked.
Quoted 7 lines
Quoted 3 lines
And I agree with Simon that we should look into the FAT driver and fix
it. Is that not possible ?Definitely as seems everyone believe this should be the right way to go.
Indeed
Quoted 32 lines
Quoted 27 lines
Quoted 20 lines
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Your design breaks in the scenario where someone does big malloc
followed by two small mallocs if I understand it correctly. This
doesn't scale and is a hack.Quoted 6 lines
Actually the proposed free is a simple implementation which acts as
stack push and pop with depth of 2. This is to enhance existing implementation which don't handle the pop. This get worst especially
dealing with fat driver.Quoted 4 lines
Well, how does it handle my example? It doesn't and it fails to help
in
such case, right ?Quoted 6 lines
I was thinking what is the correct depth while trying to keep things
simple. From the FAT access testing with SD and eMMC, depth of 2 works
well by cutting lot of memory consumption by simple malloc implementation. Any thoughts whether should have more flexibility?Quoted 4 lines
You still didn't answer my question -- how will this handle my example
usecase ?
Quoted 5 lines
I did and wonder my email server having issue again. For this case, yah, it will not being handle as we try to keep it simple by having depth of 2. FYI, the 2 is being derived from my experiment of FAT driver access with SD and eMMC devices. We can enhance that but probably that might not a good idea per Simon suggested.
How would you enhance it such that I cannot find counter-example ? :)
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 malloc_simple: Add simple malloc free function
In reply to Chin Liang SeeHi,
Quoted 8 lines · Chin Liang See
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of
gd->malloc_ptrthat we stored.
I'm really not keen on this patch. Can we not adjust the FAT code to avoid repeated malloc()/free()?
Quoted 7 lines
Signed-off-by Chin Liang See <[email protected]>Cc Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Dinh Nguyen <[email protected]>Cc Tien Fong Chee <[email protected]>
Quoted 6 lines
--- common/dlmalloc.c | 6 ++++-- common/malloc_simple.c | 34 ++++++++++++++++++++++++++++++++++ include/asm-generic/global_data.h | 2 ++ include/malloc.h | 3 ++- 4 files changed, 42 insertions(+), 3 deletions(-)
Regards,
Simon
PATCH 1/1 malloc_simple: Add simple malloc free function
Quoted 2 lines · Simon Glass
Hi,
Hi Simon,
Quoted 6 lines · Chin Liang See
Quoted 5 lines
Enable a simple malloc implementation which will minimize memory usage prior relocation. This is essential as memory available prior location is internal memory and limited in size.
Quoted 7 lines
Quoted 3 lines
This implementation will stored last 2 usage of malloc. When free is invoked and the free address matched, we shall revert to previous value of
gd->malloc_ptrthat we stored.I'm really not keen on this patch. Can we not adjust the FAT code to avoid repeated malloc()/free()?
Sure and let me take a look on enhancing the FAT driver for the malloc/free aspect.
Thanks
Chin Liang
Quoted 18 lines
Quoted 8 lines
Signed-off-by Chin Liang See <[email protected]>Cc Marek Vasut <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>Cc Dinh Nguyen <[email protected]>Cc Tien Fong Chee <[email protected]>Quoted 7 lines
--- common/dlmalloc.c | 6 ++++-- common/malloc_simple.c | 34 ++++++++++++++++++++++++++++++++++ include/asm-generic/global_data.h | 2 ++ include/malloc.h | 3 ++- 4 files changed, 42 insertions(+), 3 deletions(-)Regards,
Simon