From f6468e9eb2c9de9b9af113b10cd1a0b3c64c0e42 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 26 Jan 2010 12:50:33 -0800 Subject: [PATCH] HAMMER VFS - Disallow rebalancing on small-memory machines * Rebalancing may have to hold upwards of 3900 buffers locked in the worst case, disallow the operation on machines which do not configure enough buffer cache buffers. --- sys/vfs/hammer/hammer.h | 10 ++++++++++ sys/vfs/hammer/hammer_ioctl.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/sys/vfs/hammer/hammer.h b/sys/vfs/hammer/hammer.h index e883edf5ba..b3cae002a0 100644 --- a/sys/vfs/hammer/hammer.h +++ b/sys/vfs/hammer/hammer.h @@ -856,6 +856,16 @@ struct hammer_sync_info { int waitfor; }; +/* + * Minium buffer cache bufs required to rebalance the B-Tree. + * This is because we must hold the children and the children's children + * locked. Even this might not be enough if things are horribly out + * of balance. + */ +#define HAMMER_REBALANCE_MIN_BUFS \ + (HAMMER_BTREE_LEAF_ELMS * HAMMER_BTREE_LEAF_ELMS) + + #endif /* diff --git a/sys/vfs/hammer/hammer_ioctl.c b/sys/vfs/hammer/hammer_ioctl.c index 7d68e13c92..e099a36439 100644 --- a/sys/vfs/hammer/hammer_ioctl.c +++ b/sys/vfs/hammer/hammer_ioctl.c @@ -88,6 +88,17 @@ hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag, } break; case HAMMERIOC_REBALANCE: + /* + * Rebalancing needs to lock a lot of B-Tree nodes. The + * children and children's children. Systems with very + * little memory will not be able to do it. + */ + if (error == 0 && nbuf < HAMMER_REBALANCE_MIN_BUFS) { + kprintf("hammer: System has insufficient buffers " + "to rebalance the tree. nbuf < %d\n", + HAMMER_REBALANCE_MIN_BUFS); + error = ENOSPC; + } if (error == 0) { error = hammer_ioc_rebalance(&trans, ip, (struct hammer_ioc_rebalance *)data); -- 2.11.4.GIT