From patchwork Sun Nov 4 22:13:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 10667169 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 1042D13B5 for ; Sun, 4 Nov 2018 22:13:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1C84295F0 for ; Sun, 4 Nov 2018 22:13:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E327429610; Sun, 4 Nov 2018 22:13:17 +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 E8099295F0 for ; Sun, 4 Nov 2018 22:13:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59C3B6B0005; Sun, 4 Nov 2018 17:13:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 524716B0006; Sun, 4 Nov 2018 17:13:15 -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 39FB86B0007; Sun, 4 Nov 2018 17:13:15 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by kanga.kvack.org (Postfix) with ESMTP id C2CA86B0005 for ; Sun, 4 Nov 2018 17:13:14 -0500 (EST) Received: by mail-lj1-f200.google.com with SMTP id h12-v6so2008807ljb.12 for ; Sun, 04 Nov 2018 14:13:14 -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=3+9nOJfv1Giy/GsTEbrqN61DZ7j3uZOtL7gHu+ElGdU=; b=bU55RMXwudyxiJNcWdiC4B99Mzb7GTIK3TRxKfxNG7+UvV8jOK81dpor6T6Qmj5VM7 tj3IFo08xETdSqbB8Bd+2jsmn0TH4PR8y7r8WL4AFsVYaiMEfAxQn9JKWhROgocDb11g lJ/MAKgCgZmJs4KZamrPS6bttupouoW2+pr1IfK5VuHU0yOa1KSEIR4LTdGzXBIkIeU7 IPCjuptzzpnZ0oqn7eT2akZOl6oG+19pAF6q9kOi61lTwGBAg3IhWVLtMponEhJReRF1 aW7sgRA35rdxtxxjwcgSqzWxVrlX+5IXJEOFSjz4J2HYQ9O6AXJr3RrlUThNVbc4JkM5 AXaw== 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: AGRZ1gL+gMBc2SElRQPZOIb84o1JwYj1MsW1tT89eVqbRIxnE+/A/nLI xwxmO1raDcwlh/Ohdq9SdZenDGxntGv5zorbV2aPtulMVSoQa7ur8vRBu3sbMOyAIsTfr7wJOnL dHse+O0VzNApy/PZsZwrMA5g9mF4aTLMGDApBcEKljsIny9XhNyFPGEnuQP2grg1IMg== X-Received: by 2002:a2e:2b99:: with SMTP id r25-v6mr12425235ljr.91.1541369593994; Sun, 04 Nov 2018 14:13:13 -0800 (PST) X-Google-Smtp-Source: AJdET5fQ+Cjkqz3MpjzoPG1hb5Lvjfuy2SEBHCgfLPY2zr237A49UDyb7PAvVV42OrQGQE155l6T X-Received: by 2002:a2e:2b99:: with SMTP id r25-v6mr12425215ljr.91.1541369593027; Sun, 04 Nov 2018 14:13:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541369593; cv=none; d=google.com; s=arc-20160816; b=rV8E67W3Hc8HFThLk07ZgOGDl8XBaFqlanVHlVlxEHdrAG6ZBUXTDmYAc1aj1iFu2x HnFQuBV8CATAPH4YgOBqqU/03mJroDMsHOKkAI0IXf+kvvqRY5xViJVQMmzB8ViLurD2 Rc6mKq4Jfp+cmsSo57WTYs51T5w8ydo6ueSy3rkYjgD1CBlA1LPaAuyJx3gFSm7M8OzR MkgzOfBYukBNDfDaIoYqeJ0keTossjgpxiRQvO7FSq5qLleHTf/OJXs3CMlu7xlyxh4N FhM5uQsWcRj7qLArWbKtsh4BdRnNeSgxpShpT7panpIGUFgAJPIqZOI+4isgCtNb/BRQ Yy+A== 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=3+9nOJfv1Giy/GsTEbrqN61DZ7j3uZOtL7gHu+ElGdU=; b=kBhn2DFIr/0EOuMdFzZe5IaSbdjAoU5WKVX8HasD/hDd/+JQ4oJwusNfTmiF4Gq6gv AVMayd925mruaHbxfJ2AohX+P+VL0W/qp3MZmtt4RXJXwpQf2qf2zpF9p8PvSABZVB9H 78Mn+jbHO6Fv7RK6GbowVfS7Cnlue5bQFp0p4IfsQ3YyeQA7ts7tU20rCeKtn5SZbNDN Fqx0Y0K4bTZOd3Zpv8EnjR2zOm6ObeiF/3VM9cLsdCmJVuV99eQFN4xY1+HAa+HzAUbn STFo0CgPl8QkTZBjSXlahvG9WfZwKkFAen1iGx2r3iSCtlqd0cRu0TnNbLDU+f3r7Usj jPoQ== 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 l10-v6si8931043ljj.86.2018.11.04.14.13.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 14:13:12 -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 1gJQdl-00063N-Gh; Mon, 05 Nov 2018 01:13:05 +0300 From: Vasily Averin Subject: [PATCH 1/2] mm: use kvzalloc for swap_info_struct allocation To: linux-mm@kvack.org, Andrew Morton Cc: Huang Ying , linux-kernel@vger.kernel.org, Aaron Lu Message-ID: <37b60523-d085-71e9-fef9-80b90bfcef18@virtuozzo.com> Date: Mon, 5 Nov 2018 01:13:04 +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 commit a2468cc9bfdf ("swap: choose swap device according to numa node") increased size of swap_info_struct up to 44 Kbytes, now it requires 4th order page. Switch to kvzmalloc allows to avoid unexpected allocation failures. Signed-off-by: Vasily Averin Acked-by: Aaron Lu --- mm/swapfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 644f746e167a..8688ae65ef58 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2813,7 +2813,7 @@ static struct swap_info_struct *alloc_swap_info(void) unsigned int type; int i; - p = kzalloc(sizeof(*p), GFP_KERNEL); + p = kvzalloc(sizeof(*p), GFP_KERNEL); if (!p) return ERR_PTR(-ENOMEM); @@ -2824,7 +2824,7 @@ static struct swap_info_struct *alloc_swap_info(void) } if (type >= MAX_SWAPFILES) { spin_unlock(&swap_lock); - kfree(p); + kvfree(p); return ERR_PTR(-EPERM); } if (type >= nr_swapfiles) { @@ -2838,7 +2838,7 @@ static struct swap_info_struct *alloc_swap_info(void) smp_wmb(); nr_swapfiles++; } else { - kfree(p); + kvfree(p); p = swap_info[type]; /* * Do not memset this entry: a racing procfs swap_next() 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; /*