mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
mm/mm_heap: Optimizing heap performance, changing the mm_size2ndx and mm-addfreechunk functions to inline functions can improve by about 7%
Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
This commit is contained in:
@@ -27,8 +27,6 @@ if(CONFIG_MM_DEFAULT_MANAGER)
|
|||||||
set(SRCS
|
set(SRCS
|
||||||
mm_initialize.c
|
mm_initialize.c
|
||||||
mm_lock.c
|
mm_lock.c
|
||||||
mm_addfreechunk.c
|
|
||||||
mm_size2ndx.c
|
|
||||||
mm_malloc_size.c
|
mm_malloc_size.c
|
||||||
mm_shrinkchunk.c
|
mm_shrinkchunk.c
|
||||||
mm_brkaddr.c
|
mm_brkaddr.c
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
ifeq ($(CONFIG_MM_DEFAULT_MANAGER),y)
|
ifeq ($(CONFIG_MM_DEFAULT_MANAGER),y)
|
||||||
|
|
||||||
CSRCS += mm_initialize.c mm_lock.c mm_addfreechunk.c mm_size2ndx.c
|
CSRCS += mm_initialize.c mm_lock.c
|
||||||
CSRCS += mm_malloc_size.c mm_shrinkchunk.c mm_brkaddr.c mm_calloc.c
|
CSRCS += mm_malloc_size.c mm_shrinkchunk.c mm_brkaddr.c mm_calloc.c
|
||||||
CSRCS += mm_extend.c mm_free.c mm_mallinfo.c mm_malloc.c mm_foreach.c
|
CSRCS += mm_extend.c mm_free.c mm_mallinfo.c mm_malloc.c mm_foreach.c
|
||||||
CSRCS += mm_memalign.c mm_realloc.c mm_zalloc.c mm_heapmember.c mm_memdump.c
|
CSRCS += mm_memalign.c mm_realloc.c mm_zalloc.c mm_heapmember.c mm_memdump.c
|
||||||
|
|||||||
+52
-9
@@ -292,15 +292,6 @@ void mm_unlock(FAR struct mm_heap_s *heap);
|
|||||||
void mm_shrinkchunk(FAR struct mm_heap_s *heap,
|
void mm_shrinkchunk(FAR struct mm_heap_s *heap,
|
||||||
FAR struct mm_allocnode_s *node, size_t size);
|
FAR struct mm_allocnode_s *node, size_t size);
|
||||||
|
|
||||||
/* Functions contained in mm_addfreechunk.c *********************************/
|
|
||||||
|
|
||||||
void mm_addfreechunk(FAR struct mm_heap_s *heap,
|
|
||||||
FAR struct mm_freenode_s *node);
|
|
||||||
|
|
||||||
/* Functions contained in mm_size2ndx.c *************************************/
|
|
||||||
|
|
||||||
int mm_size2ndx(size_t size);
|
|
||||||
|
|
||||||
/* Functions contained in mm_foreach.c **************************************/
|
/* Functions contained in mm_foreach.c **************************************/
|
||||||
|
|
||||||
void mm_foreach(FAR struct mm_heap_s *heap, mm_node_handler_t handler,
|
void mm_foreach(FAR struct mm_heap_s *heap, mm_node_handler_t handler,
|
||||||
@@ -310,4 +301,56 @@ void mm_foreach(FAR struct mm_heap_s *heap, mm_node_handler_t handler,
|
|||||||
|
|
||||||
void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem, bool delay);
|
void mm_delayfree(FAR struct mm_heap_s *heap, FAR void *mem, bool delay);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Inline Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static inline_function int mm_size2ndx(size_t size)
|
||||||
|
{
|
||||||
|
DEBUGASSERT(size >= MM_MIN_CHUNK);
|
||||||
|
if (size >= MM_MAX_CHUNK)
|
||||||
|
{
|
||||||
|
return MM_NNODES - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size >>= MM_MIN_SHIFT;
|
||||||
|
return flsl(size) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline_function void mm_addfreechunk(FAR struct mm_heap_s *heap,
|
||||||
|
FAR struct mm_freenode_s *node)
|
||||||
|
{
|
||||||
|
FAR struct mm_freenode_s *next;
|
||||||
|
FAR struct mm_freenode_s *prev;
|
||||||
|
size_t nodesize = MM_SIZEOF_NODE(node);
|
||||||
|
int ndx;
|
||||||
|
|
||||||
|
DEBUGASSERT(nodesize >= MM_MIN_CHUNK);
|
||||||
|
DEBUGASSERT(MM_NODE_IS_FREE(node));
|
||||||
|
|
||||||
|
/* Convert the size to a nodelist index */
|
||||||
|
|
||||||
|
ndx = mm_size2ndx(nodesize);
|
||||||
|
|
||||||
|
/* Now put the new node into the next */
|
||||||
|
|
||||||
|
for (prev = &heap->mm_nodelist[ndx],
|
||||||
|
next = heap->mm_nodelist[ndx].flink;
|
||||||
|
next && next->size && MM_SIZEOF_NODE(next) < nodesize;
|
||||||
|
prev = next, next = next->flink);
|
||||||
|
|
||||||
|
/* Does it go in mid next or at the end? */
|
||||||
|
|
||||||
|
prev->flink = node;
|
||||||
|
node->blink = prev;
|
||||||
|
node->flink = next;
|
||||||
|
|
||||||
|
if (next)
|
||||||
|
{
|
||||||
|
/* The new node goes between prev and next */
|
||||||
|
|
||||||
|
next->blink = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __MM_MM_HEAP_MM_H */
|
#endif /* __MM_MM_HEAP_MM_H */
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* mm/mm_heap/mm_addfreechunk.c
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership. The
|
|
||||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <nuttx/mm/mm.h>
|
|
||||||
|
|
||||||
#include "mm_heap/mm.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: mm_addfreechunk
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Add a free chunk to the nodes list. It is assumed that the caller holds
|
|
||||||
* the mm mutex.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
void mm_addfreechunk(FAR struct mm_heap_s *heap,
|
|
||||||
FAR struct mm_freenode_s *node)
|
|
||||||
{
|
|
||||||
FAR struct mm_freenode_s *next;
|
|
||||||
FAR struct mm_freenode_s *prev;
|
|
||||||
size_t nodesize = MM_SIZEOF_NODE(node);
|
|
||||||
int ndx;
|
|
||||||
|
|
||||||
DEBUGASSERT(nodesize >= MM_MIN_CHUNK);
|
|
||||||
DEBUGASSERT(MM_NODE_IS_FREE(node));
|
|
||||||
|
|
||||||
/* Convert the size to a nodelist index */
|
|
||||||
|
|
||||||
ndx = mm_size2ndx(nodesize);
|
|
||||||
|
|
||||||
/* Now put the new node into the next */
|
|
||||||
|
|
||||||
for (prev = &heap->mm_nodelist[ndx],
|
|
||||||
next = heap->mm_nodelist[ndx].flink;
|
|
||||||
next && next->size && MM_SIZEOF_NODE(next) < nodesize;
|
|
||||||
prev = next, next = next->flink);
|
|
||||||
|
|
||||||
/* Does it go in mid next or at the end? */
|
|
||||||
|
|
||||||
prev->flink = node;
|
|
||||||
node->blink = prev;
|
|
||||||
node->flink = next;
|
|
||||||
|
|
||||||
if (next)
|
|
||||||
{
|
|
||||||
/* The new node goes between prev and next */
|
|
||||||
|
|
||||||
next->blink = node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* mm/mm_heap/mm_size2ndx.c
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership. The
|
|
||||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <nuttx/mm/mm.h>
|
|
||||||
|
|
||||||
#include "mm_heap/mm.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: mm_size2ndx
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Convert the size to a nodelist index.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int mm_size2ndx(size_t size)
|
|
||||||
{
|
|
||||||
DEBUGASSERT(size >= MM_MIN_CHUNK);
|
|
||||||
if (size >= MM_MAX_CHUNK)
|
|
||||||
{
|
|
||||||
return MM_NNODES - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size >>= MM_MIN_SHIFT;
|
|
||||||
return flsl(size) - 1;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user