From ef82c280fd63448b3f8199a53ecc7768e393ecdc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 2 Nov 2014 12:11:20 -0600 Subject: [PATCH] MM: Minimum memory allocation must to up to 32 if sizeof pointer is 8-bytes --- arch/sim/include/limits.h | 11 +++++++--- include/nuttx/mm/mm.h | 42 +++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/arch/sim/include/limits.h b/arch/sim/include/limits.h index 5a8d7c54e8..fabb97d8ee 100644 --- a/arch/sim/include/limits.h +++ b/arch/sim/include/limits.h @@ -77,10 +77,15 @@ #define LLONG_MAX 9223372036854775807LL #define ULLONG_MAX 18446744073709551615ULL -/* A pointer is 4 bytes */ +/* A pointer is 4 or 8 bytes */ #define PTR_MIN (-PTR_MAX - 1) -#define PTR_MAX 2147483647 -#define UPTR_MAX 4294967295U +#if !defined(CONFIG_HOST_X86_64) || defined(CONFIG_SIM_M32) +# define PTR_MAX 2147483647 +# define UPTR_MAX 4294967295U +#else +# define PTR_MAX 9223372036854775807LL +# define UPTR_MAX 18446744073709551615ULL +#endif #endif /* __ARCH_SIM_INCLUDE_LIMITS_H */ diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 707d7f7daa..97c260f501 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -112,24 +112,44 @@ /* These definitions define the characteristics of allocator * * MM_MIN_SHIFT is used to define MM_MIN_CHUNK. - * MM_MIN_CHUNK - is the smallest physical chunk that can - * be allocated. It must be at least a large as - * sizeof(struct mm_freenode_s). Larger values may - * improve performance slightly, but will waste memory - * due to quantization losses. + * MM_MIN_CHUNK - is the smallest physical chunk that can be allocated. It + * must be at least a large as sizeof(struct mm_freenode_s). Larger values + * may improve performance slightly, but will waste memory due to + * quantization losses. * * MM_MAX_SHIFT is used to define MM_MAX_CHUNK - * MM_MAX_CHUNK is the largest, contiguous chunk of memory - * that can be allocated. It can range from 16-bytes to - * 4Gb. Larger values of MM_MAX_SHIFT can cause larger - * data structure sizes and, perhaps, minor performance - * losses. + * MM_MAX_CHUNK is the largest, contiguous chunk of memory that can be + * allocated. It can range from 16-bytes to 4Gb. Larger values of + * MM_MAX_SHIFT can cause larger data structure sizes and, perhaps, + * minor performance losses. + */ + +#if defined(CONFIG_MM_SMALL) && UINTPTR_MAX <= UINT32_MAX +/* Two byte offsets; Pointers may be 2 or 4 bytes; + * sizeof(struct mm_freenode_s) is 8 or 12 bytes. + * REVISIT: We could do better on machines with 16-bit addressing. */ -#ifdef CONFIG_MM_SMALL # define MM_MIN_SHIFT 4 /* 16 bytes */ # define MM_MAX_SHIFT 15 /* 32 Kb */ + +#elif defined(CONFIG_HAVE_LONG_LONG) +/* Four byte offsets; Pointers may be 4 or 8 bytes + * sizeof(struct mm_freenode_s) is 16 or 24 bytes. + */ + +# if UINTPTR_MAX <= UINT32_MAX +# define MM_MIN_SHIFT 4 /* 16 bytes */ +# elif UINTPTR_MAX <= UINT64_MAX +# define MM_MIN_SHIFT 5 /* 32 bytes */ +# endif +# define MM_MAX_SHIFT 22 /* 4 Mb */ + #else +/* Four byte offsets; Pointers must be 4 bytes. + * sizeof(struct mm_freenode_s) is 16 bytes. + */ + # define MM_MIN_SHIFT 4 /* 16 bytes */ # define MM_MAX_SHIFT 22 /* 4 Mb */ #endif