Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp40664imu; Tue, 8 Jan 2019 14:15:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN4dcFL81ywkVXhPZSs9obKSANc1v2+9B0+32AQhCAEeSdxjF6OD6eJUepAAeWHszoq6+WvC X-Received: by 2002:a17:902:c804:: with SMTP id u4mr1850121plx.172.1546985727341; Tue, 08 Jan 2019 14:15:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546985727; cv=none; d=google.com; s=arc-20160816; b=DPrvro2p95pmUie80tIqnGEq6lhRTlSuOja+rGOQUx3ysTBwj1GVCKK+0Qo2eB1262 x4BDJBoYiOkU170c68/d1I5lRLdrlcjZwKwp6R7YS+UwicCQXcMqnTtqnmMNBcceQUaq 4+VVl+EfPvsFeX5NRWm1uB9mboOR5xtn1/a+MmdlPedNZtR8dQRJIA6OuccoXELMlYnx HZBQ/M3q0la0etOrrK2aBpVO2aJqkU9ntP162I1hLZhXrnxA+Gfk3mrTvgldgRhXz5gE cEkVMfJ2KauTLFp79swkdDX4AHTWIoV8gIzeHYbi24w8KPdOZ0I+Kmxr/vS/Xxkq/Mo8 kUYQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B7OIVJsSOOS/yQ7M6k/k7Qb3moNypXKHgkRHbiYazN4=; b=GNBe3PNo4PQ6JVKJ0LiCoaTRiUGGOLKvySkGiiqFEbmanKSgFM55ICdioVSWS4quPw LaGfFnXfmNTI5FBU7okQt/xoB+V2RZUOV/XvnzhM2lztvrImyEugKK4lX40zD9eMtnNP JEeebvtoEAdfo5tjWenh85Q4YwN+CLjUFqEmqS+1M2xo9nRFgQeMe9gv4v1RDoPeLj9q jqb5zpZJ+0IygKxyNVCmoJdLn4o1vW3rlqt1FzoswTMDKtLZXpNt7vdVsNq8Cn3GqNk5 BMCvMCeM1iXYe7ZK4ypPHE7ENib6IpxRilHWFWsyN5vLhyEm5m3JSvqRfYgd59/j7cAF ViWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lyRsITDR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 82si28122929pfa.115.2019.01.08.14.15.12; Tue, 08 Jan 2019 14:15:27 -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=lyRsITDR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730477AbfAHT3q (ORCPT + 99 others); Tue, 8 Jan 2019 14:29:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:37094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728913AbfAHT3i (ORCPT ); Tue, 8 Jan 2019 14:29:38 -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 5100A2070B; Tue, 8 Jan 2019 19:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975777; bh=xxfrKVFK4+INIlF6rCwPWKplFrmYURb2A5IovYoXsqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lyRsITDRV7/43VhEThZ1mtfMF2JHgZW0E+I/40WUEFTQ2F+UQ9J/EEJXkqNE3zNyt Ddo9UnDMbrcHxlXNrUPK8eEC2U1GwGBPxccRFkC8pq/77UVf3vUtKU6nNBs9zRfINm ceMf4Yo5SZdL/8z9FVuuzQafwcg25TBUShP7iKh4= 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.20 114/117] mm/swap: use nr_node_ids for avail_lists in swap_info_struct Date: Tue, 8 Jan 2019 14:26:22 -0500 Message-Id: <20190108192628.121270-114-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-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 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.19.1