Commit Graph

67 Commits

Author SHA1 Message Date
Hans Petter Selasky
c743a6bd4f Implement mallocarray_domainset(9) variant of mallocarray(9).
Reviewed by:	kib @
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2021-03-06 11:38:55 +01:00
Mateusz Guzik
828afdda17 malloc: export kernel zones instead of relying on them being power-of-2
Reviewed by:	markj (previous version)
Differential Revision:	https://reviews.freebsd.org/D27026
2020-11-02 17:38:08 +00:00
Vladimir Kondratyev
5d4bf0578f LinuxKPI: Implement ksize() function.
In Linux, ksize() gets the actual amount of memory allocated for a given
object. This commit adds malloc_usable_size() to FreeBSD KPI which does
the same. It also maps LinuxKPI ksize() to newly created function.

ksize() function is used by drm-kmod.

Reviewed by:	hselasky, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D26215
2020-08-29 19:26:31 +00:00
Mark Johnston
96ad26eefb Remove free_domain() and uma_zfree_domain().
These functions were introduced before UMA started ensuring that freed
memory gets placed in domain-local caches.  They no longer serve any
purpose since UMA now provides their functionality by default.  Remove
them to simplyify the kernel memory allocator interfaces a bit.

Reviewed by:	cem, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D25937
2020-08-04 13:58:36 +00:00
Matt Macy
45035becfe Add zfree to zero allocation before free
Key and cookie management typically wants to
avoid information leaks by explicitly zeroing
before free. This routine simplifies that by
permitting consumers to do so without carrying
the size around.

Reviewed by:	jeff@, jhb@
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC (Netgate)
Differential Revision:	https://reviews.freebsd.org/D22790
2020-02-16 00:12:53 +00:00
Mark Johnston
9978bd996b Add malloc_domainset(9) and _domainset variants to other allocator KPIs.
Remove malloc_domain(9) and most other _domain KPIs added in r327900.
The new functions allow the caller to specify a general NUMA domain
selection policy, rather than specifically requesting an allocation from
a specific domain.  The latter policy tends to interact poorly with
M_WAITOK, resulting in situations where a caller is blocked indefinitely
because the specified domain is depleted.  Most existing consumers of
the _domain KPIs are converted to instead use a DOMAINSET_PREF() policy,
in which we fall back to other domains to satisfy the allocation
request.

This change also defines a set of DOMAINSET_FIXED() policies, which
only permit allocations from the specified domain.

Discussed with:	gallatin, jeff
Reported and tested by:	pho (previous version)
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17418
2018-10-30 18:26:34 +00:00
Jonathan T. Looney
0766f278d8 Make UMA and malloc(9) return non-executable memory in most cases.
Most kernel memory that is allocated after boot does not need to be
executable.  There are a few exceptions.  For example, kernel modules
do need executable memory, but they don't use UMA or malloc(9).  The
BPF JIT compiler also needs executable memory and did use malloc(9)
until r317072.

(Note that a side effect of r316767 was that the "small allocation"
path in UMA on amd64 already returned non-executable memory.  This
meant that some calls to malloc(9) or the UMA zone(9) allocator could
return executable memory, while others could return non-executable
memory.  This change makes the behavior consistent.)

This change makes malloc(9) return non-executable memory unless the new
M_EXEC flag is specified.  After this change, the UMA zone(9) allocator
will always return non-executable memory, and a KASSERT will catch
attempts to use the M_EXEC flag to allocate executable memory using
uma_zalloc() or its variants.

Allocations that do need executable memory have various choices.  They
may use the M_EXEC flag to malloc(9), or they may use a different VM
interfact to obtain executable pages.

Now that malloc(9) again allows executable allocations, this change also
reverts most of r317072.

PR:		228927
Reviewed by:	alc, kib, markj, jhb (previous version)
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D15691
2018-06-13 17:04:41 +00:00
Jeff Roberson
93f31533df Document new NUMA related syscalls and utility options.
Sponsored by:	Netflix, Dell/EMC Isilon
2018-03-24 23:58:44 +00:00
Conrad Meyer
bd555da94b malloc(9): Change nominal size to size_t to match standard C
No functional change -- size_t matches unsigned long on all platforms.

Reported by:	bde
Discussed with:	jhb
Sponsored by:	Dell EMC Isilon
2018-01-24 19:37:18 +00:00
Conrad Meyer
0a8edd1cad malloc.9: Fix minor typo from rewording in r327796
Sponsored by:	Dell EMC Isilon
2018-01-10 22:20:49 +00:00
Conrad Meyer
c02fc9607a mallocarray(9): panic if the requested allocation would overflow
Additionally, move the overflow check logic out to WOULD_OVERFLOW() for
consumers to have a common means of testing for overflowing allocations.
WOULD_OVERFLOW() should be a secondary check -- on 64-bit platforms, just
because an allocation won't overflow size_t does not mean it is a sane size
to request.  Callers should be imposing reasonable allocation limits far,
far, below overflow.

Discussed with:	emaste, jhb, kp
Sponsored by:	Dell EMC Isilon
2018-01-10 21:49:45 +00:00
Kristof Provost
fd91e076c1 Introduce mallocarray() in the kernel
Similar to calloc() the mallocarray() function checks for integer
overflows before allocating memory.
It does not zero memory, unless the M_ZERO flag is set.

Reviewed by:	pfg, vangyzen (previous version), imp (previous version)
Obtained from:	OpenBSD
Differential Revision:	https://reviews.freebsd.org/D13766
2018-01-07 13:21:01 +00:00
Christian Brueffer
c4b0ec0d15 Fix issues found by mandoc -Tlint.
MFC after:	1 week
2016-01-08 13:33:22 +00:00
Jonathan T. Looney
1067a2ba68 Consistently enforce the restriction against calling malloc/free when in a
critical section.

uma_zalloc_arg()/uma_zalloc_free() may acquire a sleepable lock on the
zone. The malloc() family of functions may call uma_zalloc_arg() or
uma_zalloc_free().

The malloc(9) man page currently claims that free() will never sleep.
It also implies that the malloc() family of functions will not sleep
when called with M_NOWAIT. However, it is more correct to say that
these functions will not sleep indefinitely. Indeed, they may acquire
a sleepable lock. However, a developer may overlook this restriction
because the WITNESS check that catches attempts to call the malloc()
family of functions within a critical section is inconsistenly
applied.

This change clarifies the language of the malloc(9) man page to clarify
the restriction against calling the malloc() family of functions
while in a critical section or holding a spin lock. It also adds
KASSERTs at appropriate points to make the enforcement of this
restriction more consistent.

PR:		204633
Differential Revision:	https://reviews.freebsd.org/D4197
Reviewed by:	markj
Approved by:	gnn (mentor)
Sponsored by:	Juniper Networks
2015-11-19 14:04:53 +00:00
Joel Dahl
d4d112e34a Misc mdoc fixes:
- Remove superfluous paragraph macros.
- Remove/fix empty or incorrect macros.
- Sort sections into conventional order.
- Terminate quoted strings properly.
- Remove EOL whitespace.
2014-11-23 21:00:00 +00:00
Gleb Smirnoff
ba82ceef53 Remove notes about historical mbuf(9) allocator flags from documentation.
Sponsored by:	Nginx, Inc.
2014-01-16 13:58:55 +00:00
Joel Dahl
788c8ebcb5 Remove trailing whitespace. 2012-11-16 11:56:53 +00:00
Alan Cox
96509a1fd9 M_USE_RESERVE is no longer deprecated. It is once again supported.
Reviewed by:	kib
2012-11-16 06:40:40 +00:00
Kevin Lo
d14fdb79fe Put parenthesis around sizeof args. 2012-07-17 02:05:39 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Kip Macy
c3bd46fe5b update .Dd 2012-01-28 23:30:39 +00:00
Kip Macy
986e5ec7af document M_NODUMP flag 2012-01-28 17:21:12 +00:00
Joel Dahl
c0de7d2f15 The NetBSD Foundation has granted permission to remove clause 3 and 4 from
their software.

Obtained from:	NetBSD
2010-03-02 21:50:36 +00:00
Dag-Erling Smørgrav
1ede983cc9 Retire the MALLOC and FREE macros. They are an abomination unto style(9).
MFC after:	3 months
2008-10-23 15:53:51 +00:00
Ruslan Ermilov
eb085c43f0 s/M_TRYWAIT/M_WAIT/ 2008-03-25 15:44:49 +00:00
Christian Brueffer
a3256b8880 Xref memguard(9) 2005-02-22 17:20:20 +00:00
Ruslan Ermilov
9cbda59000 Sort sections. 2005-01-21 08:36:40 +00:00
Mike Pritchard
2988974b58 Spelling fixes. 2004-06-21 14:11:45 +00:00
Joseph Koshy
d7f29ce72b Cross-reference contigmalloc(9). 2004-03-06 02:13:03 +00:00
Dag-Erling Smørgrav
497ddd5807 Back out previous commit due to objections. 2004-02-16 21:36:59 +00:00
Dag-Erling Smørgrav
6f29aba23f Document the change in M_WAITOK semantics. 2004-02-16 18:46:16 +00:00
Ruslan Ermilov
fe08efe680 mdoc(7): Use the new feature of the .In macro. 2003-09-08 19:57:22 +00:00
Hartmut Brandt
eb74baf398 Rename the section 'locking considerations' into 'context'.
Change the wording in this section to get rid of references to mutexes
and talk about sleeping instead.

Discussed with: jhb@, ru@
2003-06-12 09:03:15 +00:00
Ruslan Ermilov
c8185672b2 Assorted mdoc(7), grammar, spelling, and punctuation fixes.
Approved by:	re (blanket)
2003-05-21 15:49:01 +00:00
Hiten Pandya
73692bebe4 malloc(9) types can be used to identify multiple allocations.
PR: docs/38618
Approved by: des (mentor)
2003-05-06 19:10:17 +00:00
Hartmut Brandt
7081c47416 Forced commit to fill in the fields below for the last commit. Also
bump the date of the man page.

PR:		docs/24797
Reviewed by:	bde, jake, jhb
2003-04-10 10:18:56 +00:00
Hartmut Brandt
473e34ce22 Explicitely document the locking requirements for the malloc interface.
While beeing here also correct the following:

 - list missing macros in the header
 - document MALLOC_DEFINE and MALLOC_DECLARE in the SYNOPSIS section
 - document additional include requirements for MALLOC_DEFINE
 - M_NOWAIT is not 0 anymore
 - remove rotted diagnostic messages
2003-04-09 08:27:32 +00:00
Tom Rhodes
1e73455ba1 Return bits which were removed in revision 1.28.
Requested by:	imp
2003-02-24 05:53:27 +00:00
Philippe Charnier
60dca836a7 The .Fn function 2003-02-05 14:00:46 +00:00
Alfred Perlstein
2a62ffb72d Catch up to WAIT/NOWAIT cleanup. 2003-01-21 08:57:35 +00:00
Sheldon Hearn
63264a559f Add required commas that were ommitted in the previous delta; the
SEE ALSO section's list of manual pages must be comma-separated.
2003-01-19 15:44:32 +00:00
Alfred Perlstein
79525d59b2 Document lock order reversals possible when calling allocation functions
with vnode interlocks held.

Emphasize that users need to be careful with malloc flags versus mbuf
flags.

Remove stale portion in vnode.9 about v_tag.  We don't have it anylonger.

Submitted by: Hiten Pandya <hiten@unixdaemons.com>
2003-01-18 19:51:52 +00:00
Robert Watson
eef9bd4c3f Caution programmers not to confuse M_DONTWAIT with M_NOWAIT. They
are not the same.

Suggested by:	Hiten Pandya <hiten@unixdaemons.com>
2003-01-18 03:25:40 +00:00
Ruslan Ermilov
074ad11567 Spelling: s/then/than/ where appropriate. 2002-12-24 16:52:31 +00:00
Ruslan Ermilov
c2f7105cd0 mdoc(7) police: fixed some wording, kill whitespace at EOL. 2002-03-18 10:52:09 +00:00
Archie Cobbs
44a8ff315e Add realloc() and reallocf(), and make free(NULL, ...) acceptable.
Reviewed by:	alfred
2002-03-13 01:42:33 +00:00
Ruslan Ermilov
32eef9aeb1 mdoc(7) police: Use the new .In macro for #include statements. 2001-10-01 16:09:29 +00:00
John Baldwin
a63e78202c Spelling fix: depreciated -> deprecated. 2001-08-23 23:41:53 +00:00
John Baldwin
e6f6e49f5c Remove refernces to M_ASLEEP/asleep/await. 2001-08-23 23:40:53 +00:00
Jens Schweikhardt
c1f3e4bf21 Removed whitespace at end-of-line; no content changes. I simply did
cd src/share; find man[1-9] -type f|xargs perl -pi -e 's/[ \t]+$//'

BTW, what editors are the culprits? I'm using vim and it shows
me whitespace at EOL in troff files with a thick blue block...

Reviewed by:	Silence from cvs diff -b
MFC after:	7 days
2001-07-14 19:41:16 +00:00