From owner-freebsd-current Fri Jan 3 10:46: 0 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DFB4A37B401; Fri, 3 Jan 2003 10:45:58 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8FF8243E4A; Fri, 3 Jan 2003 10:45:57 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id FAA13006; Sat, 4 Jan 2003 05:45:55 +1100 Date: Sat, 4 Jan 2003 05:46:04 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: current@freebsd.org Cc: phk@freebsd.org Subject: aligned_nblks calculations broken in vm_swap.c Message-ID: <20030104053046.A5138-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG % Index: vm_swap.c % =================================================================== % RCS file: /home/ncvs/src/sys/vm/vm_swap.c,v % retrieving revision 1.127 % retrieving revision 1.128 % diff -u -1 -r1.127 -r1.128 % --- vm_swap.c 3 Jan 2003 09:55:05 -0000 1.127 % +++ vm_swap.c 3 Jan 2003 14:30:46 -0000 1.128 % ... % @@ -353,3 +352,3 @@ % */ % - aligned_nblks = (nblks + (dmmax - 1)) & ~(u_long)(dmmax - 1); % + aligned_nblks = (nblks + dmmax_mask) & ~(u_long)dmmax_mask; % % @@ -472,3 +471,3 @@ % % - aligned_nblks = (nblks + (dmmax - 1)) & ~(u_long)(dmmax - 1); % + aligned_nblks = (nblks + dmmax_mask) & ~(u_long)dmmax_mask; % nswap = aligned_nblks * nswdev; dmmax_mask is ~(dmmax - 1) not (dmmax - 1), so all of these changes are wrong. (New) nearby style bugs: removing the use of dmmax bogotifies a comment which refers to dmmax. (Old) related type bugs: dmmax_mask has the bogus type `int', so it is not clear how it works as a mask on machines with 32-bit ints and 64-bit block numbers. I think it works because all supported machines are 2's complement; this makes the negative value obtained by complementing the bits of (dmmax - 1) right for masking with ints, and C's integral promotion rules then make it right for masking with larger integral types too. ~(u_long)(dmmax - 1) in the old code was more careful about this, except it only works for u_long and smaller block numbers (which is enough for aligned_nblks). Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message