views:

109

answers:

3

if you know there is one, can you let me know what its for ? if not please say so : ) thanks.

Signature : void * malloc(unsigned long size, struct malloc_type type, int flags);

for example. other flags are...

 M_ZERO  
         Causes the allocated memory to be set to all zeros.

 M_WAITOK
         Indicates that it is OK to wait for resources.  If the request
         cannot be immediately fulfilled, the current process is put to
         sleep to wait for resources to be released by other processes.
         The malloc(), realloc(), and reallocf() functions cannot return
         NULL if M_WAITOK is specified.**

This is the root of my confusion

EDIT:

The clarification for M_FAST is made in my answer below.

A: 

If the docs don't mention an M_FAST flag, and it's not defined in the <stdlib.h> header on the platform, you can safely assume that it doesn't exist (or rather, that if it did, it wouldn't be a stable API suitable for use in user code).

Stephen Canon
Kernel's malloc flags are in /sys/malloc.h in FreeBSD
Petros
+3  A: 

The FreeBSD kernel does have it's own implementation of malloc() that has a different signature than the standard library's:

When writing kernel code (for many systems, not just FreeBSD) there are often constraints that prevent kernel code from using the standard library, so there's usually a kernel library that provides similar functionality with varying range of similarities and differences from the standard.

Like it or not, kernel programming is special.

However, I see no evidence of support for an M_FAST flag in the FreeBSD kernel malloc() routine.

If one did ever exist, maybe it signaled that a mutex should not be taken, perhaps indicating that the caller is certain that none is necessary or preferring an allocation failure to blocking on a synchronization object - I'm just speculating what might have been, if it ever was.

Michael Burr
Thank you so much for clearing up the confusion sir, you just made my day :). I posted the clarification about the M_WAIT.
Gollum
A: 

M_FAST is not a flag, below. The answer was always there in the question I posted :P

It is a malloc_type type argument, which is used to perform statistics on the memory allocation. For more information refer to the documentation from FreeBSD below, (where, M_FOOBUF = M_FAST)

The type argument is used to perform statistics on memory usage, and for basic sanity checks. It can be used to identify multiple allocations. The statistics can be examined by `vmstat -m'.

A type is defined using struct malloc_type via the MALLOC_DECLARE() and MALLOC_DEFINE() macros.

/* sys/something/foo_extern.h */
MALLOC_DECLARE(M_FOOBUF);

/* sys/something/foo_main.c */
MALLOC_DEFINE(M_FOOBUF,"foobuffers","Buffers to foo data in to the ether");

/* sys/something/foo_subr.c */   
buf = malloc(sizeof *buf, M_FOOBUF, M_NOWAIT);

In order to use MALLOC_DEFINE(), one must include (instead of ) and

Gollum