Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2086491imd; Sun, 4 Nov 2018 16:53:58 -0800 (PST) X-Google-Smtp-Source: AJdET5cAFOUYoe9quZlyb1hUlzsGBidF4/p7WUyDBokK661yK52ZH8BsufpjmSxQH9wHA6k4Zdd5 X-Received: by 2002:a63:1157:: with SMTP id 23mr18517495pgr.245.1541379238660; Sun, 04 Nov 2018 16:53:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541379238; cv=none; d=google.com; s=arc-20160816; b=Xb4XRqF/W+KvLXdvQivbSc3bcVYKh+KMJ+92Hu1Jo9wOGD45bI8n9TVhYYYnOsxaYP yGeS+ZF9+WVL1cowZ7is3Lnyx+dBkaBrYvV4AQmwlCoTynaCPztWcnkMKF5n+zP98uBn audQnop57THGOgb65VsZOtMtFPB4Fx8TO3suYwou24TUqGG7iRuLcJroaVGE/nvIOlCl 3g16lhxCsuj415y2bWtLYD8kaOKmeBn96G9fKToAItK98LZjGn4h0njZeCwNqY48/PS+ tNbV2f1LXaXTzo5wO82NqRg1UfJ2WZg55Yz3L4v9yKUEbDJZVJMhBOs+R7i6TbFBkZJj 0jqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:cc:to :subject:from; bh=q+9ep44CKuI0mlAF/KB+h3waFc71oVyx67MHnSwWHxg=; b=ELcW20jqy089NOLo3aCX5PpQO9Ix/J/fMVx8VtLdA8uIgU1C0slPTbbfVunRJoHPe8 ZJIBqcue5RCxLaaI9uDU28ggc+PUUi/aVqFIIF24ZdJ445lVtchVwUCbqEy3rnpgB9zg YJG9uNk2j/1icDRc/TzsR2Kdeyiu9QazNUXEHZSedUJBIoTFJccJTViwmGPP6sWIv4jo oJpu5sygRw84s/i7iNdjlptwj4xy+VNZtI+XJyjBk456uykBpdnnN8YbBZ3mbHkAtFWV r1hpQOJVWw7HMr2Kf+LRzM5cuVetbOoJ5QQkNG2FW7qdKI8BPv0sdCpj0YcHYMuBsJz7 8etA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2-v6si1948866pfa.150.2018.11.04.16.53.44; Sun, 04 Nov 2018 16:53:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730217AbeKEH3m (ORCPT + 99 others); Mon, 5 Nov 2018 02:29:42 -0500 Received: from relay.sw.ru ([185.231.240.75]:54608 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729223AbeKEH3m (ORCPT ); Mon, 5 Nov 2018 02:29:42 -0500 Received: from [172.16.24.21] by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gJQds-00063T-EZ; Mon, 05 Nov 2018 01:13:12 +0300 From: Vasily Averin Subject: [PATCH 2/2] mm: avoid unnecessary swap_info_struct allocation To: linux-mm@kvack.org, Andrew Morton Cc: Huang Ying , linux-kernel@vger.kernel.org, Aaron Lu Message-ID: Date: Mon, 5 Nov 2018 01:13:12 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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