Date: Sun, 27 Feb 2011 09:46:51 +0000 From: Bruce Cran <bruce@cran.org.uk> To: Bruce Evans <brde@optusnet.com.au> Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r218966 - head/sys/vm Message-ID: <1298800011.24317.7.camel@core.nessbank> In-Reply-To: <20110224102112.P1871@besplex.bde.org> References: <201102231028.p1NASbET045275@svn.freebsd.org> <20110224063233.Y1100@besplex.bde.org> <1298499116.9366.3.camel@core.nessbank> <20110224102112.P1871@besplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-j8MDx4GezBwO3yPa/kG/ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Thu, 2011-02-24 at 10:36 +1100, Bruce Evans wrote: > > I would cast operand(s) in the expression as necessary to prevent overflow > of subexpressions. vm_pindex_t would work, but I prefer to use a type > related to the subexpressions. Not sure what that is. Maybe just > uintmax_t for safety (even that is not safe if the subexpressions have > large values). So: > > (uintmax_t)swap_bcount * SWAP_META_PAGES * n / mumble. Following Alan's suggestion, I've attached an updated patch which uses a cast to u_long and returns long. -- Bruce Cran --=-j8MDx4GezBwO3yPa/kG/ Content-Disposition: attachment; filename="vm.diff" Content-Type: text/x-patch; name="vm.diff"; charset="us-ascii" Content-Transfer-Encoding: 7bit Index: vm_map.h =================================================================== --- vm_map.h (revision 219050) +++ vm_map.h (working copy) @@ -380,6 +380,6 @@ int flags); int vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t end, int flags); -vm_offset_t vmspace_swap_count(struct vmspace *vmspace); +long vmspace_swap_count(struct vmspace *vmspace); #endif /* _KERNEL */ #endif /* _VM_MAP_ */ Index: swap_pager.c =================================================================== --- swap_pager.c (revision 219050) +++ swap_pager.c (working copy) @@ -2420,13 +2420,13 @@ * if the VM object has any swap use at all the associated map entries * count for at least 1 swap page. */ -vm_offset_t +long vmspace_swap_count(struct vmspace *vmspace) { vm_map_t map; vm_map_entry_t cur; vm_object_t object; - vm_offset_t count, n; + long count, n; map = &vmspace->vm_map; count = 0; @@ -2438,7 +2438,7 @@ if (object->type == OBJT_SWAP && object->un_pager.swp.swp_bcount != 0) { n = (cur->end - cur->start) / PAGE_SIZE; - count += object->un_pager.swp.swp_bcount * + count += (u_long)object->un_pager.swp.swp_bcount * SWAP_META_PAGES * n / object->size + 1; } VM_OBJECT_UNLOCK(object); --=-j8MDx4GezBwO3yPa/kG/--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1298800011.24317.7.camel>