mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-14 06:12:01 +01:00
Flip the semantic of M_NOWAIT to only require the allocation to not
sleep, and perform the page allocations with VM_ALLOC_SYSTEM class. Previously, the allocation was also allowed to completely drain the reserve of the free pages, being translated to VM_ALLOC_INTERRUPT request class for vm_page_alloc() and similar functions. Allow the caller of malloc* to request the 'deep drain' semantic by providing M_USE_RESERVE flag, now translated to VM_ALLOC_INTERRUPT class. Previously, it resulted in less aggressive VM_ALLOC_SYSTEM allocation class. Centralize the translation of the M_* malloc(9) flags in the single inline function malloc2vm_flags(). Discussion started by: "Sears, Steven" <Steven.Sears@netapp.com> Reviewed by: alc, mdf (previous version) Tested by: pho (previous version) MFC after: 2 weeks
This commit is contained in:
parent
6feceb86ab
commit
b32ecf44bc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=243040
@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/systm.h>
|
||||
#include <vm/vm.h>
|
||||
@ -48,12 +49,7 @@ uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
int pflags;
|
||||
|
||||
*flags = UMA_SLAB_PRIV;
|
||||
if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED;
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED;
|
||||
for (;;) {
|
||||
m = vm_page_alloc(NULL, 0, pflags);
|
||||
if (m == NULL) {
|
||||
|
@ -651,12 +651,7 @@ uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
ret = ((void *)kmem_malloc(kmem_map, bytes, M_NOWAIT));
|
||||
return (ret);
|
||||
}
|
||||
if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED;
|
||||
for (;;) {
|
||||
m = vm_page_alloc(NULL, 0, pflags | VM_ALLOC_NOOBJ);
|
||||
if (m == NULL) {
|
||||
|
@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/systm.h>
|
||||
#include <vm/vm.h>
|
||||
@ -46,12 +47,7 @@ uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
int pflags;
|
||||
|
||||
*flags = UMA_SLAB_PRIV;
|
||||
if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED;
|
||||
|
||||
for (;;) {
|
||||
m = vm_page_alloc(NULL, 0, pflags | VM_ALLOC_NOOBJ);
|
||||
|
@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/systm.h>
|
||||
#include <vm/vm.h>
|
||||
@ -48,13 +49,7 @@ uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
void *va;
|
||||
|
||||
*flags = UMA_SLAB_PRIV;
|
||||
|
||||
if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED;
|
||||
|
||||
for (;;) {
|
||||
m = vm_page_alloc_freelist(VM_FREELIST_DIRECT, pflags);
|
||||
|
@ -119,6 +119,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/ktr.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/msgbuf.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/rwlock.h>
|
||||
@ -1368,13 +1369,7 @@ moea64_uma_page_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
|
||||
*flags = UMA_SLAB_PRIV;
|
||||
needed_lock = !PMAP_LOCKED(kernel_pmap);
|
||||
|
||||
if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED;
|
||||
|
||||
for (;;) {
|
||||
m = vm_page_alloc(NULL, 0, pflags | VM_ALLOC_NOOBJ);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/systm.h>
|
||||
@ -483,12 +484,7 @@ slb_uma_real_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
realmax = platform_real_maxaddr();
|
||||
|
||||
*flags = UMA_SLAB_PRIV;
|
||||
if ((wait & (M_NOWAIT | M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED;
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED;
|
||||
|
||||
for (;;) {
|
||||
m = vm_page_alloc_contig(NULL, 0, pflags, 1, 0, realmax,
|
||||
|
@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sysctl.h>
|
||||
@ -56,12 +57,7 @@ uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
int pflags;
|
||||
|
||||
*flags = UMA_SLAB_PRIV;
|
||||
if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED;
|
||||
|
||||
for (;;) {
|
||||
m = vm_page_alloc(NULL, 0, pflags | VM_ALLOC_NOOBJ);
|
||||
|
@ -501,14 +501,7 @@ uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
|
||||
PMAP_STATS_INC(uma_nsmall_alloc);
|
||||
|
||||
*flags = UMA_SLAB_PRIV;
|
||||
|
||||
if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
|
||||
|
||||
if (wait & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(wait) | VM_ALLOC_WIRED;
|
||||
|
||||
for (;;) {
|
||||
m = vm_page_alloc(NULL, 0, pflags | VM_ALLOC_NOOBJ);
|
||||
|
@ -222,12 +222,7 @@ kmem_alloc_attr(vm_map_t map, vm_size_t size, int flags, vm_paddr_t low,
|
||||
vm_object_reference(object);
|
||||
vm_map_insert(map, object, offset, addr, addr + size, VM_PROT_ALL,
|
||||
VM_PROT_ALL, 0);
|
||||
if ((flags & (M_NOWAIT | M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOBUSY;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_NOBUSY;
|
||||
if (flags & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY;
|
||||
VM_OBJECT_LOCK(object);
|
||||
end_offset = offset + size;
|
||||
for (; offset < end_offset; offset += PAGE_SIZE) {
|
||||
@ -296,14 +291,7 @@ kmem_alloc_contig(vm_map_t map, vm_size_t size, int flags, vm_paddr_t low,
|
||||
vm_object_reference(object);
|
||||
vm_map_insert(map, object, offset, addr, addr + size, VM_PROT_ALL,
|
||||
VM_PROT_ALL, 0);
|
||||
if ((flags & (M_NOWAIT | M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOBUSY;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_NOBUSY;
|
||||
if (flags & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
if (flags & M_NODUMP)
|
||||
pflags |= VM_ALLOC_NODUMP;
|
||||
pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY;
|
||||
VM_OBJECT_LOCK(object);
|
||||
tries = 0;
|
||||
retry:
|
||||
@ -487,15 +475,7 @@ kmem_back(vm_map_t map, vm_offset_t addr, vm_size_t size, int flags)
|
||||
entry->wired_count == 0 && (entry->eflags & MAP_ENTRY_IN_TRANSITION)
|
||||
== 0, ("kmem_back: entry not found or misaligned"));
|
||||
|
||||
if ((flags & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
|
||||
pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
|
||||
else
|
||||
pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
|
||||
|
||||
if (flags & M_ZERO)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
if (flags & M_NODUMP)
|
||||
pflags |= VM_ALLOC_NODUMP;
|
||||
pflags = malloc2vm_flags(flags) | VM_ALLOC_WIRED;
|
||||
|
||||
VM_OBJECT_LOCK(kmem_object);
|
||||
for (i = 0; i < size; i += PAGE_SIZE) {
|
||||
|
@ -347,6 +347,22 @@ vm_page_t PHYS_TO_VM_PAGE(vm_paddr_t pa);
|
||||
#define VM_ALLOC_COUNT_SHIFT 16
|
||||
#define VM_ALLOC_COUNT(count) ((count) << VM_ALLOC_COUNT_SHIFT)
|
||||
|
||||
#ifdef M_NOWAIT
|
||||
static inline int
|
||||
malloc2vm_flags(int malloc_flags)
|
||||
{
|
||||
int pflags;
|
||||
|
||||
pflags = (malloc_flags & M_USE_RESERVE) != 0 ? VM_ALLOC_INTERRUPT :
|
||||
VM_ALLOC_SYSTEM;
|
||||
if ((malloc_flags & M_ZERO) != 0)
|
||||
pflags |= VM_ALLOC_ZERO;
|
||||
if ((malloc_flags & M_NODUMP) != 0)
|
||||
pflags |= VM_ALLOC_NODUMP;
|
||||
return (pflags);
|
||||
}
|
||||
#endif
|
||||
|
||||
void vm_page_busy(vm_page_t m);
|
||||
void vm_page_flash(vm_page_t m);
|
||||
void vm_page_io_start(vm_page_t m);
|
||||
|
Loading…
Reference in New Issue
Block a user