[RFC,4/5] files: Add fdtable_align() helper

Submitted by Kirill Tkhai on Jan. 12, 2018, 3:46 p.m.

Details

Message ID 151577200090.11063.6552343623503258413.stgit@localhost.localdomain
State New
Series "Shrink big fdtable on criu restore"
Headers show

Commit Message

Kirill Tkhai Jan. 12, 2018, 3:46 p.m.
Move alignment functionality from expand_fdtable()
to separate function. This will be used in next patch.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 fs/file.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/file.c b/fs/file.c
index 9743283200e0..f009eb9bf1c8 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -84,11 +84,8 @@  static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt, bool shrink
 	memset((char *)(nfdt->close_on_exec) + cpy, 0, set);
 }
 
-static struct fdtable * alloc_fdtable(unsigned int nr)
+static unsigned int fdtable_align(unsigned int nr)
 {
-	struct fdtable *fdt;
-	void *data;
-
 	/*
 	 * Figure out how many fds we actually want to support in this fdtable.
 	 * Allocation steps are keyed to the size of the fdarray, since it
@@ -110,6 +107,16 @@  static struct fdtable * alloc_fdtable(unsigned int nr)
 	if (unlikely(nr > sysctl_nr_open))
 		nr = ((sysctl_nr_open - 1) | (BITS_PER_LONG - 1)) + 1;
 
+	return nr;
+}
+
+static struct fdtable * alloc_fdtable(unsigned int nr)
+{
+	struct fdtable *fdt;
+	void *data;
+
+	nr = fdtable_align(nr);
+
 	fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL_ACCOUNT);
 	if (!fdt)
 		goto out;