git: b64e34805596 - stable/14 - buf: Add a runningbufclaim() helper
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 06 Dec 2024 14:51:40 UTC
The branch stable/14 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=b64e34805596130ae702ec9dd536888dd43f7456
commit b64e34805596130ae702ec9dd536888dd43f7456
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-22 13:54:08 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-12-06 14:51:09 +0000
buf: Add a runningbufclaim() helper
No functional change intended.
Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D47696
(cherry picked from commit 4efe531c9d50a803a28d001fab9cc3011eb1f587)
---
sys/kern/vfs_bio.c | 15 ++++++++++++---
sys/sys/buf.h | 2 +-
sys/ufs/ffs/ffs_snapshot.c | 11 ++++-------
sys/ufs/ffs/ffs_vfsops.c | 4 +---
sys/vm/vnode_pager.c | 8 ++++----
5 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index c15e2c99fead..c7c890dd83bd 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -204,7 +204,7 @@ static int sysctl_bufspace(SYSCTL_HANDLER_ARGS);
int vmiodirenable = TRUE;
SYSCTL_INT(_vfs, OID_AUTO, vmiodirenable, CTLFLAG_RW, &vmiodirenable, 0,
"Use the VM system for directory writes");
-long runningbufspace;
+static long runningbufspace;
SYSCTL_LONG(_vfs, OID_AUTO, runningbufspace, CTLFLAG_RD, &runningbufspace, 0,
"Amount of presently outstanding async buffer io");
SYSCTL_PROC(_vfs, OID_AUTO, bufspace, CTLTYPE_LONG|CTLFLAG_MPSAFE|CTLFLAG_RD,
@@ -939,6 +939,16 @@ runningbufwakeup(struct buf *bp)
runningwakeup();
}
+long
+runningbufclaim(struct buf *bp, int space)
+{
+ long old;
+
+ old = atomic_fetchadd_long(&runningbufspace, space);
+ bp->b_runningbufspace = space;
+ return (old);
+}
+
/*
* waitrunningbufspace()
*
@@ -2346,8 +2356,7 @@ bufwrite(struct buf *bp)
/*
* Normal bwrites pipeline writes
*/
- bp->b_runningbufspace = bp->b_bufsize;
- space = atomic_fetchadd_long(&runningbufspace, bp->b_runningbufspace);
+ space = runningbufclaim(bp, bp->b_bufsize);
#ifdef RACCT
if (racct_enable) {
diff --git a/sys/sys/buf.h b/sys/sys/buf.h
index 7fffb52f84f2..7c0ea9605e28 100644
--- a/sys/sys/buf.h
+++ b/sys/sys/buf.h
@@ -514,7 +514,6 @@ extern int nbuf; /* The number of buffer headers */
extern u_long maxswzone; /* Max KVA for swap structures */
extern u_long maxbcache; /* Max KVA for buffer cache */
extern int maxbcachebuf; /* Max buffer cache block size */
-extern long runningbufspace;
extern long hibufspace;
extern int dirtybufthresh;
extern int bdwriteskip;
@@ -531,6 +530,7 @@ buf_mapped(struct buf *bp)
return (bp->b_data != unmapped_buf);
}
+long runningbufclaim(struct buf *, int);
void runningbufwakeup(struct buf *);
void waitrunningbufspace(void);
caddr_t kern_vfs_bio_buffer_alloc(caddr_t v, long physmem_est);
diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c
index fedac50e38fb..ae3b444a19e9 100644
--- a/sys/ufs/ffs/ffs_snapshot.c
+++ b/sys/ufs/ffs/ffs_snapshot.c
@@ -2345,9 +2345,8 @@ ffs_copyonwrite(struct vnode *devvp, struct buf *bp)
TAILQ_EMPTY(&sn->sn_head)) {
VI_UNLOCK(devvp);
if (saved_runningbufspace != 0) {
- bp->b_runningbufspace = saved_runningbufspace;
- atomic_add_long(&runningbufspace,
- bp->b_runningbufspace);
+ (void)runningbufclaim(bp,
+ saved_runningbufspace);
}
return (0); /* Snapshot gone */
}
@@ -2481,10 +2480,8 @@ ffs_copyonwrite(struct vnode *devvp, struct buf *bp)
/*
* I/O on bp will now be started, so count it in runningbufspace.
*/
- if (saved_runningbufspace != 0) {
- bp->b_runningbufspace = saved_runningbufspace;
- atomic_add_long(&runningbufspace, bp->b_runningbufspace);
- }
+ if (saved_runningbufspace != 0)
+ (void)runningbufclaim(bp, saved_runningbufspace);
return (error);
}
diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index 14046de1e7b3..c56603752a50 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -2519,9 +2519,7 @@ ffs_geom_strategy(struct bufobj *bo, struct buf *bp)
return;
}
}
- bp->b_runningbufspace = bp->b_bufsize;
- atomic_add_long(&runningbufspace,
- bp->b_runningbufspace);
+ (void)runningbufclaim(bp, bp->b_bufsize);
} else {
error = ffs_copyonwrite(vp, bp);
if (error != 0 && error != EOPNOTSUPP) {
diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c
index a690e48e07ee..496c3586c321 100644
--- a/sys/vm/vnode_pager.c
+++ b/sys/vm/vnode_pager.c
@@ -702,8 +702,7 @@ vnode_pager_input_smlfs(vm_object_t object, vm_page_t m)
bp->b_vp = vp;
bp->b_bcount = bsize;
bp->b_bufsize = bsize;
- bp->b_runningbufspace = bp->b_bufsize;
- atomic_add_long(&runningbufspace, bp->b_runningbufspace);
+ (void)runningbufclaim(bp, bp->b_bufsize);
/* do the input */
bp->b_iooffset = dbtob(bp->b_blkno);
@@ -1145,7 +1144,7 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count,
bp->b_wcred = crhold(curthread->td_ucred);
pbgetbo(bo, bp);
bp->b_vp = vp;
- bp->b_bcount = bp->b_bufsize = bp->b_runningbufspace = bytecount;
+ bp->b_bcount = bp->b_bufsize = bytecount;
bp->b_iooffset = dbtob(bp->b_blkno);
KASSERT(IDX_TO_OFF(m[0]->pindex - bp->b_pages[0]->pindex) ==
(blkno0 - bp->b_blkno) * DEV_BSIZE +
@@ -1155,7 +1154,8 @@ vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, int count,
(uintmax_t)m[0]->pindex, (uintmax_t)bp->b_pages[0]->pindex,
(uintmax_t)blkno0, (uintmax_t)bp->b_blkno));
- atomic_add_long(&runningbufspace, bp->b_runningbufspace);
+ (void)runningbufclaim(bp, bp->b_bufsize);
+
VM_CNT_INC(v_vnodein);
VM_CNT_ADD(v_vnodepgsin, bp->b_npages);