ipc/sem.c: sem optimise undo list search
[safe/jmp/linux-2.6] / ipc / shm.c
index 30162a5..e9b039f 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -55,7 +55,7 @@ struct shm_file_data {
 #define shm_file_data(file) (*((struct shm_file_data **)&(file)->private_data))
 
 static const struct file_operations shm_file_operations;
-static struct vm_operations_struct shm_vm_ops;
+static const struct vm_operations_struct shm_vm_ops;
 
 #define shm_ids(ns)    ((ns)->ids[IPC_SHM_IDS])
 
@@ -101,6 +101,7 @@ static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
 void shm_exit_ns(struct ipc_namespace *ns)
 {
        free_ipcs(ns, &shm_ids(ns), do_shm_rmid);
+       idr_destroy(&ns->ids[IPC_SHM_IDS].ipcs_idr);
 }
 #endif
 
@@ -290,29 +291,29 @@ static unsigned long shm_get_unmapped_area(struct file *file,
        unsigned long flags)
 {
        struct shm_file_data *sfd = shm_file_data(file);
-       return get_unmapped_area(sfd->file, addr, len, pgoff, flags);
-}
-
-int is_file_shm_hugepages(struct file *file)
-{
-       int ret = 0;
-
-       if (file->f_op == &shm_file_operations) {
-               struct shm_file_data *sfd;
-               sfd = shm_file_data(file);
-               ret = is_file_hugepages(sfd->file);
-       }
-       return ret;
+       return sfd->file->f_op->get_unmapped_area(sfd->file, addr, len,
+                                               pgoff, flags);
 }
 
 static const struct file_operations shm_file_operations = {
        .mmap           = shm_mmap,
        .fsync          = shm_fsync,
        .release        = shm_release,
+};
+
+static const struct file_operations shm_file_operations_huge = {
+       .mmap           = shm_mmap,
+       .fsync          = shm_fsync,
+       .release        = shm_release,
        .get_unmapped_area      = shm_get_unmapped_area,
 };
 
-static struct vm_operations_struct shm_vm_ops = {
+int is_file_shm_hugepages(struct file *file)
+{
+       return file->f_op == &shm_file_operations_huge;
+}
+
+static const struct vm_operations_struct shm_vm_ops = {
        .open   = shm_open,     /* callback for a new vm-area open */
        .close  = shm_close,    /* callback for when the vm-area is released */
        .fault  = shm_fault,
@@ -370,7 +371,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
                if (shmflg & SHM_NORESERVE)
                        acctflag = VM_NORESERVE;
                file = hugetlb_file_setup(name, size, acctflag,
-                                                       &shp->mlock_user);
+                                       &shp->mlock_user, HUGETLB_SHMFS_INODE);
        } else {
                /*
                 * Do not allow no accounting for OVERCOMMIT_NEVER, even
@@ -889,7 +890,10 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
        if (!sfd)
                goto out_put_dentry;
 
-       file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations);
+       file = alloc_file(path.mnt, path.dentry, f_mode,
+                       is_file_hugepages(shp->shm_file) ?
+                               &shm_file_operations_huge :
+                               &shm_file_operations);
        if (!file)
                goto out_free;
        ima_counts_get(file);