Date: Thu, 25 Jun 1998 02:02:34 +1000 From: Bruce Evans <bde@zeta.org.au> To: fs@FreeBSD.ORG Subject: lazy syncing of timestamps for special files Message-ID: <199806241602.CAA24267@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
These changes implement delaying until vnode reclamation time of writing timestamps for special files. This is most useful for preventing disk activity on laptops just because something wrote to a terminal (see PR5577 for a broken version). Please review. Bruce diff -c2 src/sys/ufs/ffs/ffs_inode.c~ src/sys/ufs/ffs/ffs_inode.c *** src/sys/ufs/ffs/ffs_inode.c~ Mon Jun 15 19:42:33 1998 --- src/sys/ufs/ffs/ffs_inode.c Wed Jun 24 23:35:29 1998 *************** *** 67,71 **** * from the second and third parameters; the inode change time is always * taken from the current time. If waitfor is set, then wait for the disk ! * write of the inode to complete. */ int --- 67,73 ---- * from the second and third parameters; the inode change time is always * taken from the current time. If waitfor is set, then wait for the disk ! * write of the inode to complete. The IN_LAZYMOD flag is used to specify ! * that the inode has been modified but the modified inode should not be ! * written unless IN_MODIFIED is set. */ int *************** *** 83,107 **** ip = VTOI(vp); if (vp->v_mount->mnt_flag & MNT_RDONLY) { ! ip->i_flag &= ! ~(IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE); return (0); } ! if (((ip->i_flag & ! (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0) && ! (waitfor != MNT_WAIT)) return (0); ! /* ! * XXX: Some callers make a copy too early (before the i/o has ! * completed)... ! */ ! if (ip->i_flag & IN_ACCESS) ! ip->i_atime = access->tv_sec; ! if (ip->i_flag & IN_UPDATE) { ! ip->i_mtime = modify->tv_sec; ! ip->i_modrev++; ! } ! if (ip->i_flag & IN_CHANGE) ! ip->i_ctime = time_second; ! ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE); fs = ip->i_fs; /* --- 85,116 ---- ip = VTOI(vp); if (vp->v_mount->mnt_flag & MNT_RDONLY) { ! ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_LAZYMOD | ! IN_MODIFIED | IN_UPDATE); return (0); } ! if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { ! if (vp->v_type == VBLK || vp->v_type == VCHR) ! ip->i_flag |= IN_LAZYMOD; ! else ! ip->i_flag |= IN_MODIFIED; ! /* ! * XXX some callers copy the access or modification time ! * from the current time too early (before i/o has completed). ! * XXX should set ctime to the same as the atime and mtime in ! * some cases? ! */ ! if (ip->i_flag & IN_ACCESS) ! ip->i_atime = access->tv_sec; ! if (ip->i_flag & IN_UPDATE) { ! ip->i_mtime = modify->tv_sec; ! ip->i_modrev++; ! } ! if (ip->i_flag & IN_CHANGE) ! ip->i_ctime = time_second; ! ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); ! } ! if ((ip->i_flag & IN_MODIFIED) == 0 && waitfor == 0) return (0); ! ip->i_flag &= ~(IN_LAZYMOD | IN_MODIFIED); fs = ip->i_fs; /* diff -c2 src/sys/ufs/ufs/inode.h~ src/sys/ufs/ufs/inode.h *** src/sys/ufs/ufs/inode.h~ Fri Mar 27 18:45:21 1998 --- src/sys/ufs/ufs/inode.h Wed Apr 29 19:34:22 1998 *************** *** 128,131 **** --- 129,133 ---- #define IN_EXLOCK 0x0040 /* File has exclusive lock. */ #define IN_HASHED 0x0080 /* Inode is on hash list */ + #define IN_LAZYMOD 0x0100 /* Modified, but don't write yet. */ #ifdef KERNEL diff -c2 src/sys/ufs/ufs/ufs_inode.c~ src/sys/ufs/ufs/ufs_inode.c *** src/sys/ufs/ufs/ufs_inode.c~ Thu Apr 2 23:22:41 1998 --- src/sys/ufs/ufs/ufs_inode.c Thu Jun 25 00:39:06 1998 *************** *** 117,120 **** --- 117,121 ---- register struct inode *ip; register struct vnode *vp = ap->a_vp; + struct timeval tv; #ifdef QUOTA int i; *************** *** 123,130 **** if (prtactive && vp->v_usecount != 0) vprint("ufs_reclaim: pushing active", vp); /* * Remove the inode from its hash chain. */ - ip = VTOI(vp); ufs_ihashrem(ip); /* --- 124,136 ---- if (prtactive && vp->v_usecount != 0) vprint("ufs_reclaim: pushing active", vp); + ip = VTOI(vp); + if (ip->i_flag & IN_LAZYMOD) { + ip->i_flag |= IN_MODIFIED; + getmicrotime(&tv); + UFS_UPDATE(vp, &tv, &tv, 0); + } /* * Remove the inode from its hash chain. */ ufs_ihashrem(ip); /* diff -c2 src/sys/ufs/ufs/ufs_vnops.c~ src/sys/ufs/ufs/ufs_vnops.c *** src/sys/ufs/ufs/ufs_vnops.c~ Tue Jun 9 23:56:39 1998 --- src/sys/ufs/ufs/ufs_vnops.c Thu Jun 25 00:13:50 1998 *************** *** 147,151 **** if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { tv_sec = time_second; ! ip->i_flag |= IN_MODIFIED; if (ip->i_flag & IN_ACCESS) ip->i_atime = tv_sec; --- 147,154 ---- if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { tv_sec = time_second; ! if (vp->v_type == VBLK || vp->v_type == VCHR) ! ip->i_flag |= IN_LAZYMOD; ! else ! ip->i_flag |= IN_MODIFIED; if (ip->i_flag & IN_ACCESS) ip->i_atime = tv_sec; diff -c2 src/sys/gnu/ext2fs/ext2_inode.c~ src/sys/gnu/ext2fs/ext2_inode.c *** src/sys/gnu/ext2fs/ext2_inode.c~ Mon Jun 22 16:36:50 1998 --- src/sys/gnu/ext2fs/ext2_inode.c Thu Jun 25 01:27:49 1998 *************** *** 73,82 **** /* * Update the access, modified, and inode change times as specified by the ! * IACCESS, IUPDATE, and ICHANGE flags respectively. The IMODIFIED flag is ! * used to specify that the inode needs to be updated but that the times have ! * already been set. The access and modified times are taken from the second ! * and third parameters; the inode change time is always taken from the current ! * time. If waitfor is set, then wait for the disk write of the inode to ! * complete. */ int --- 73,84 ---- /* * Update the access, modified, and inode change times as specified by the ! * IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively. The IN_MODIFIED ! * flag is used to specify that the inode needs to be updated even if none ! * of the times needs to be updated. The access and modified times are taken ! * from the second and third parameters; the inode change time is always ! * taken from the current time. If waitfor is set, then wait for the disk ! * write of the inode to complete. The IN_LAZYMOD flag is used to specify ! * that the inode has been modified but the modified inode should not be ! * written unless IN_MODIFIED is set. */ int *************** *** 94,114 **** ip = VTOI(vp); if (vp->v_mount->mnt_flag & MNT_RDONLY) { ! ip->i_flag &= ! ~(IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE); return (0); } ! if ((ip->i_flag & ! (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0) ! return (0); ! if (ip->i_flag & IN_ACCESS) ! ip->i_atime = access->tv_sec; ! if (ip->i_flag & IN_UPDATE) { ! ip->i_mtime = modify->tv_sec; ! ip->i_modrev++; ! } ! if (ip->i_flag & IN_CHANGE) { ! ip->i_ctime = time_second; } ! ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE); fs = ip->i_e2fs; if (error = bread(ip->i_devvp, --- 96,121 ---- ip = VTOI(vp); if (vp->v_mount->mnt_flag & MNT_RDONLY) { ! ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_LAZYMOD | ! IN_MODIFIED | IN_UPDATE); return (0); } ! if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { ! if (vp->v_type == VBLK || vp->v_type == VCHR) ! ip->i_flag |= IN_LAZYMOD; ! else ! ip->i_flag |= IN_MODIFIED; ! if (ip->i_flag & IN_ACCESS) ! ip->i_atime = access->tv_sec; ! if (ip->i_flag & IN_UPDATE) { ! ip->i_mtime = modify->tv_sec; ! ip->i_modrev++; ! } ! if (ip->i_flag & IN_CHANGE) ! ip->i_ctime = time_second; ! ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); } ! if ((ip->i_flag & IN_MODIFIED) == 0) ! return (0); ! ip->i_flag &= ~(IN_LAZYMOD | IN_MODIFIED); fs = ip->i_e2fs; if (error = bread(ip->i_devvp, To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-fs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806241602.CAA24267>