Added S3FS_MALLOC_TRIM build switch

This commit is contained in:
Takeshi Nakatani 2019-02-03 07:36:17 +00:00
parent c04e8e7a9d
commit 960823fb40

View File

@ -33,26 +33,32 @@ static const int64_t FIVE_GB = 5LL * 1024LL * 1024LL * 1024LL;
} \ } \
} }
// [NOTE]
// s3fs use many small allocated chunk in heap area for stats
// cache and parsing xml, etc. The OS may decide that giving
// this little memory back to the kernel will cause too much
// overhead and delay the operation.
// Address of gratitude, this workaround quotes a document of
// libxml2.( http://xmlsoft.org/xmlmem.html )
// //
// s3fs use many small allocated chunk in heap area for // When valgrind is used to test memory leak of s3fs, a large
// stats cache and parsing xml, etc. The OS may decide // amount of chunk may be reported. You can check the memory
// that giving this little memory back to the kernel // release accurately by defining the S3FS_MALLOC_TRIM flag
// will cause too much overhead and delay the operation. // and building it. Also, when executing s3fs, you can define
// So s3fs calls malloc_trim function to really get the // the MMAP_THRESHOLD environment variable and check more
// memory back. Following macros is prepared for that // accurate memory leak.( see, man 3 free )
// your system does not have it.
//
// Address of gratitude, this workaround quotes a document
// of libxml2.
// http://xmlsoft.org/xmlmem.html
// //
#ifdef S3FS_MALLOC_TRIM
#ifdef HAVE_MALLOC_TRIM #ifdef HAVE_MALLOC_TRIM
#include <malloc.h> #include <malloc.h>
#define S3FS_MALLOCTRIM(pad) malloc_trim(pad)
#define DISPWARN_MALLOCTRIM(str) #else // HAVE_MALLOC_TRIM
// malloc_trim disabled due to performance overhead with many threads/heaps
#define S3FS_MALLOCTRIM(pad) #define S3FS_MALLOCTRIM(pad)
#endif // HAVE_MALLOC_TRIM
#else // S3FS_MALLOC_TRIM
#define S3FS_MALLOCTRIM(pad)
#endif // S3FS_MALLOC_TRIM
#define S3FS_XMLFREEDOC(doc) \ #define S3FS_XMLFREEDOC(doc) \
{ \ { \
xmlFreeDoc(doc); \ xmlFreeDoc(doc); \
@ -74,18 +80,6 @@ static const int64_t FIVE_GB = 5LL * 1024LL * 1024LL * 1024LL;
S3FS_MALLOCTRIM(0); \ S3FS_MALLOCTRIM(0); \
} }
#else // HAVE_MALLOC_TRIM
#define DISPWARN_MALLOCTRIM(str) \
fprintf(stderr, "Warning: %s without malloc_trim is possibility of the use memory increase.\n", program_name.c_str())
#define S3FS_MALLOCTRIM(pad)
#define S3FS_XMLFREEDOC(doc) xmlFreeDoc(doc)
#define S3FS_XMLFREE(ptr) xmlFree(ptr)
#define S3FS_XMLXPATHFREECONTEXT(ctx) xmlXPathFreeContext(ctx)
#define S3FS_XMLXPATHFREEOBJECT(obj) xmlXPathFreeObject(obj)
#endif // HAVE_MALLOC_TRIM
#endif // S3FS_S3_H_ #endif // S3FS_S3_H_
/* /*