Date: Wed, 14 Nov 2012 20:01:40 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r243040 - in head/sys: amd64/amd64 arm/arm ia64/ia64 mips/mips powerpc/aim sparc64/sparc64 vm Message-ID: <201211142001.qAEK1eNg041343@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Wed Nov 14 20:01:40 2012 New Revision: 243040 URL: http://svnweb.freebsd.org/changeset/base/243040 Log: 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 Modified: head/sys/amd64/amd64/uma_machdep.c head/sys/arm/arm/vm_machdep.c head/sys/ia64/ia64/uma_machdep.c head/sys/mips/mips/uma_machdep.c head/sys/powerpc/aim/mmu_oea64.c head/sys/powerpc/aim/slb.c head/sys/powerpc/aim/uma_machdep.c head/sys/sparc64/sparc64/vm_machdep.c head/sys/vm/vm_kern.c head/sys/vm/vm_page.h Modified: head/sys/amd64/amd64/uma_machdep.c ============================================================================== --- head/sys/amd64/amd64/uma_machdep.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/amd64/amd64/uma_machdep.c Wed Nov 14 20:01:40 2012 (r243040) @@ -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 byt 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) { Modified: head/sys/arm/arm/vm_machdep.c ============================================================================== --- head/sys/arm/arm/vm_machdep.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/arm/arm/vm_machdep.c Wed Nov 14 20:01:40 2012 (r243040) @@ -651,12 +651,7 @@ uma_small_alloc(uma_zone_t zone, int byt 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) { Modified: head/sys/ia64/ia64/uma_machdep.c ============================================================================== --- head/sys/ia64/ia64/uma_machdep.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/ia64/ia64/uma_machdep.c Wed Nov 14 20:01:40 2012 (r243040) @@ -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 byt 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); Modified: head/sys/mips/mips/uma_machdep.c ============================================================================== --- head/sys/mips/mips/uma_machdep.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/mips/mips/uma_machdep.c Wed Nov 14 20:01:40 2012 (r243040) @@ -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 byt 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); Modified: head/sys/powerpc/aim/mmu_oea64.c ============================================================================== --- head/sys/powerpc/aim/mmu_oea64.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/powerpc/aim/mmu_oea64.c Wed Nov 14 20:01:40 2012 (r243040) @@ -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, i *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); Modified: head/sys/powerpc/aim/slb.c ============================================================================== --- head/sys/powerpc/aim/slb.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/powerpc/aim/slb.c Wed Nov 14 20:01:40 2012 (r243040) @@ -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 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, Modified: head/sys/powerpc/aim/uma_machdep.c ============================================================================== --- head/sys/powerpc/aim/uma_machdep.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/powerpc/aim/uma_machdep.c Wed Nov 14 20:01:40 2012 (r243040) @@ -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 byt 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); Modified: head/sys/sparc64/sparc64/vm_machdep.c ============================================================================== --- head/sys/sparc64/sparc64/vm_machdep.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/sparc64/sparc64/vm_machdep.c Wed Nov 14 20:01:40 2012 (r243040) @@ -501,14 +501,7 @@ uma_small_alloc(uma_zone_t zone, int byt 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); Modified: head/sys/vm/vm_kern.c ============================================================================== --- head/sys/vm/vm_kern.c Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/vm/vm_kern.c Wed Nov 14 20:01:40 2012 (r243040) @@ -222,12 +222,7 @@ kmem_alloc_attr(vm_map_t map, vm_size_t 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_ 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 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) { Modified: head/sys/vm/vm_page.h ============================================================================== --- head/sys/vm/vm_page.h Wed Nov 14 19:50:21 2012 (r243039) +++ head/sys/vm/vm_page.h Wed Nov 14 20:01:40 2012 (r243040) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211142001.qAEK1eNg041343>