Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7755049imu; Thu, 15 Nov 2018 00:40:05 -0800 (PST) X-Google-Smtp-Source: AJdET5fVOdWU72+co/8NOGyAlWrV/fXWVXVPiisvKqFMdE6iP/IGVKBuK5vDPku+efSZXK7COBPV X-Received: by 2002:a62:5bc7:: with SMTP id p190-v6mr5488994pfb.175.1542271205663; Thu, 15 Nov 2018 00:40:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542271205; cv=none; d=google.com; s=arc-20160816; b=NShaYR67EY4qv7kDY/CkAreB45zfGeABjqNOSuQQ35GmN3HH8SFFk8B39FAnzBqq1z c/YklU2DWG3RBr9CbyLnRZqkcA3H6LKCSZKAmBtFveKBacCLMdGz/oUe1vRvD0EeKq7G ILb9KmIMuKnA7HPQmjfXxa4WIFQHx1viVOQvG+5M7iff23bM8y0ar5WyfxYzJiNz49l/ j8R8ETo3JDzizVeXza7JpmadHYgR7O4ttQcxTv/jAACg1/jD00zoltISKayfCvN8DiuE pJH+IaHfLdLoo0L3pka3PeFzipCJNrN0Ht9MD/KYg2H7BSA7nI2X+vVQkKNJ96z0EPXy 18Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=4xRgo/74zHKKJhwxH+fQ/nFVPcnPmtJYXx/AFCrcwSs=; b=YyH7AtmNdA4V8NPRj1DDoeR6QFc6YZXPfEEQ/7oxFIfWHGTjORMDgNLkWkTaIXrENX pH/Z9ekuktAC5otu6Fbr0pURcbA2FnqczgHOX7IkHRMYCW6p+utPlTedzFaC8crZ6P+x tT+scpR7mCfHeo7tT1JrU9pwbkpo2C7Ng4BHMNV0HGD2+UGBvZb2QAM/25/1HiQ4KFJD P4VZnIOX/f4uUmecpM4bf1De5jR2waPUgjkc6W3ECYXJl6PlA18zzigg0UPaoSlcM8YH 5s2hGmPSkm0CJu7TEfMKMVzNIZUsgLA34nl4l9DgsIfg3DnLe77ZvzOG/wtZo3JGH0fQ 5mYQ== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f22si16525039pgm.81.2018.11.15.00.39.50; Thu, 15 Nov 2018 00:40:05 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729014AbeKOSpl (ORCPT + 99 others); Thu, 15 Nov 2018 13:45:41 -0500 Received: from mga17.intel.com ([192.55.52.151]:47159 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728527AbeKOSpk (ORCPT ); Thu, 15 Nov 2018 13:45:40 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2018 00:38:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,235,1539673200"; d="scan'208";a="104573356" Received: from aaronlu.sh.intel.com (HELO intel.com) ([10.239.159.44]) by fmsmga002.fm.intel.com with ESMTP; 15 Nov 2018 00:38:47 -0800 Date: Thu, 15 Nov 2018 16:38:47 +0800 From: Aaron Lu To: linux-mm , lkml Cc: Vasily Averin , Michal Hocko , Huang Ying , Andrew Morton Subject: [PATCH] mm/swap: use nr_node_ids for avail_lists in swap_info_struct Message-ID: <20181115083847.GA11129@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit 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. Cc: Vasily Averin Cc: Michal Hocko Cc: Huang Ying Signed-off-by: Aaron Lu --- 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 d8a07a4f171d..3d3630b3f63d 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -233,7 +233,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 */ @@ -274,6 +273,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 8688ae65ef58..6e06821623f6 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2812,8 +2812,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.17.2