Deleted Added
full compact
vfs_bio.c (141337) vfs_bio.c (141539)
1/*-
2 * Copyright (c) 2004 Poul-Henning Kamp
3 * Copyright (c) 1994,1997 John S. Dyson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 25 unchanged lines hidden (view full) ---

34 * Author: John S. Dyson
35 * Significant help during the development and debugging phases
36 * had been provided by David Greenman, also of the FreeBSD core team.
37 *
38 * see man buf(9) for more info.
39 */
40
41#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2004 Poul-Henning Kamp
3 * Copyright (c) 1994,1997 John S. Dyson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 25 unchanged lines hidden (view full) ---

34 * Author: John S. Dyson
35 * Significant help during the development and debugging phases
36 * had been provided by David Greenman, also of the FreeBSD core team.
37 *
38 * see man buf(9) for more info.
39 */
40
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 141337 2005-02-05 01:26:14Z jeff $");
42__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 141539 2005-02-08 20:29:10Z phk $");
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/bio.h>
47#include <sys/conf.h>
48#include <sys/buf.h>
49#include <sys/devicestat.h>
50#include <sys/eventhandler.h>

--- 44 unchanged lines hidden (view full) ---

95 vm_offset_t to);
96static void vm_hold_load_pages(struct buf *bp, vm_offset_t from,
97 vm_offset_t to);
98static void vfs_page_set_valid(struct buf *bp, vm_ooffset_t off,
99 int pageno, vm_page_t m);
100static void vfs_clean_pages(struct buf *bp);
101static void vfs_setdirty(struct buf *bp);
102static void vfs_vmio_release(struct buf *bp);
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/bio.h>
47#include <sys/conf.h>
48#include <sys/buf.h>
49#include <sys/devicestat.h>
50#include <sys/eventhandler.h>

--- 44 unchanged lines hidden (view full) ---

95 vm_offset_t to);
96static void vm_hold_load_pages(struct buf *bp, vm_offset_t from,
97 vm_offset_t to);
98static void vfs_page_set_valid(struct buf *bp, vm_ooffset_t off,
99 int pageno, vm_page_t m);
100static void vfs_clean_pages(struct buf *bp);
101static void vfs_setdirty(struct buf *bp);
102static void vfs_vmio_release(struct buf *bp);
103static void vfs_backgroundwritedone(struct buf *bp);
104static int vfs_bio_clcheck(struct vnode *vp, int size,
105 daddr_t lblkno, daddr_t blkno);
106static int flushbufqueues(int flushdeps);
107static void buf_daemon(void);
108void bremfreel(struct buf *bp);
109
110int vmiodirenable = TRUE;
111SYSCTL_INT(_vfs, OID_AUTO, vmiodirenable, CTLFLAG_RW, &vmiodirenable, 0,

--- 65 unchanged lines hidden (view full) ---

177SYSCTL_INT(_vfs, OID_AUTO, hifreebuffers, CTLFLAG_RW, &hifreebuffers, 0,
178 "XXX Complicatedly unused");
179static int getnewbufcalls;
180SYSCTL_INT(_vfs, OID_AUTO, getnewbufcalls, CTLFLAG_RW, &getnewbufcalls, 0,
181 "Number of calls to getnewbuf");
182static int getnewbufrestarts;
183SYSCTL_INT(_vfs, OID_AUTO, getnewbufrestarts, CTLFLAG_RW, &getnewbufrestarts, 0,
184 "Number of times getnewbuf has had to restart a buffer aquisition");
103static int vfs_bio_clcheck(struct vnode *vp, int size,
104 daddr_t lblkno, daddr_t blkno);
105static int flushbufqueues(int flushdeps);
106static void buf_daemon(void);
107void bremfreel(struct buf *bp);
108
109int vmiodirenable = TRUE;
110SYSCTL_INT(_vfs, OID_AUTO, vmiodirenable, CTLFLAG_RW, &vmiodirenable, 0,

--- 65 unchanged lines hidden (view full) ---

176SYSCTL_INT(_vfs, OID_AUTO, hifreebuffers, CTLFLAG_RW, &hifreebuffers, 0,
177 "XXX Complicatedly unused");
178static int getnewbufcalls;
179SYSCTL_INT(_vfs, OID_AUTO, getnewbufcalls, CTLFLAG_RW, &getnewbufcalls, 0,
180 "Number of calls to getnewbuf");
181static int getnewbufrestarts;
182SYSCTL_INT(_vfs, OID_AUTO, getnewbufrestarts, CTLFLAG_RW, &getnewbufrestarts, 0,
183 "Number of times getnewbuf has had to restart a buffer aquisition");
185static int dobkgrdwrite = 1;
186SYSCTL_INT(_debug, OID_AUTO, dobkgrdwrite, CTLFLAG_RW, &dobkgrdwrite, 0,
187 "Do background writes (honoring the BV_BKGRDWRITE flag)?");
188
189/*
190 * Wakeup point for bufdaemon, as well as indicator of whether it is already
191 * active. Set to 1 when the bufdaemon is already "on" the queue, 0 when it
192 * is idling.
193 */
194static int bd_request;
195

--- 602 unchanged lines hidden (view full) ---

798 * now so we set it generally. This could be set either here
799 * or in biodone() since the I/O is synchronous. We put it
800 * here.
801 */
802int
803bufwrite(struct buf *bp)
804{
805 int oldflags, s;
184
185/*
186 * Wakeup point for bufdaemon, as well as indicator of whether it is already
187 * active. Set to 1 when the bufdaemon is already "on" the queue, 0 when it
188 * is idling.
189 */
190static int bd_request;
191

--- 602 unchanged lines hidden (view full) ---

794 * now so we set it generally. This could be set either here
795 * or in biodone() since the I/O is synchronous. We put it
796 * here.
797 */
798int
799bufwrite(struct buf *bp)
800{
801 int oldflags, s;
806 struct buf *newbp;
807
808 CTR3(KTR_BUF, "bufwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags);
809 if (bp->b_flags & B_INVAL) {
810 brelse(bp);
811 return (0);
812 }
813
814 oldflags = bp->b_flags;
815
816 if (BUF_REFCNT(bp) == 0)
817 panic("bufwrite: buffer is not busy???");
818 s = splbio();
802
803 CTR3(KTR_BUF, "bufwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags);
804 if (bp->b_flags & B_INVAL) {
805 brelse(bp);
806 return (0);
807 }
808
809 oldflags = bp->b_flags;
810
811 if (BUF_REFCNT(bp) == 0)
812 panic("bufwrite: buffer is not busy???");
813 s = splbio();
819 /*
820 * If a background write is already in progress, delay
821 * writing this block if it is asynchronous. Otherwise
822 * wait for the background write to complete.
823 */
824 BO_LOCK(bp->b_bufobj);
825 if (bp->b_vflags & BV_BKGRDINPROG) {
826 if (bp->b_flags & B_ASYNC) {
827 BO_UNLOCK(bp->b_bufobj);
828 splx(s);
829 bdwrite(bp);
830 return (0);
831 }
832 bp->b_vflags |= BV_BKGRDWAIT;
833 msleep(&bp->b_xflags, BO_MTX(bp->b_bufobj), PRIBIO, "bwrbg", 0);
834 if (bp->b_vflags & BV_BKGRDINPROG)
835 panic("bufwrite: still writing");
836 }
837 BO_UNLOCK(bp->b_bufobj);
838
814
815 KASSERT(!(bp->b_vflags & BV_BKGRDINPROG),
816 ("FFS background buffer should not get here %p", bp));
817
839 /* Mark the buffer clean */
840 bundirty(bp);
841
818 /* Mark the buffer clean */
819 bundirty(bp);
820
842 /*
843 * If this buffer is marked for background writing and we
844 * do not have to wait for it, make a copy and write the
845 * copy so as to leave this buffer ready for further use.
846 *
847 * This optimization eats a lot of memory. If we have a page
848 * or buffer shortfall we can't do it.
849 */
850 if (dobkgrdwrite && (bp->b_xflags & BX_BKGRDWRITE) &&
851 (bp->b_flags & B_ASYNC) &&
852 !vm_page_count_severe() &&
853 !buf_dirty_count_severe()) {
854 KASSERT(bp->b_iodone == NULL,
855 ("bufwrite: needs chained iodone (%p)", bp->b_iodone));
821 KASSERT(!(bp->b_xflags & BX_BKGRDWRITE),
822 ("FFS background buffer should not get here %p", bp));
856
823
857 /* get a new block */
858 newbp = geteblk(bp->b_bufsize);
859
860 /*
861 * set it to be identical to the old block. We have to
862 * set b_lblkno and BKGRDMARKER before calling bgetvp()
863 * to avoid confusing the splay tree and gbincore().
864 */
865 memcpy(newbp->b_data, bp->b_data, bp->b_bufsize);
866 newbp->b_lblkno = bp->b_lblkno;
867 newbp->b_xflags |= BX_BKGRDMARKER;
868 BO_LOCK(bp->b_bufobj);
869 bp->b_vflags |= BV_BKGRDINPROG;
870 bgetvp(bp->b_vp, newbp);
871 BO_UNLOCK(bp->b_bufobj);
872 newbp->b_bufobj = &bp->b_vp->v_bufobj;
873 newbp->b_blkno = bp->b_blkno;
874 newbp->b_offset = bp->b_offset;
875 newbp->b_iodone = vfs_backgroundwritedone;
876 newbp->b_flags |= B_ASYNC;
877 newbp->b_flags &= ~B_INVAL;
878
879 /* move over the dependencies */
880 if (LIST_FIRST(&bp->b_dep) != NULL)
881 buf_movedeps(bp, newbp);
882
883 /*
884 * Initiate write on the copy, release the original to
885 * the B_LOCKED queue so that it cannot go away until
886 * the background write completes. If not locked it could go
887 * away and then be reconstituted while it was being written.
888 * If the reconstituted buffer were written, we could end up
889 * with two background copies being written at the same time.
890 */
891 bqrelse(bp);
892 bp = newbp;
893 }
894
895 bp->b_flags &= ~B_DONE;
896 bp->b_ioflags &= ~BIO_ERROR;
897 bp->b_flags |= B_CACHE;
898 bp->b_iocmd = BIO_WRITE;
899
900 bufobj_wref(bp->b_bufobj);
901 vfs_busy_pages(bp, 1);
902

--- 28 unchanged lines hidden (view full) ---

931 curthread->td_proc != updateproc)
932 waitrunningbufspace();
933 }
934
935 return (0);
936}
937
938/*
824 bp->b_flags &= ~B_DONE;
825 bp->b_ioflags &= ~BIO_ERROR;
826 bp->b_flags |= B_CACHE;
827 bp->b_iocmd = BIO_WRITE;
828
829 bufobj_wref(bp->b_bufobj);
830 vfs_busy_pages(bp, 1);
831

--- 28 unchanged lines hidden (view full) ---

860 curthread->td_proc != updateproc)
861 waitrunningbufspace();
862 }
863
864 return (0);
865}
866
867/*
939 * Complete a background write started from bwrite.
940 */
941static void
942vfs_backgroundwritedone(struct buf *bp)
943{
944 struct buf *origbp;
945
946 /*
947 * Find the original buffer that we are writing.
948 */
949 BO_LOCK(bp->b_bufobj);
950 if ((origbp = gbincore(bp->b_bufobj, bp->b_lblkno)) == NULL)
951 panic("backgroundwritedone: lost buffer");
952 BO_UNLOCK(bp->b_bufobj);
953 /*
954 * Process dependencies then return any unfinished ones.
955 */
956 if (LIST_FIRST(&bp->b_dep) != NULL)
957 buf_complete(bp);
958 if (LIST_FIRST(&bp->b_dep) != NULL)
959 buf_movedeps(bp, origbp);
960
961 /*
962 * This buffer is marked B_NOCACHE, so when it is released
963 * by biodone, it will be tossed. We mark it with BIO_READ
964 * to avoid biodone doing a second bufobj_wdrop.
965 */
966 bp->b_flags |= B_NOCACHE;
967 bp->b_iocmd = BIO_READ;
968 bp->b_flags &= ~(B_CACHE | B_DONE);
969 bp->b_iodone = 0;
970 bufdone(bp);
971 BO_LOCK(origbp->b_bufobj);
972 /*
973 * Clear the BV_BKGRDINPROG flag in the original buffer
974 * and awaken it if it is waiting for the write to complete.
975 * If BV_BKGRDINPROG is not set in the original buffer it must
976 * have been released and re-instantiated - which is not legal.
977 */
978 KASSERT((origbp->b_vflags & BV_BKGRDINPROG),
979 ("backgroundwritedone: lost buffer2"));
980 origbp->b_vflags &= ~BV_BKGRDINPROG;
981 if (origbp->b_vflags & BV_BKGRDWAIT) {
982 origbp->b_vflags &= ~BV_BKGRDWAIT;
983 wakeup(&origbp->b_xflags);
984 }
985 BO_UNLOCK(origbp->b_bufobj);
986}
987
988/*
989 * Delayed write. (Buffer is marked dirty). Do not bother writing
990 * anything if the buffer is marked invalid.
991 *
992 * Note that since the buffer must be completely valid, we can safely
993 * set B_CACHE. In fact, we have to set B_CACHE here rather then in
994 * biodone() in order to prevent getblk from writing the buffer
995 * out synchronously.
996 */

--- 2934 unchanged lines hidden ---
868 * Delayed write. (Buffer is marked dirty). Do not bother writing
869 * anything if the buffer is marked invalid.
870 *
871 * Note that since the buffer must be completely valid, we can safely
872 * set B_CACHE. In fact, we have to set B_CACHE here rather then in
873 * biodone() in order to prevent getblk from writing the buffer
874 * out synchronously.
875 */

--- 2934 unchanged lines hidden ---