diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2018-04-17 15:50:06 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2018-04-17 15:50:06 +0000 |
commit | f75248742b9a46c5467ce5c4671f8eb613e68581 (patch) | |
tree | 0c1df735528bebb953fdfdb8f458bae022f87503 /sys | |
parent | 5920db117427ac6fd430c44eb4918aabe1c4ffe0 (diff) |
- Make rnd hints avoid the brk area. The rnd allocator refuses to allocate in
the brk area anyway.
- Use a larger hint bound to spread the allocations more for the 32-bit case
- Simplified the overy abstracted brs/stack allocator and switch of
guard pages for the brk case. This allows i386 some extra space,
depending on memory usage patterns.
- Reduce brk area on i386 to give the rnd space more room
ok stefan@ sthen@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/include/vmparam.h | 4 | ||||
-rw-r--r-- | sys/uvm/uvm_addr.c | 73 | ||||
-rw-r--r-- | sys/uvm/uvm_map.c | 14 |
3 files changed, 34 insertions, 57 deletions
diff --git a/sys/arch/i386/include/vmparam.h b/sys/arch/i386/include/vmparam.h index 9e6ab08ee37..d7ff0523b86 100644 --- a/sys/arch/i386/include/vmparam.h +++ b/sys/arch/i386/include/vmparam.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmparam.h,v 1.55 2015/11/01 20:09:59 miod Exp $ */ +/* $OpenBSD: vmparam.h,v 1.56 2018/04/17 15:50:05 otto Exp $ */ /* $NetBSD: vmparam.h,v 1.15 1994/10/27 04:16:34 cgd Exp $ */ /*- @@ -54,7 +54,7 @@ #define MAXDSIZ (3UL*1024*1024*1024) /* max data size */ #endif #ifndef BRKSIZ -#define BRKSIZ (1024*1024*1024) /* heap gap size */ +#define BRKSIZ (128*1024*1024) /* heap gap size */ #endif #ifndef DFLSSIZ #define DFLSSIZ (4*1024*1024) /* initial stack size limit */ diff --git a/sys/uvm/uvm_addr.c b/sys/uvm/uvm_addr.c index aa2f2e27459..9dd0b22ad91 100644 --- a/sys/uvm/uvm_addr.c +++ b/sys/uvm/uvm_addr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_addr.c,v 1.25 2018/04/10 12:27:01 otto Exp $ */ +/* $OpenBSD: uvm_addr.c,v 1.26 2018/04/17 15:50:05 otto Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl> @@ -1322,15 +1322,6 @@ uaddr_pivot_print(struct uvm_addr_state *uaddr_p, boolean_t full, #ifndef SMALL_KERNEL /* - * Strategy for uaddr_stack_brk_select. - */ -struct uaddr_bs_strat { - vaddr_t start; /* Start of area. */ - vaddr_t end; /* End of area. */ - int dir; /* Search direction. */ -}; - -/* * Stack/break allocator. * * Stack area is grown into in the opposite direction of the stack growth, @@ -1355,53 +1346,41 @@ uaddr_stack_brk_select(struct vm_map *map, struct uvm_addr_state *uaddr, vsize_t sz, vaddr_t align, vaddr_t offset, vm_prot_t prot, vaddr_t hint) { - vsize_t before_gap, after_gap; - int stack_idx, brk_idx; - struct uaddr_bs_strat strat[2], *s; - vsize_t sb_size; + vaddr_t start; + vaddr_t end; + vsize_t before_gap; + vsize_t after_gap; + int dir; - /* - * Choose gap size and if the stack is searched before or after the - * brk area. - */ - before_gap = ((arc4random() & 0x3) + 1) << PAGE_SHIFT; - after_gap = ((arc4random() & 0x3) + 1) << PAGE_SHIFT; + /* Set up brk search strategy. */ + start = MAX(map->b_start, uaddr->uaddr_minaddr); + end = MIN(map->b_end, uaddr->uaddr_maxaddr); + before_gap = 0; + after_gap = 0; + dir = -1; /* Opposite of brk() growth. */ - sb_size = (map->s_end - map->s_start) + (map->b_end - map->b_start); - sb_size >>= PAGE_SHIFT; - if (arc4random_uniform(MAX(sb_size, 0xffffffff)) > - map->b_end - map->b_start) { - brk_idx = 1; - stack_idx = 0; - } else { - brk_idx = 0; - stack_idx = 1; + if (end - start >= sz) { + if (uvm_addr_linsearch(map, uaddr, entry_out, addr_out, + 0, sz, align, offset, dir, start, end - sz, + before_gap, after_gap) == 0) + return 0; } /* Set up stack search strategy. */ - s = &strat[stack_idx]; - s->start = MAX(map->s_start, uaddr->uaddr_minaddr); - s->end = MIN(map->s_end, uaddr->uaddr_maxaddr); + start = MAX(map->s_start, uaddr->uaddr_minaddr); + end = MIN(map->s_end, uaddr->uaddr_maxaddr); + before_gap = ((arc4random() & 0x3) + 1) << PAGE_SHIFT; + after_gap = ((arc4random() & 0x3) + 1) << PAGE_SHIFT; #ifdef MACHINE_STACK_GROWS_UP - s->dir = -1; + dir = -1; #else - s->dir = 1; + dir = 1; #endif - - /* Set up brk search strategy. */ - s = &strat[brk_idx]; - s->start = MAX(map->b_start, uaddr->uaddr_minaddr); - s->end = MIN(map->b_end, uaddr->uaddr_maxaddr); - s->dir = -1; /* Opposite of brk() growth. */ - - /* Linear search for space. */ - for (s = &strat[0]; s < &strat[nitems(strat)]; s++) { - if (s->end - s->start < sz) - continue; + if (end - start >= sz + before_gap + after_gap) { if (uvm_addr_linsearch(map, uaddr, entry_out, addr_out, - 0, sz, align, offset, s->dir, s->start, s->end - sz, + 0, sz, align, offset, dir, start, end - sz, before_gap, after_gap) == 0) - return 0; + return 0; } return ENOMEM; diff --git a/sys/uvm/uvm_map.c b/sys/uvm/uvm_map.c index 15f5ad450ae..634bff84e7f 100644 --- a/sys/uvm/uvm_map.c +++ b/sys/uvm/uvm_map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_map.c,v 1.235 2018/04/17 14:39:59 stefan Exp $ */ +/* $OpenBSD: uvm_map.c,v 1.236 2018/04/17 15:50:05 otto Exp $ */ /* $NetBSD: uvm_map.c,v 1.86 2000/11/27 08:40:03 chs Exp $ */ /* @@ -3989,19 +3989,17 @@ uvm_map_hint(struct vmspace *vm, vm_prot_t prot, vaddr_t minaddr, #endif #if defined (__LP64__) - spacing = (MIN((4UL * 1024 * 1024 * 1024), BRKSIZ) - 1); + spacing = MIN(4UL * 1024 * 1024 * 1024, MAXDSIZ) - 1; #else - spacing = (MIN((256 * 1024 * 1024), BRKSIZ) - 1); + spacing = MIN(1 * 1024 * 1024 * 1024, MAXDSIZ) - 1; #endif - addr = (vaddr_t)vm->vm_daddr; /* * Start malloc/mmap after the brk. - * If the random spacing area has been used up, - * the brk area becomes fair game for mmap as well. */ - if (vm->vm_dused < spacing >> PAGE_SHIFT) - addr += BRKSIZ; + addr = (vaddr_t)vm->vm_daddr + BRKSIZ; + addr = MAX(addr, minaddr); + if (addr < maxaddr) { while (spacing > maxaddr - addr) spacing >>= 1; |