[merged] pidns-simpler-allocation-of-pid_-caches.patch removed from -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: pidns: simpler allocation of pid_* caches
has been removed from the -mm tree.  Its filename was
     pidns-simpler-allocation-of-pid_-caches.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Subject: pidns: simpler allocation of pid_* caches

Those pid_* caches are created on demand when a process advances to the
new level of pid namespace.  Which means pointers are stable, write only
and thus can be packed into an array instead of spreading them over and
using lists(!) to find them.

Both first and subsequent clone/unshare(CLONE_NEWPID) become faster.

Link: http://lkml.kernel.org/r/20180320185106.GA325@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
Cc: Pavel Emelyanov <xemul@xxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 kernel/pid_namespace.c |   65 +++++++++++++--------------------------
 1 file changed, 23 insertions(+), 42 deletions(-)

diff -puN kernel/pid_namespace.c~pidns-simpler-allocation-of-pid_-caches kernel/pid_namespace.c
--- a/kernel/pid_namespace.c~pidns-simpler-allocation-of-pid_-caches
+++ a/kernel/pid_namespace.c
@@ -23,55 +23,39 @@
 #include <linux/sched/signal.h>
 #include <linux/idr.h>
 
-struct pid_cache {
-	int nr_ids;
-	char name[16];
-	struct kmem_cache *cachep;
-	struct list_head list;
-};
-
-static LIST_HEAD(pid_caches_lh);
 static DEFINE_MUTEX(pid_caches_mutex);
 static struct kmem_cache *pid_ns_cachep;
+/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
+#define MAX_PID_NS_LEVEL 32
+/* Write once array, filled from the beginning. */
+static struct kmem_cache *pid_cache[MAX_PID_NS_LEVEL];
 
 /*
  * creates the kmem cache to allocate pids from.
- * @nr_ids: the number of numerical ids this pid will have to carry
+ * @level: pid namespace level
  */
 
-static struct kmem_cache *create_pid_cachep(int nr_ids)
+static struct kmem_cache *create_pid_cachep(unsigned int level)
 {
-	struct pid_cache *pcache;
-	struct kmem_cache *cachep;
+	/* Level 0 is init_pid_ns.pid_cachep */
+	struct kmem_cache **pkc = &pid_cache[level - 1];
+	struct kmem_cache *kc;
+	char name[4 + 10 + 1];
+	unsigned int len;
+
+	kc = READ_ONCE(*pkc);
+	if (kc)
+		return kc;
 
+	snprintf(name, sizeof(name), "pid_%u", level + 1);
+	len = sizeof(struct pid) + level * sizeof(struct upid);
 	mutex_lock(&pid_caches_mutex);
-	list_for_each_entry(pcache, &pid_caches_lh, list)
-		if (pcache->nr_ids == nr_ids)
-			goto out;
-
-	pcache = kmalloc(sizeof(struct pid_cache), GFP_KERNEL);
-	if (pcache == NULL)
-		goto err_alloc;
-
-	snprintf(pcache->name, sizeof(pcache->name), "pid_%d", nr_ids);
-	cachep = kmem_cache_create(pcache->name,
-			sizeof(struct pid) + (nr_ids - 1) * sizeof(struct upid),
-			0, SLAB_HWCACHE_ALIGN, NULL);
-	if (cachep == NULL)
-		goto err_cachep;
-
-	pcache->nr_ids = nr_ids;
-	pcache->cachep = cachep;
-	list_add(&pcache->list, &pid_caches_lh);
-out:
-	mutex_unlock(&pid_caches_mutex);
-	return pcache->cachep;
-
-err_cachep:
-	kfree(pcache);
-err_alloc:
+	/* Name collision forces to do allocation under mutex. */
+	if (!*pkc)
+		*pkc = kmem_cache_create(name, len, 0, SLAB_HWCACHE_ALIGN, 0);
 	mutex_unlock(&pid_caches_mutex);
-	return NULL;
+	/* current can fail, but someone else can succeed. */
+	return READ_ONCE(*pkc);
 }
 
 static void proc_cleanup_work(struct work_struct *work)
@@ -80,9 +64,6 @@ static void proc_cleanup_work(struct wor
 	pid_ns_release_proc(ns);
 }
 
-/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
-#define MAX_PID_NS_LEVEL 32
-
 static struct ucounts *inc_pid_namespaces(struct user_namespace *ns)
 {
 	return inc_ucount(ns, current_euid(), UCOUNT_PID_NAMESPACES);
@@ -119,7 +100,7 @@ static struct pid_namespace *create_pid_
 
 	idr_init(&ns->idr);
 
-	ns->pid_cachep = create_pid_cachep(level + 1);
+	ns->pid_cachep = create_pid_cachep(level);
 	if (ns->pid_cachep == NULL)
 		goto out_free_idr;
 
_

Patches currently in -mm which might be from adobriyan@xxxxxxxxx are

slab-mark-kmalloc-machinery-as-__ro_after_init.patch
slab-fixup-calculate_alignment-argument-type.patch
slab-make-kmalloc_index-return-unsigned-int.patch
slab-make-kmalloc_size-return-unsigned-int.patch
slab-make-create_kmalloc_cache-work-with-32-bit-sizes.patch
slab-make-create_boot_cache-work-with-32-bit-sizes.patch
slab-make-kmem_cache_create-work-with-32-bit-sizes.patch
slab-make-size_index-array-u8.patch
slab-make-size_index_elem-unsigned-int.patch
slub-make-remote_node_defrag_ratio-unsigned-int.patch
slub-make-max_attr_size-unsigned-int.patch
slub-make-red_left_pad-unsigned-int.patch
slub-make-reserved-unsigned-int.patch
slub-make-align-unsigned-int.patch
slub-make-inuse-unsigned-int.patch
slub-make-cpu_partial-unsigned-int.patch
slub-make-offset-unsigned-int.patch
slub-make-object_size-unsigned-int.patch
slub-make-size-unsigned-int.patch
slab-make-kmem_cache_flags-accept-32-bit-object-size.patch
kasan-make-kasan_cache_create-work-with-32-bit-slab-cache-sizes.patch
slab-make-usercopy-region-32-bit.patch
slub-make-slab_index-return-unsigned-int.patch
slub-make-struct-kmem_cache_order_objects-x-unsigned-int.patch
slub-make-size_from_object-return-unsigned-int.patch
slab-use-32-bit-arithmetic-in-freelist_randomize.patch
proc-do-less-stuff-under-pde_unload_lock.patch
proc-move-proc-sysvipc-creation-to-where-it-belongs.patch
proc-faster-open-close-of-files-without-release-hook.patch
proc-randomize-struct-pde_opener.patch
proc-move-struct-pde_opener-to-kmem-cache.patch
proc-account-struct-pde_opener.patch
proc-check-permissions-earlier-for-proc-wchan.patch
proc-use-set_puts-at-proc-wchan.patch
proc-test-proc-self-wchan.patch
proc-test-proc-self-syscall.patch
proc-move-struct-proc_dir_entry-into-kmem-cache.patch
proc-fix-proc-map_files-lookup-some-more.patch
proc-register-filesystem-last.patch
proc-faster-proc-cmdline.patch
proc-do-mmput-asap-for-proc-map_files.patch
proc-revalidate-misc-dentries.patch
proc-test-last-field-of-proc-loadavg.patch
proc-reject-and-as-filenames.patch
proc-switch-struct-proc_dir_entry-count-to-refcount.patch
proc-shotgun-test-read-readdir-readlink-a-little-write.patch
proc-shotgun-test-read-readdir-readlink-a-little-write-fix.patch
proc-shotgun-test-read-readdir-readlink-a-little-write-fix-2.patch
proc-use-slower-rb_first.patch
proc-test-proc-uptime.patch
uts-create-struct-uts_namespace-from-kmem_cache.patch
seq_file-allocate-seq_file-from-kmem_cache.patch
seq_file-account-everything.patch
seq_file-delete-small-value-optimization.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux