Commit 0aa8a4ad99954ba48c46c31276ec0f6a5f15211d
Committed by
Tom Rini
1 parent
41ac233c61
Exists in
v2017.01-smarct4x
and in
37 other branches
dlmalloc: do memset in malloc init as new default config
This commit introduces new config: CONFIG_SYS_MALLOC_CLEAR_ON_INIT. This config is an expert option and is enabled by default. The all amount of memory reserved for the malloc, is by default set to zero in mem_malloc_init(). When the malloc reserved memory exceeds few MiB, then the boot process can slow down. So disabling this config, is an expert option to reduce the boot time, and can be disabled by Kconfig. Note: After disable this option, only calloc() will return the pointer to the zeroed memory area. Previously, without this option, the memory pointed to untouched malloc memory region, was filled with zeros. So it means, that code with malloc() calls should be reexamined. Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 32 additions and 10 deletions Side-by-side Diff
Kconfig
... | ... | @@ -72,13 +72,31 @@ |
72 | 72 | initial serial device and any others that are needed. |
73 | 73 | |
74 | 74 | menuconfig EXPERT |
75 | - bool "Configure standard U-Boot features (expert users)" | |
76 | - help | |
77 | - This option allows certain base U-Boot options and settings | |
78 | - to be disabled or tweaked. This is for specialized | |
79 | - environments which can tolerate a "non-standard" U-Boot. | |
80 | - Only use this if you really know what you are doing. | |
75 | + bool "Configure standard U-Boot features (expert users)" | |
76 | + default y | |
77 | + help | |
78 | + This option allows certain base U-Boot options and settings | |
79 | + to be disabled or tweaked. This is for specialized | |
80 | + environments which can tolerate a "non-standard" U-Boot. | |
81 | + Only use this if you really know what you are doing. | |
81 | 82 | |
83 | +if EXPERT | |
84 | + config SYS_MALLOC_CLEAR_ON_INIT | |
85 | + bool "Init with zeros the memory reserved for malloc (slow)" | |
86 | + default y | |
87 | + help | |
88 | + This setting is enabled by default. The reserved malloc | |
89 | + memory is initialized with zeros, so first malloc calls | |
90 | + will return the pointer to the zeroed memory. But this | |
91 | + slows the boot time. | |
92 | + | |
93 | + It is recommended to disable it, when CONFIG_SYS_MALLOC_LEN | |
94 | + value, has more than few MiB, e.g. when uses bzip2 or bmp logo. | |
95 | + Then the boot time can be significantly reduced. | |
96 | + Warning: | |
97 | + When disabling this, please check if malloc calls, maybe | |
98 | + should be replaced by calloc - if expects zeroed memory. | |
99 | +endif | |
82 | 100 | endmenu # General setup |
83 | 101 | |
84 | 102 | menu "Boot images" |
common/dlmalloc.c
... | ... | @@ -1535,9 +1535,9 @@ |
1535 | 1535 | |
1536 | 1536 | debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start, |
1537 | 1537 | mem_malloc_end); |
1538 | - | |
1539 | - memset((void *)mem_malloc_start, 0, size); | |
1540 | - | |
1538 | +#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT | |
1539 | + memset((void *)mem_malloc_start, 0x0, size); | |
1540 | +#endif | |
1541 | 1541 | malloc_bin_reloc(); |
1542 | 1542 | } |
1543 | 1543 | |
1544 | 1544 | |
... | ... | @@ -2948,10 +2948,12 @@ |
2948 | 2948 | |
2949 | 2949 | |
2950 | 2950 | /* check if expand_top called, in which case don't need to clear */ |
2951 | +#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT | |
2951 | 2952 | #if MORECORE_CLEARS |
2952 | 2953 | mchunkptr oldtop = top; |
2953 | 2954 | INTERNAL_SIZE_T oldtopsize = chunksize(top); |
2954 | 2955 | #endif |
2956 | +#endif | |
2955 | 2957 | Void_t* mem = mALLOc (sz); |
2956 | 2958 | |
2957 | 2959 | if ((long)n < 0) return NULL; |
2958 | 2960 | |
... | ... | @@ -2977,12 +2979,14 @@ |
2977 | 2979 | |
2978 | 2980 | csz = chunksize(p); |
2979 | 2981 | |
2982 | +#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT | |
2980 | 2983 | #if MORECORE_CLEARS |
2981 | 2984 | if (p == oldtop && csz > oldtopsize) |
2982 | 2985 | { |
2983 | 2986 | /* clear only the bytes from non-freshly-sbrked memory */ |
2984 | 2987 | csz = oldtopsize; |
2985 | 2988 | } |
2989 | +#endif | |
2986 | 2990 | #endif |
2987 | 2991 | |
2988 | 2992 | MALLOC_ZERO(mem, csz - SIZE_SZ); |