From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C44C6C43387 for ; Tue, 8 Jan 2019 19:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8ECE82063F for ; Tue, 8 Jan 2019 19:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546976651; bh=np7J0OPCSAqbeNRfUOY15xqqT+mEf8WJchTq9Gb4nrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=auswOkbUephjNtLYaR65j5fMeALHSMuJiZnDE+G2VudIgb1nmb98Mz/lTVyU0OKIT /D0mLBYzXNsG5Bd68+F611kNdR52b7XWai8I7ertkUgxPxjANJZQBjv/CDrORKhvMh w9HoWNu5XFqIMHH/9l9QbKIm4izXYk6e2+C7yHGU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732638AbfAHToL (ORCPT ); Tue, 8 Jan 2019 14:44:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:42564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731124AbfAHTdq (ORCPT ); Tue, 8 Jan 2019 14:33:46 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 76538205C9; Tue, 8 Jan 2019 19:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546976025; bh=np7J0OPCSAqbeNRfUOY15xqqT+mEf8WJchTq9Gb4nrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZcqHfmG/hgfl+T2WnE5jO4ucATBJ6huTH/SnAUs2t1+5nwQb6qB5mI5W0IPNNzPRD nJgyTL8XoMQLEBn8ZbkDUzU1rjltyKU666/rEGtKCJPpZHUCD3bkv6FD5ZdLEVPidu kHCIpuL9AeHsY3bU+LofmNLZP7dMO85DGNFc1u8o= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Aaron Lu , Vasily Averin , Huang Ying , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.14 52/53] mm/swap: use nr_node_ids for avail_lists in swap_info_struct Date: Tue, 8 Jan 2019 14:32:20 -0500 Message-Id: <20190108193222.123316-52-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108193222.123316-1-sashal@kernel.org> References: <20190108193222.123316-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aaron Lu [ 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 08e8cd21770c..d687dc3c7050 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2829,8 +2829,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