Re: PATCH - raise max_anon limit

From: Andrew Morton
Date: Wed Feb 11 2004 - 17:48:47 EST


Tim Hockin <thockin@xxxxxxx> wrote:
>
> > Wanna test this?
>
> sure:
>
> -------------------
> sysfs: could not mount!
> Unable to handle kernel paging request at virtual address ffffff01

Bah, ordering problem.


25-akpm/fs/super.c | 36 +++++++++++++++++++++---------------
25-akpm/include/linux/fs.h | 1 +
25-akpm/init/main.c | 1 +
3 files changed, 23 insertions(+), 15 deletions(-)

diff -puN fs/super.c~max_anon-use-idr fs/super.c
--- 25/fs/super.c~max_anon-use-idr Wed Feb 11 14:42:15 2004
+++ 25-akpm/fs/super.c Wed Feb 11 14:47:16 2004
@@ -23,6 +23,8 @@
#include <linux/config.h>
#include <linux/module.h>
#include <linux/slab.h>
+#include <linux/init.h>
+#include <asm/semaphore.h>
#include <linux/smp_lock.h>
#include <linux/acct.h>
#include <linux/blkdev.h>
@@ -33,6 +35,7 @@
#include <linux/security.h>
#include <linux/vfs.h>
#include <linux/writeback.h> /* for the emergency remount stuff */
+#include <linux/idr.h>
#include <asm/uaccess.h>


@@ -536,38 +539,41 @@ void emergency_remount(void)
* filesystems which don't use real block-devices. -- jrs
*/

-enum {Max_anon = 256};
-static unsigned long unnamed_dev_in_use[Max_anon/(8*sizeof(unsigned long))];
-static spinlock_t unnamed_dev_lock = SPIN_LOCK_UNLOCKED;/* protects the above */
+static struct idr unnamed_dev_idr;
+static DECLARE_MUTEX(unnamed_dev_sem);

int set_anon_super(struct super_block *s, void *data)
{
int dev;
- spin_lock(&unnamed_dev_lock);
- dev = find_first_zero_bit(unnamed_dev_in_use, Max_anon);
- if (dev == Max_anon) {
- spin_unlock(&unnamed_dev_lock);
- return -EMFILE;
+
+ down(&unnamed_dev_sem);
+ if (idr_pre_get(&unnamed_dev_idr) == 0) {
+ up(&unnamed_dev_sem);
+ return -ENOMEM;
}
- set_bit(dev, unnamed_dev_in_use);
- spin_unlock(&unnamed_dev_lock);
+ dev = idr_get_new(&unnamed_dev_idr, NULL);
+ up(&unnamed_dev_sem);
s->s_dev = MKDEV(0, dev);
return 0;
}
-
EXPORT_SYMBOL(set_anon_super);

void kill_anon_super(struct super_block *sb)
{
int slot = MINOR(sb->s_dev);
+
generic_shutdown_super(sb);
- spin_lock(&unnamed_dev_lock);
- clear_bit(slot, unnamed_dev_in_use);
- spin_unlock(&unnamed_dev_lock);
+ down(&unnamed_dev_sem);
+ idr_remove(&unnamed_dev_idr, slot);
+ up(&unnamed_dev_sem);
}
-
EXPORT_SYMBOL(kill_anon_super);

+void __init unnamed_dev_init(void)
+{
+ idr_init(&unnamed_dev_idr);
+}
+
void kill_litter_super(struct super_block *sb)
{
if (sb->s_root)
diff -puN include/linux/fs.h~max_anon-use-idr include/linux/fs.h
--- 25/include/linux/fs.h~max_anon-use-idr Wed Feb 11 14:45:52 2004
+++ 25-akpm/include/linux/fs.h Wed Feb 11 14:46:06 2004
@@ -1051,6 +1051,7 @@ struct super_block *sget(struct file_sys
void *data);
struct super_block *get_sb_pseudo(struct file_system_type *, char *,
struct super_operations *ops, unsigned long);
+void unnamed_dev_init(void);

/* Alas, no aliases. Too much hassle with bringing module.h everywhere */
#define fops_get(fops) \
diff -puN init/main.c~max_anon-use-idr init/main.c
--- 25/init/main.c~max_anon-use-idr Wed Feb 11 14:48:12 2004
+++ 25-akpm/init/main.c Wed Feb 11 14:48:15 2004
@@ -473,6 +473,7 @@ asmlinkage void __init start_kernel(void
fork_init(num_physpages);
proc_caches_init();
buffer_init();
+ unnamed_dev_init();
security_scaffolding_startup();
vfs_caches_init(num_physpages);
radix_tree_init();

_

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/