Use lfs_malloc() to manage the blkiov arrays that the cleaner functions use,

since the cleaner is likely to operate in a low-memory condition.
This commit is contained in:
perseant 2005-04-16 17:28:37 +00:00
parent b818779753
commit 94decdd25d
5 changed files with 59 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs.h,v 1.81 2005/04/14 00:58:26 perseant Exp $ */
/* $NetBSD: lfs.h,v 1.82 2005/04/16 17:28:37 perseant Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -138,7 +138,8 @@ typedef struct lfs_res_blk {
#define LFS_NB_IBLOCK 2
#define LFS_NB_CLUSTER 3
#define LFS_NB_CLEAN 4
#define LFS_NB_COUNT 5 /* always last */
#define LFS_NB_BLKIOV 5
#define LFS_NB_COUNT 6 /* always last */
/* Number of reserved memory blocks of each type */
#define LFS_N_SUMMARIES 2
@ -146,10 +147,11 @@ typedef struct lfs_res_blk {
#define LFS_N_IBLOCKS 16 /* In theory ssize/bsize; in practice around 2 */
#define LFS_N_CLUSTERS 16 /* In theory ssize/MAXPHYS */
#define LFS_N_CLEAN 0
#define LFS_N_BLKIOV 1
/* Total count of "large" (non-pool) types */
#define LFS_N_TOTAL (LFS_N_SUMMARIES + LFS_N_SBLOCKS + LFS_N_IBLOCKS + \
LFS_N_CLUSTERS + LFS_N_CLEAN)
LFS_N_CLUSTERS + LFS_N_CLEAN + LFS_N_BLKIOV)
/* Counts for pool types */
#define LFS_N_CL LFS_N_CLUSTERS

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_inode.c,v 1.92 2005/04/14 00:02:46 perseant Exp $ */
/* $NetBSD: lfs_inode.c,v 1.93 2005/04/16 17:28:37 perseant Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.92 2005/04/14 00:02:46 perseant Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.93 2005/04/16 17:28:37 perseant Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@ -81,7 +81,6 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.92 2005/04/14 00:02:46 perseant Exp
#include <sys/buf.h>
#include <sys/vnode.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/trace.h>
#include <sys/resourcevar.h>
@ -713,7 +712,7 @@ lfs_indirtrunc(struct inode *ip, daddr_t lbn, daddr_t dbn,
bap = (int32_t *)bp->b_data; /* XXX ondisk32 */
if (lastbn >= 0) {
MALLOC(copy, int32_t *, fs->lfs_bsize, M_TEMP, M_WAITOK);
copy = (int32_t *)lfs_malloc(fs, fs->lfs_bsize, LFS_NB_IBLOCK);
memcpy((caddr_t)copy, (caddr_t)bap, (u_int)fs->lfs_bsize);
memset((caddr_t)&bap[last + 1], 0,
/* XXX ondisk32 */
@ -766,7 +765,7 @@ lfs_indirtrunc(struct inode *ip, daddr_t lbn, daddr_t dbn,
}
if (copy != NULL) {
FREE(copy, M_TEMP);
lfs_free(fs, copy, LFS_NB_IBLOCK);
} else {
if (bp->b_flags & B_DELWRI) {
LFS_UNLOCK_BUF(bp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_subr.c,v 1.51 2005/04/01 21:59:46 perseant Exp $ */
/* $NetBSD: lfs_subr.c,v 1.52 2005/04/16 17:28:37 perseant Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.51 2005/04/01 21:59:46 perseant Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.52 2005/04/16 17:28:37 perseant Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -124,9 +124,10 @@ lfs_blkatoff(void *v)
char *lfs_res_names[LFS_NB_COUNT] = {
"summary",
"superblock",
"ifile block",
"file block",
"cluster",
"clean",
"blkiov",
};
#endif
@ -136,6 +137,7 @@ int lfs_res_qty[LFS_NB_COUNT] = {
LFS_N_IBLOCKS,
LFS_N_CLUSTERS,
LFS_N_CLEAN,
LFS_N_BLKIOV,
};
void
@ -168,6 +170,8 @@ lfs_setup_resblks(struct lfs *fs)
fs->lfs_resblk[i].size = MAXPHYS;
for (j = 0; j < LFS_N_CLEAN; j++, i++)
fs->lfs_resblk[i].size = MAXPHYS;
for (j = 0; j < LFS_N_BLKIOV; j++, i++)
fs->lfs_resblk[i].size = LFS_MARKV_MAXBLKCNT * sizeof(BLOCK_INFO);
for (i = 0; i < LFS_N_TOTAL; i++) {
fs->lfs_resblk[i].p = malloc(fs->lfs_resblk[i].size,

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_syscalls.c,v 1.104 2005/04/01 21:59:46 perseant Exp $ */
/* $NetBSD: lfs_syscalls.c,v 1.105 2005/04/16 17:28:37 perseant Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.104 2005/04/01 21:59:46 perseant Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.105 2005/04/16 17:28:37 perseant Exp $");
#ifndef LFS
# define LFS /* for prototypes in syscallargs.h */
@ -79,7 +79,6 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.104 2005/04/01 21:59:46 perseant
#include <sys/buf.h>
#include <sys/mount.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/sa.h>
@ -124,6 +123,8 @@ sys_lfs_markv(struct proc *p, void *v, register_t *retval)
BLOCK_INFO *blkiov;
int blkcnt, error;
fsid_t fsid;
struct lfs *fs;
struct mount *mntp;
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
return (error);
@ -131,11 +132,15 @@ sys_lfs_markv(struct proc *p, void *v, register_t *retval)
if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
return (error);
if ((mntp = vfs_getvfs(fsidp)) == NULL)
return (ENOENT);
fs = VFSTOUFS(mntp)->um_lfs;
blkcnt = SCARG(uap, blkcnt);
if ((u_int) blkcnt > LFS_MARKV_MAXBLKCNT)
return (EINVAL);
blkiov = malloc(blkcnt * sizeof(BLOCK_INFO), M_SEGMENT, M_WAITOK);
blkiov = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO), LFS_NB_BLKIOV);
if ((error = copyin(SCARG(uap, blkiov), blkiov,
blkcnt * sizeof(BLOCK_INFO))) != 0)
goto out;
@ -144,7 +149,7 @@ sys_lfs_markv(struct proc *p, void *v, register_t *retval)
copyout(blkiov, SCARG(uap, blkiov),
blkcnt * sizeof(BLOCK_INFO));
out:
free(blkiov, M_SEGMENT);
lfs_free(fs, blkiov, LFS_NB_BLKIOV);
return error;
}
#else
@ -160,6 +165,8 @@ sys_lfs_markv(struct lwp *l, void *v, register_t *retval)
BLOCK_INFO_15 *blkiov15;
int i, blkcnt, error;
fsid_t fsid;
struct lfs *fs;
struct mount *mntp;
if ((error = suser(l->l_proc->p_ucred, &l->l_proc->p_acflag)) != 0)
return (error);
@ -167,12 +174,16 @@ sys_lfs_markv(struct lwp *l, void *v, register_t *retval)
if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
return (error);
if ((mntp = vfs_getvfs(&fsid)) == NULL)
return (ENOENT);
fs = VFSTOUFS(mntp)->um_lfs;
blkcnt = SCARG(uap, blkcnt);
if ((u_int) blkcnt > LFS_MARKV_MAXBLKCNT)
return (EINVAL);
blkiov = malloc(blkcnt * sizeof(BLOCK_INFO), M_SEGMENT, M_WAITOK);
blkiov15 = malloc(blkcnt * sizeof(BLOCK_INFO_15), M_SEGMENT, M_WAITOK);
blkiov = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO), LFS_NB_BLKIOV);
blkiov15 = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO_15), LFS_NB_BLKIOV);
if ((error = copyin(SCARG(uap, blkiov), blkiov15,
blkcnt * sizeof(BLOCK_INFO_15))) != 0)
goto out;
@ -201,8 +212,8 @@ sys_lfs_markv(struct lwp *l, void *v, register_t *retval)
blkcnt * sizeof(BLOCK_INFO_15));
}
out:
free(blkiov, M_SEGMENT);
free(blkiov15, M_SEGMENT);
lfs_free(fs, blkiov, LFS_NB_BLKIOV);
lfs_free(fs, blkiov15, LFS_NB_BLKIOV);
return error;
}
#endif
@ -559,6 +570,8 @@ sys_lfs_bmapv(struct proc *p, void *v, register_t *retval)
BLOCK_INFO *blkiov;
int blkcnt, error;
fsid_t fsid;
struct lfs *fs;
struct mount *mntp;
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
return (error);
@ -566,10 +579,14 @@ sys_lfs_bmapv(struct proc *p, void *v, register_t *retval)
if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
return (error);
if ((mntp = vfs_getvfs(&fsid)) == NULL)
return (ENOENT);
fs = VFSTOUFS(mntp)->um_lfs;
blkcnt = SCARG(uap, blkcnt);
if ((u_int) blkcnt > SIZE_T_MAX / sizeof(BLOCK_INFO))
return (EINVAL);
blkiov = malloc(blkcnt * sizeof(BLOCK_INFO), M_SEGMENT, M_WAITOK);
blkiov = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO), LFS_NB_BLKIOV);
if ((error = copyin(SCARG(uap, blkiov), blkiov,
blkcnt * sizeof(BLOCK_INFO))) != 0)
goto out;
@ -578,7 +595,7 @@ sys_lfs_bmapv(struct proc *p, void *v, register_t *retval)
copyout(blkiov, SCARG(uap, blkiov),
blkcnt * sizeof(BLOCK_INFO));
out:
free(blkiov, M_SEGMENT);
lfs_free(fs, blkiov, LFS_NB_BLKIOV);
return error;
}
#else
@ -595,6 +612,8 @@ sys_lfs_bmapv(struct lwp *l, void *v, register_t *retval)
BLOCK_INFO_15 *blkiov15;
int i, blkcnt, error;
fsid_t fsid;
struct lfs *fs;
struct mount *mntp;
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
return (error);
@ -602,11 +621,15 @@ sys_lfs_bmapv(struct lwp *l, void *v, register_t *retval)
if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
return (error);
if ((mntp = vfs_getvfs(&fsid)) == NULL)
return (ENOENT);
fs = VFSTOUFS(mntp)->um_lfs;
blkcnt = SCARG(uap, blkcnt);
if ((size_t) blkcnt > SIZE_T_MAX / sizeof(BLOCK_INFO))
return (EINVAL);
blkiov = malloc(blkcnt * sizeof(BLOCK_INFO), M_SEGMENT, M_WAITOK);
blkiov15 = malloc(blkcnt * sizeof(BLOCK_INFO_15), M_SEGMENT, M_WAITOK);
blkiov = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO), LFS_NB_BLKIOV);
blkiov15 = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO_15), LFS_NB_BLKIOV);
if ((error = copyin(SCARG(uap, blkiov), blkiov15,
blkcnt * sizeof(BLOCK_INFO_15))) != 0)
goto out;
@ -635,8 +658,8 @@ sys_lfs_bmapv(struct lwp *l, void *v, register_t *retval)
blkcnt * sizeof(BLOCK_INFO_15));
}
out:
free(blkiov, M_SEGMENT);
free(blkiov15, M_SEGMENT);
lfs_free(fs, blkiov, LFS_NB_BLKIOV);
lfs_free(fs, blkiov15, LFS_NB_BLKIOV);
return error;
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vnops.c,v 1.143 2005/04/14 00:58:26 perseant Exp $ */
/* $NetBSD: lfs_vnops.c,v 1.144 2005/04/16 17:28:37 perseant Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.143 2005/04/14 00:58:26 perseant Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.144 2005/04/16 17:28:37 perseant Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -80,7 +80,6 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.143 2005/04/14 00:58:26 perseant Exp
#include <sys/proc.h>
#include <sys/mount.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
#include <sys/pool.h>
#include <sys/signalvar.h>
@ -1313,10 +1312,10 @@ lfs_fcntl(void *v)
blkcnt = blkvp.blkcnt;
if ((u_int) blkcnt > LFS_MARKV_MAXBLKCNT)
return (EINVAL);
blkiov = malloc(blkcnt * sizeof(BLOCK_INFO), M_SEGMENT, M_WAITOK);
blkiov = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO), LFS_NB_BLKIOV);
if ((error = copyin(blkvp.blkiov, blkiov,
blkcnt * sizeof(BLOCK_INFO))) != 0) {
free(blkiov, M_SEGMENT);
lfs_free(fs, blkiov, LFS_NB_BLKIOV);
return error;
}
@ -1336,7 +1335,7 @@ lfs_fcntl(void *v)
if (--fs->lfs_sleepers == 0)
wakeup(&fs->lfs_sleepers);
simple_unlock(&fs->lfs_interlock);
free(blkiov, M_SEGMENT);
lfs_free(fs, blkiov, LFS_NB_BLKIOV);
return error;
case LFCNRECLAIM: