From owner-svn-src-head@FreeBSD.ORG Wed Nov 14 20:01:41 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0148593; Wed, 14 Nov 2012 20:01:41 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id DA3698FC17; Wed, 14 Nov 2012 20:01:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qAEK1eUb041354; Wed, 14 Nov 2012 20:01:40 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qAEK1eNg041343; Wed, 14 Nov 2012 20:01:40 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201211142001.qAEK1eNg041343@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 14 Nov 2012 20:01:40 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Nov 2012 20:01:41 -0000 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" 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 #include +#include #include #include #include @@ -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 #include +#include #include #include #include @@ -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 #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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);