* [PATCH 3/5] hugetlbfs: use call_once()
[not found] ` <20080310150026.GA6407@APFDCB5C>
@ 2008-03-10 15:01 ` Akinobu Mita
2008-03-10 15:03 ` [PATCH 4/5] shmem: " Akinobu Mita
0 siblings, 1 reply; 6+ messages in thread
From: Akinobu Mita @ 2008-03-10 15:01 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm, William Irwin, linux-fsdevel
This patch defers mounting hugetlbfs till hugetlb_file_setup() is
called first time by using call_once().
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: William Irwin <wli@holomorphy.com>
---
fs/hugetlbfs/inode.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
Index: 2.6-rc/fs/hugetlbfs/inode.c
===================================================================
--- 2.6-rc.orig/fs/hugetlbfs/inode.c
+++ 2.6-rc/fs/hugetlbfs/inode.c
@@ -31,6 +31,7 @@
#include <linux/dnotify.h>
#include <linux/statfs.h>
#include <linux/security.h>
+#include <linux/once.h>
#include <asm/uaccess.h>
@@ -903,6 +904,13 @@ static struct file_system_type hugetlbfs
static struct vfsmount *hugetlbfs_vfsmount;
+static int init_hugetlbfs_vfsmount(void)
+{
+ hugetlbfs_vfsmount = kern_mount(&hugetlbfs_fs_type);
+
+ return IS_ERR(hugetlbfs_vfsmount) ? PTR_ERR(hugetlbfs_vfsmount) : 0;
+}
+
static int can_do_hugetlb_shm(void)
{
return likely(capable(CAP_IPC_LOCK) ||
@@ -912,14 +920,16 @@ static int can_do_hugetlb_shm(void)
struct file *hugetlb_file_setup(const char *name, size_t size)
{
- int error = -ENOMEM;
+ int error;
struct file *file;
struct inode *inode;
struct dentry *dentry, *root;
struct qstr quick_string;
+ static DEFINE_ONCE(once);
- if (!hugetlbfs_vfsmount)
- return ERR_PTR(-ENOENT);
+ error = call_once(&once, init_hugetlbfs_vfsmount);
+ if (error)
+ return ERR_PTR(error);
if (!can_do_hugetlb_shm())
return ERR_PTR(-EPERM);
@@ -970,7 +980,6 @@ out_shm_unlock:
static int __init init_hugetlbfs_fs(void)
{
int error;
- struct vfsmount *vfsmount;
error = bdi_init(&hugetlbfs_backing_dev_info);
if (error)
@@ -986,18 +995,9 @@ static int __init init_hugetlbfs_fs(void
if (error)
goto out;
- vfsmount = kern_mount(&hugetlbfs_fs_type);
-
- if (!IS_ERR(vfsmount)) {
- hugetlbfs_vfsmount = vfsmount;
- return 0;
- }
-
- error = PTR_ERR(vfsmount);
-
+ return 0;
out:
- if (error)
- kmem_cache_destroy(hugetlbfs_inode_cachep);
+ kmem_cache_destroy(hugetlbfs_inode_cachep);
out2:
bdi_destroy(&hugetlbfs_backing_dev_info);
return error;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] shmem: use call_once()
2008-03-10 15:01 ` [PATCH 3/5] hugetlbfs: use call_once() Akinobu Mita
@ 2008-03-10 15:03 ` Akinobu Mita
2008-03-10 15:05 ` [PATCH 5/5] tiny-shmem: " Akinobu Mita
2008-03-10 22:15 ` [PATCH 4/5] shmem: " Hugh Dickins
0 siblings, 2 replies; 6+ messages in thread
From: Akinobu Mita @ 2008-03-10 15:03 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm, linux-fsdevel
This patch defers mounting tmpfs till shmem_file_setup() is
called first time by using call_once().
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
mm/shmem.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
Index: 2.6-rc/mm/shmem.c
===================================================================
--- 2.6-rc.orig/mm/shmem.c
+++ 2.6-rc/mm/shmem.c
@@ -50,6 +50,7 @@
#include <linux/migrate.h>
#include <linux/highmem.h>
#include <linux/seq_file.h>
+#include <linux/once.h>
#include <asm/uaccess.h>
#include <asm/div64.h>
@@ -2520,7 +2521,6 @@ static struct file_system_type tmpfs_fs_
.get_sb = shmem_get_sb,
.kill_sb = kill_litter_super,
};
-static struct vfsmount *shm_mnt;
static int __init init_tmpfs(void)
{
@@ -2540,27 +2540,29 @@ static int __init init_tmpfs(void)
goto out2;
}
- shm_mnt = vfs_kern_mount(&tmpfs_fs_type, MS_NOUSER,
- tmpfs_fs_type.name, NULL);
- if (IS_ERR(shm_mnt)) {
- error = PTR_ERR(shm_mnt);
- printk(KERN_ERR "Could not kern_mount tmpfs\n");
- goto out1;
- }
return 0;
-
-out1:
- unregister_filesystem(&tmpfs_fs_type);
out2:
destroy_inodecache();
out3:
bdi_destroy(&shmem_backing_dev_info);
out4:
- shm_mnt = ERR_PTR(error);
return error;
}
module_init(init_tmpfs)
+static struct vfsmount *shm_mnt;
+
+static int init_shm_mnt(void)
+{
+ shm_mnt = vfs_kern_mount(&tmpfs_fs_type, MS_NOUSER,
+ tmpfs_fs_type.name, NULL);
+ if (IS_ERR(shm_mnt)) {
+ printk(KERN_ERR "Could not kern_mount tmpfs\n");
+ return PTR_ERR(shm_mnt);
+ }
+ return 0;
+}
+
/*
* shmem_file_setup - get an unlinked file living in tmpfs
*
@@ -2575,9 +2577,11 @@ struct file *shmem_file_setup(char *name
struct inode *inode;
struct dentry *dentry, *root;
struct qstr this;
+ static DEFINE_ONCE(once);
- if (IS_ERR(shm_mnt))
- return (void *)shm_mnt;
+ error = call_once(&once, init_shm_mnt);
+ if (error)
+ return ERR_PTR(error);
if (size < 0 || size > SHMEM_MAX_BYTES)
return ERR_PTR(-EINVAL);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] tiny-shmem: use call_once()
2008-03-10 15:03 ` [PATCH 4/5] shmem: " Akinobu Mita
@ 2008-03-10 15:05 ` Akinobu Mita
2008-03-10 22:15 ` [PATCH 4/5] shmem: " Hugh Dickins
1 sibling, 0 replies; 6+ messages in thread
From: Akinobu Mita @ 2008-03-10 15:05 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm, linux-fsdevel
This patch defers mounting tmpfs till shmem_file_setup() is
called first time by using call_once().
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
mm/tiny-shmem.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
Index: 2.6-rc/mm/tiny-shmem.c
===================================================================
--- 2.6-rc.orig/mm/tiny-shmem.c
+++ 2.6-rc/mm/tiny-shmem.c
@@ -19,6 +19,7 @@
#include <linux/module.h>
#include <linux/swap.h>
#include <linux/ramfs.h>
+#include <linux/once.h>
static struct file_system_type tmpfs_fs_type = {
.name = "tmpfs",
@@ -26,19 +27,23 @@ static struct file_system_type tmpfs_fs_
.kill_sb = kill_litter_super,
};
-static struct vfsmount *shm_mnt;
-
static int __init init_tmpfs(void)
{
BUG_ON(register_filesystem(&tmpfs_fs_type) != 0);
- shm_mnt = kern_mount(&tmpfs_fs_type);
- BUG_ON(IS_ERR(shm_mnt));
-
return 0;
}
module_init(init_tmpfs)
+static struct vfsmount *shm_mnt;
+
+static int init_shm_mnt(void)
+{
+ shm_mnt = kern_mount(&tmpfs_fs_type);
+
+ return IS_ERR(shm_mnt) ? PTR_ERR(shm_mnt) : 0;
+}
+
/*
* shmem_file_setup - get an unlinked file living in tmpfs
*
@@ -53,9 +58,11 @@ struct file *shmem_file_setup(char *name
struct inode *inode;
struct dentry *dentry, *root;
struct qstr this;
+ static DEFINE_ONCE(once);
- if (IS_ERR(shm_mnt))
- return (void *)shm_mnt;
+ error = call_once(&once, init_shm_mnt);
+ if (error)
+ return ERR_PTR(error);
error = -ENOMEM;
this.name = name;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/5] shmem: use call_once()
2008-03-10 15:03 ` [PATCH 4/5] shmem: " Akinobu Mita
2008-03-10 15:05 ` [PATCH 5/5] tiny-shmem: " Akinobu Mita
@ 2008-03-10 22:15 ` Hugh Dickins
2008-03-11 12:29 ` Akinobu Mita
1 sibling, 1 reply; 6+ messages in thread
From: Hugh Dickins @ 2008-03-10 22:15 UTC (permalink / raw)
To: Akinobu Mita; +Cc: linux-kernel, akpm, linux-fsdevel
On Tue, 11 Mar 2008, Akinobu Mita wrote:
> This patch defers mounting tmpfs till shmem_file_setup() is
> called first time by using call_once().
Please explain why we might need this patch: is something changing
elsewhere? Or are you misled by that "module_init(init_tmpfs)"
into thinking that mm/shmem.c is sometimes built modular?
Hugh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/5] shmem: use call_once()
2008-03-10 22:15 ` [PATCH 4/5] shmem: " Hugh Dickins
@ 2008-03-11 12:29 ` Akinobu Mita
2008-03-11 13:41 ` Hugh Dickins
0 siblings, 1 reply; 6+ messages in thread
From: Akinobu Mita @ 2008-03-11 12:29 UTC (permalink / raw)
To: Hugh Dickins; +Cc: linux-kernel, akpm, linux-fsdevel
2008/3/11, Hugh Dickins <hugh@veritas.com>:
> On Tue, 11 Mar 2008, Akinobu Mita wrote:
> > This patch defers mounting tmpfs till shmem_file_setup() is
> > called first time by using call_once().
>
>
> Please explain why we might need this patch: is something changing
> elsewhere? Or are you misled by that "module_init(init_tmpfs)"
> into thinking that mm/shmem.c is sometimes built modular?
>
If no processes call shmem_file_setup() (via shm_get(2)), it is unnecessary
to do vfs_kern_mount(&tmpfs_fs_type, ...) unconditionary in boot-time.
So I thought it is suitable example to demonstrate how to use "call_once()"
in this patch set.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 4/5] shmem: use call_once()
2008-03-11 12:29 ` Akinobu Mita
@ 2008-03-11 13:41 ` Hugh Dickins
0 siblings, 0 replies; 6+ messages in thread
From: Hugh Dickins @ 2008-03-11 13:41 UTC (permalink / raw)
To: Akinobu Mita
Cc: linux-kernel, akpm, linux-fsdevel, William Irwin, Matt Mackall
On Tue, 11 Mar 2008, Akinobu Mita wrote:
> 2008/3/11, Hugh Dickins <hugh@veritas.com>:
> > On Tue, 11 Mar 2008, Akinobu Mita wrote:
> > > This patch defers mounting tmpfs till shmem_file_setup() is
> > > called first time by using call_once().
> >
> > Please explain why we might need this patch: is something changing
> > elsewhere? Or are you misled by that "module_init(init_tmpfs)"
> > into thinking that mm/shmem.c is sometimes built modular?
>
> If no processes call shmem_file_setup() (via shm_get(2)), it is unnecessary
or shmem_zero_setup, not very common
> to do vfs_kern_mount(&tmpfs_fs_type, ...) unconditionary in boot-time.
> So I thought it is suitable example to demonstrate how to use "call_once()"
> in this patch set.
Oh, I see, thanks. Well, I don't feel all that strongly about it; but
on the whole I'd prefer we leave it as part of the __init, than change
it around to provide this example (and risk introducing some weird issue
e.g. related to its "dev"?). I guess the same should go for the huge
and the tiny, whereas you have better justification in the idr case.
Call me over-cautious.
Hugh
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-03-11 20:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20080310145704.GA6396@APFDCB5C>
[not found] ` <20080310150026.GA6407@APFDCB5C>
2008-03-10 15:01 ` [PATCH 3/5] hugetlbfs: use call_once() Akinobu Mita
2008-03-10 15:03 ` [PATCH 4/5] shmem: " Akinobu Mita
2008-03-10 15:05 ` [PATCH 5/5] tiny-shmem: " Akinobu Mita
2008-03-10 22:15 ` [PATCH 4/5] shmem: " Hugh Dickins
2008-03-11 12:29 ` Akinobu Mita
2008-03-11 13:41 ` Hugh Dickins
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).