Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp150899imu; Sun, 4 Nov 2018 21:20:09 -0800 (PST) X-Google-Smtp-Source: AJdET5fl0+7r3Pi+aZmgSh/1KBH0Do0uWW66Dsky3k0f+KfJq5XEKTBW6DGCZFypeZYz6/92bioP X-Received: by 2002:a17:902:e81:: with SMTP id 1-v6mr20707457plx.48.1541395209020; Sun, 04 Nov 2018 21:20:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541395208; cv=none; d=google.com; s=arc-20160816; b=ll+9/dNP2ATieCVfuBWKJEmF/vYJ1RSl3Xbu9tfRHJxUNNbI7JLQ8JHef5JWJdZdyD RsSOL90XmerSx3rLTaVqL8hG56k1/FipUYWWW/xM4U/utr/fHpGbKSdWiSyhS/6np1n/ 1obFGo0tya8NvobNgqf219jRdMqslhgGH7TVmvNxcXLr18FXtNIwFYXJgHne8sW+nArm TcdJEjC0hS5ZddB/RQR0nZfE95nYU9+Uo26Xkh4DsYrrOy+aB6V5KxVKLUnRt0bAI2XJ R6P9gA5i/Sc4f1bRllp6pkbtbNtj0lD/xGOX3OEDGd2EijLzaF3oVcuC5Dj4RGqm3qLz U4Lw== 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:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Av+LVfhdeuJ0xp09nkfoU6JAdsBqe+BqJTVFL0LJD6w=; b=GvMSZf8TrGFh01y43nt/D6Sd2tV2KvCN+2QEQZ7RX124yeK/T+8VkRX++w9t7FotBt y67kwIajaRgIBP4L1hj5MEveZ7SnHzPFZJU1raRPlDN0lmk5dELLjnVPVjVWysIKCXfs qRe+6tFxc4Pq96c1uYx5oIUj87LCJgsXqiXF714YmY/L+tFjedkR/F+amNRGjNiohO6l ARr5SZwcgKJsFxvmtRAFk7jofjLD7IHcnGdHBkJjNP5ux8QQDJwaoeYdB83Tg4T2vWgR UbJOHxCEPe7WQr1bEHuwOvEKvw9p4OOBy9k3S+jJl0fErpypv+WrGyn8mcA+zIBuDT4h ONRA== 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 f62-v6si42908734plf.288.2018.11.04.21.19.53; Sun, 04 Nov 2018 21:20:08 -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 S1729078AbeKEOhX (ORCPT + 99 others); Mon, 5 Nov 2018 09:37:23 -0500 Received: from relay.sw.ru ([185.231.240.75]:38012 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728918AbeKEOhX (ORCPT ); Mon, 5 Nov 2018 09:37:23 -0500 Received: from [172.16.24.21] by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gJXIO-0006hy-6C; Mon, 05 Nov 2018 08:19:28 +0300 Subject: Re: [PATCH 2/2] mm: avoid unnecessary swap_info_struct allocation To: "Huang, Ying" Cc: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, Aaron Lu References: <87sh0gbau6.fsf@yhuang-dev.intel.com> From: Vasily Averin Message-ID: Date: Mon, 5 Nov 2018 08:19:27 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <87sh0gbau6.fsf@yhuang-dev.intel.com> 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 On 11/5/18 3:57 AM, Huang, Ying wrote: > Vasily Averin writes: > >> 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. > > I think swapon/swapoff are rare operations, so it will not increase the > memory pressure much. You are right, typically it should not affect usual nodes. It's OpenVz-specific usecase. OpenVz allows hosters to run hundreds of non-trusted containers per node. Our containers have enabled "virtual swap" functionality, and container's owners can call sys_swapon without any limits. Containers can be restarted in any time and we would like to decrease number of unnecessary high-order memory allocations. >> 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; >> /* >