Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2372505imu; Thu, 24 Jan 2019 11:35:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN7fe2xrH7GoY6GoKLY8M3Xvd217ceufu341VTMeGikf28Vf9/+nxLombFCUJmeTBqwcTlXH X-Received: by 2002:a17:902:b707:: with SMTP id d7mr7495595pls.29.1548358541903; Thu, 24 Jan 2019 11:35:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548358541; cv=none; d=google.com; s=arc-20160816; b=Gwykr1z10w74EKg3X5D5IsebdUEZWFpXiydx8mna2fVGWNf4h9r/mMFqcGdmpaSscL SovP2thJ3GiRTfJgkg/apwwWm+jmSjByYAgwD0ZQa0hV3Z3Cbwdt62POIdCYNwgwWhSp cFGghdYqpZbpu3m32ajtvu26WVRhSEImACwtSbayI290X0Pc2YJr/QwBPnM/VkTsaxhN goTJ1mNDO+gpz360nYa3lm+jbCh4bRvi0RAV9IFclT7JWNDZtFpdAGEIlLY/53glmFdV PZUC2nOA2XuKwU26CcDdi3X6oWT920860XxQ8DJpnMJlDzQufXqXO+gckiyf59TVR9IZ dWFg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M+pWXwJ+Z78nRL1Vd9Fdv7VVGsowZo1t/cT6b2vZHJ4=; b=tCpDSBj8cIJsIO3fP1FOIf3HFw00q30sqwsrmV/il3QLTiWe+lU3QrKnJfibvcLbdi f383Wsm0Z5gm0Jxi69xxyqSzpVqTadyTTcFJbgC5Iu1R7AGSjL5L1MII0MSrfPawTrtM vPsj+Q2tfOEpiqZYY1IJBRIBZaGSi4YcCh56PH2AxIX6Md9ocesgofF3+n9dFcUKnMqd xhEJ+0cDB8zjZxqk9s05razvBDrki6y9B0oFHdMNRSJoqf1/aE71R2GYHto1Qr1pGprM A/vuXnzu7V3gME4HcgMg8VEH9BS5Gy3sk4yfItNRWqLOCNla5dijpgdGikuOwXjCj1RS iTwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cOzkKrAi; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h14si22513397pgd.189.2019.01.24.11.35.26; Thu, 24 Jan 2019 11:35:41 -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; dkim=pass header.i=@kernel.org header.s=default header.b=cOzkKrAi; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729802AbfAXTdO (ORCPT + 99 others); Thu, 24 Jan 2019 14:33:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:32996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730946AbfAXTdM (ORCPT ); Thu, 24 Jan 2019 14:33:12 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EACEA218D4; Thu, 24 Jan 2019 19:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548358391; bh=IZd+rWVFhfmTDWUPhHtjUtuWgakP+kYh2HLd0bScYuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cOzkKrAiVhpYqALtFOfOPScOlKfaWpJVe7+CFGFx6KnqxFuSG/kbSPlb4sFFRSMpz AJVGasb8vPVg0I8n+OkYGgfVkkC6UZKb+u8/76esjtXfVZjmAQCt9RFdXA+l91TfGy 1QlRgNWft02fgLOXtX6YGbV6lKbe3NsptxK14iyI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaron Lu , Andrew Morton , Michal Hocko , Vasily Averin , Huang Ying , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 56/63] mm/swap: use nr_node_ids for avail_lists in swap_info_struct Date: Thu, 24 Jan 2019 20:20:45 +0100 Message-Id: <20190124190201.924268856@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190155.176570028@linuxfoundation.org> References: <20190124190155.176570028@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 66f71da9dd38af17dc17209cdde7987d4679a699 ] Since a2468cc9bfdf ("swap: choose swap device according to numa node"), avail_lists field of swap_info_struct is changed to an array with MAX_NUMNODES elements. This made swap_info_struct size increased to 40KiB and needs an order-4 page to hold it. This is not optimal in that: 1 Most systems have way less than MAX_NUMNODES(1024) nodes so it is a waste of memory; 2 It could cause swapon failure if the swap device is swapped on after system has been running for a while, due to no order-4 page is available as pointed out by Vasily Averin. Solve the above two issues by using nr_node_ids(which is the actual possible node number the running system has) for avail_lists instead of MAX_NUMNODES. nr_node_ids is unknown at compile time so can't be directly used when declaring this array. What I did here is to declare avail_lists as zero element array and allocate space for it when allocating space for swap_info_struct. The reason why keep using array but not pointer is plist_for_each_entry needs the field to be part of the struct, so pointer will not work. This patch is on top of Vasily Averin's fix commit. I think the use of kvzalloc for swap_info_struct is still needed in case nr_node_ids is really big on some systems. Link: http://lkml.kernel.org/r/20181115083847.GA11129@intel.com Signed-off-by: Aaron Lu Reviewed-by: Andrew Morton Acked-by: Michal Hocko Cc: Vasily Averin Cc: Huang Ying Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/swap.h | 11 ++++++++++- mm/swapfile.c | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index f02fb5db8914..4fd1ab9565ba 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -231,7 +231,6 @@ struct swap_info_struct { unsigned long flags; /* SWP_USED etc: see above */ signed short prio; /* swap priority of this type */ struct plist_node list; /* entry in swap_active_head */ - struct plist_node avail_lists[MAX_NUMNODES];/* entry in swap_avail_heads */ signed char type; /* strange name for an index */ unsigned int max; /* extent of the swap_map */ unsigned char *swap_map; /* vmalloc'ed array of usage counts */ @@ -272,6 +271,16 @@ struct swap_info_struct { */ struct work_struct discard_work; /* discard worker */ struct swap_cluster_list discard_clusters; /* discard clusters list */ + struct plist_node avail_lists[0]; /* + * entries in swap_avail_heads, one + * entry per node. + * Must be last as the number of the + * array is nr_node_ids, which is not + * a fixed value so have to allocate + * dynamically. + * And it has to be an array so that + * plist_for_each_* can work. + */ }; #ifdef CONFIG_64BIT diff --git a/mm/swapfile.c b/mm/swapfile.c index af3c4c5a0b4e..4f9e522643a2 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2830,8 +2830,9 @@ static struct swap_info_struct *alloc_swap_info(void) struct swap_info_struct *p; unsigned int type; int i; + int size = sizeof(*p) + nr_node_ids * sizeof(struct plist_node); - p = kvzalloc(sizeof(*p), GFP_KERNEL); + p = kvzalloc(size, GFP_KERNEL); if (!p) return ERR_PTR(-ENOMEM); -- 2.19.1