All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm] proc: faster open/close of files without ->release hook
@ 2018-02-14  6:30 Alexey Dobriyan
  2018-02-14  8:19 ` [PATCH -mm 1/3] proc: randomize "struct pde_opener" Alexey Dobriyan
  0 siblings, 1 reply; 11+ messages in thread
From: Alexey Dobriyan @ 2018-02-14  6:30 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

The whole point of code in fs/proc/inode.c is to make sure ->release
hook is called either at close() or at rmmod time.

All if it is unnecessary if there is no ->release hook.

Save allocation+list manipulations under spinlock in that case.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/proc/inode.c |   41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -342,31 +342,36 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 	 *
 	 * Save every "struct file" with custom ->release hook.
 	 */
-	pdeo = kmalloc(sizeof(struct pde_opener), GFP_KERNEL);
-	if (!pdeo)
-		return -ENOMEM;
-
-	if (!use_pde(pde)) {
-		kfree(pdeo);
+	if (!use_pde(pde))
 		return -ENOENT;
-	}
-	open = pde->proc_fops->open;
+
 	release = pde->proc_fops->release;
+	if (release) {
+		pdeo = kmalloc(sizeof(struct pde_opener), GFP_KERNEL);
+		if (!pdeo) {
+			rv = -ENOMEM;
+			goto out_unuse;
+		}
+	}
 
+	open = pde->proc_fops->open;
 	if (open)
 		rv = open(inode, file);
 
-	if (rv == 0 && release) {
-		/* To know what to release. */
-		pdeo->file = file;
-		pdeo->closing = false;
-		pdeo->c = NULL;
-		spin_lock(&pde->pde_unload_lock);
-		list_add(&pdeo->lh, &pde->pde_openers);
-		spin_unlock(&pde->pde_unload_lock);
-	} else
-		kfree(pdeo);
+	if (release) {
+		if (rv == 0) {
+			/* To know what to release. */
+			pdeo->file = file;
+			pdeo->closing = false;
+			pdeo->c = NULL;
+			spin_lock(&pde->pde_unload_lock);
+			list_add(&pdeo->lh, &pde->pde_openers);
+			spin_unlock(&pde->pde_unload_lock);
+		} else
+			kfree(pdeo);
+	}
 
+out_unuse:
 	unuse_pde(pde);
 	return rv;
 }

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-02-16  4:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14  6:30 [PATCH -mm] proc: faster open/close of files without ->release hook Alexey Dobriyan
2018-02-14  8:19 ` [PATCH -mm 1/3] proc: randomize "struct pde_opener" Alexey Dobriyan
2018-02-14  8:23   ` [PATCH -mm 2/3] proc: move "struct pde_opener" to kmem cache Alexey Dobriyan
2018-02-14  8:24     ` [PATCH -mm 3/3] proc: account "struct pde_opener" Alexey Dobriyan
2018-02-15 19:07   ` [PATCH -mm 1/3] proc: randomize " Al Viro
2018-02-15 21:41     ` Alexey Dobriyan
2018-02-16  0:13       ` Al Viro
2018-02-16  1:03         ` Kees Cook
2018-02-16  4:48         ` Alexey Dobriyan
2018-02-16  0:53   ` Kees Cook
2018-02-16  4:41     ` Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.