lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 5 Nov 2018 01:13:12 +0300
From:   Vasily Averin <vvs@...tuozzo.com>
To:     linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>
Cc:     Huang Ying <ying.huang@...el.com>, linux-kernel@...r.kernel.org,
        Aaron Lu <aaron.lu@...el.com>
Subject: [PATCH 2/2] mm: avoid unnecessary swap_info_struct allocation

Currently newly allocated swap_info_struct can be quickly freed.
This patch avoid uneccessary high-order page allocation and helps
to decrease the memory pressure.

Signed-off-by: Vasily Averin <vvs@...tuozzo.com>
---
 mm/swapfile.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 8688ae65ef58..53ec2f0cdf26 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2809,14 +2809,17 @@ late_initcall(max_swapfiles_check);
 
 static struct swap_info_struct *alloc_swap_info(void)
 {
-	struct swap_info_struct *p;
+	struct swap_info_struct *p = NULL;
 	unsigned int type;
 	int i;
+	bool force_alloc = false;
 
-	p = kvzalloc(sizeof(*p), GFP_KERNEL);
-	if (!p)
-		return ERR_PTR(-ENOMEM);
-
+retry:
+	if (force_alloc) {
+		p = kvzalloc(sizeof(*p), GFP_KERNEL);
+		if (!p)
+			return ERR_PTR(-ENOMEM);
+	}
 	spin_lock(&swap_lock);
 	for (type = 0; type < nr_swapfiles; type++) {
 		if (!(swap_info[type]->flags & SWP_USED))
@@ -2828,6 +2831,11 @@ static struct swap_info_struct *alloc_swap_info(void)
 		return ERR_PTR(-EPERM);
 	}
 	if (type >= nr_swapfiles) {
+		if (!force_alloc) {
+			force_alloc = true;
+			spin_unlock(&swap_lock);
+			goto retry;
+		}
 		p->type = type;
 		swap_info[type] = p;
 		/*
-- 
2.17.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ