From patchwork Sun Nov 4 22:13:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 10667171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BABB13B5 for ; Sun, 4 Nov 2018 22:13:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68E39295F0 for ; Sun, 4 Nov 2018 22:13:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59ABB29610; Sun, 4 Nov 2018 22:13:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SUBJ_OBFU_PUNCT_FEW autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3000295F0 for ; Sun, 4 Nov 2018 22:13:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D16D26B0006; Sun, 4 Nov 2018 17:13:17 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C9EA66B0007; Sun, 4 Nov 2018 17:13:17 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B40616B000A; Sun, 4 Nov 2018 17:13:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by kanga.kvack.org (Postfix) with ESMTP id 3B3006B0007 for ; Sun, 4 Nov 2018 17:13:17 -0500 (EST) Received: by mail-lf1-f72.google.com with SMTP id p19so895273lfg.5 for ; Sun, 04 Nov 2018 14:13:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:subject :to:cc:message-id:date:user-agent:mime-version:content-language :content-transfer-encoding; bh=q+9ep44CKuI0mlAF/KB+h3waFc71oVyx67MHnSwWHxg=; b=MhDuOVmgnqytk7t7qiRX9pxQCm/ohB4feaufTYDZOfPacfbkF/G/WnqhSZ1N+nEeM/ 7Y0vxpEmOnEfFjQ11upjaVlkM43QxdmWx0o3Ex76k1j/zN+JrDMHECagCLELai+rYk75 K50RLN6hXFkRaYg91Lac6Y0PDW1gQZTgDxG5ws6LUdDyNZqPRRET9ugyzj4ldpdpyFq/ zIrUpfN8R1qiqjWTXFxAn3m6cZFL6kwOMy2LMkkxgwm9m4Lr9xRB024cIB+5DJ4Ws0n5 iPCjfOfHYOS6FQ/5j/C5qu+1BLQYVFCq10BSjS2cGVt5mC/H39ZnmpAnhQRBfwtMdKiW 7t/A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vvs@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=vvs@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com X-Gm-Message-State: AGRZ1gIVBSob8iOfNpHKJs1O4dbbpfdAoSEDGTnndziQgNeXqKN7JDQo 4O+YdyQQzXU+567XgHh5bdS4ROgYYVW6v/1vhjC3X80LGhMOoUFmgxLVrECvFJPMz+mQhogQKQw ZPEbDNqKa6MkbZKCJvCcjV0ldXOGA+vJDNAPC2hB+vJDcG/DRXo51JDBz4xmrl2dGAQ== X-Received: by 2002:a2e:744:: with SMTP id i4-v6mr13606064ljd.36.1541369596658; Sun, 04 Nov 2018 14:13:16 -0800 (PST) X-Google-Smtp-Source: AJdET5cCSBXF+EdyHF4Vsds/3wx+UmX81pfGRWvGaNPBp7Ox1GPyHKkGyV/0hTxO1VzzMP8kvgOv X-Received: by 2002:a2e:744:: with SMTP id i4-v6mr13606041ljd.36.1541369595665; Sun, 04 Nov 2018 14:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541369595; cv=none; d=google.com; s=arc-20160816; b=IATky12VwZ3VFd2xGOleVkr+5fH+PDPTPjP5OUnf/560HnmtIxZQvDT3SBqBHSb1Y3 eNLc3Zh9Wrz5Ks35vnJ+9g/gSBwBgzvKXgioTVVm6brYYtkZolbpKuqtGGWw6NJdeiWO En8K79vq0vH9pjYn3t/tvS30ySQ6ij7uHdbUJTuOWDR3rCzKTV/yX7G+kWUyZfr8Ko2o jpQTWs++TtayOSLEn1LGMbCarFGkm90Rpy9bpIoYbCZkkxQQw3fOQULr5qDBBo830h3l G2sSKpmA5CIlwYIQZybGF/jwgC9VsqqL1n2WL/lbE5jqwu90YwoDzsUn3P71670qXL0Q wgmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version:user-agent :date:message-id:cc:to:subject:from; bh=q+9ep44CKuI0mlAF/KB+h3waFc71oVyx67MHnSwWHxg=; b=xWFMlwLCYp+i2uHyStNV2IdAPWlrFZO1hJ8Ovd15qz1IvoZ7H5Jar32crBEOpLmaRL 4bOF6ushws74dQAhkiqs57AhXToyC4bjpVNP0TWLkuL6EQ2vWeuWcz8hfHJHKGaKlUHr fdDqU8AQ5CT1sKgpQV6UogPlRQFKISW+/s5jQ8P64BeMgO2mh7Lugi/gZRSVz2q4POOm Ee5Wh4/g14sdmQB43d35Ei/xyx+T0v/ASFvihWbAaFtAXlMSHLD9NEMYLXqvPtQhs9OQ JVGMTNjSplV53DOMLeDT4WCIzaIgsX2liDep84sBmfzOcxseAuXW9K2qfV7QsyC4kTSi pEow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vvs@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=vvs@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: from relay.sw.ru (relay.sw.ru. [185.231.240.75]) by mx.google.com with ESMTPS id q22si30629394lfj.86.2018.11.04.14.13.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 14:13:15 -0800 (PST) Received-SPF: pass (google.com: domain of vvs@virtuozzo.com designates 185.231.240.75 as permitted sender) client-ip=185.231.240.75; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vvs@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=vvs@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com 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-Language: en-US X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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; /*