From patchwork Thu Nov 15 08:38:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 10683689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B8DE13B5 for ; Thu, 15 Nov 2018 08:38:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 679172C323 for ; Thu, 15 Nov 2018 08:38:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BAC12C3B4; Thu, 15 Nov 2018 08:38:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD9DB2C323 for ; Thu, 15 Nov 2018 08:38:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95EC26B000D; Thu, 15 Nov 2018 03:38:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 934DE6B000E; Thu, 15 Nov 2018 03:38:55 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84C076B0010; Thu, 15 Nov 2018 03:38:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 4712D6B000D for ; Thu, 15 Nov 2018 03:38:55 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id y2so6396214plr.8 for ; Thu, 15 Nov 2018 00:38:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:mime-version:content-disposition:user-agent; bh=4xRgo/74zHKKJhwxH+fQ/nFVPcnPmtJYXx/AFCrcwSs=; b=UIqNiF5Zz6KLCN3t0L41GDikH4IZUbHmdDoKYOBzYAH8yS5A5yfYB0N6A6Vpqxu4PK N1QkoD+1IaWuGDt3qm1rTGQtc5LFDNmj9HRmBWmcWzMF5CnvE7fLTjr9anaF0/Z+gFS8 j+nrwojCgu5V44PV1b24OTjaGhg3cJIMaLM3HaAhCJekJHqKmD3qk4xB5hHSCjDJ26vx T5zHGa3UGF/wCE1eyn5b/mYX30Bv8LGIOJ4KXg1jIUl7jCajPfraolG9gkT+WyrvY4Zm 0doxZsVXTgONusJ2oBygm1dSB4rfNkHEne4avI3eO9ucGUk8WG9IDYhucDWK7L4SnWHW 2VqQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AGRZ1gLBWpOcYqm/bvZDLoHQPELL+vEPgw7IfZYqOPPn2vkm4GvyXc4c 8GL6mvHNPUkzGjOCfCI3biCEQsAeayouX2r7k7hh6KRaDmVnH5aFP+AsgDJPbZk5V8bPm11MVUq 8xCppGRDcByEK5vz/SuEkfr7BaRxyganpX3tFei7BOCohpTzY9LaJvSAr8mGwW4xITg== X-Received: by 2002:a63:d301:: with SMTP id b1mr5012831pgg.61.1542271134876; Thu, 15 Nov 2018 00:38:54 -0800 (PST) X-Google-Smtp-Source: AJdET5egzZDPQT4iwzg4jFoKHj2LmCC8uDrPwt82jXiVuUw8M2TdIRbiJ3xwkGnDoyPfIZmpX1hw X-Received: by 2002:a63:d301:: with SMTP id b1mr5012805pgg.61.1542271134133; Thu, 15 Nov 2018 00:38:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542271134; cv=none; d=google.com; s=arc-20160816; b=wYYHIw7P++uKpnlL5KIpHoVC7+8e3PXDChFPSMpml/pGoe/VHNAegFbS69yHBqmW7R 89xx40dwMYoq7Y6KwFPiDzBqnfDtNDHOVXCTBWZzLi2/yvz/D/OuV+1XtBVEqfyqr4YX rXwQOlc8DqgHfKQuacD4GwNCbiO1LzgRm5sC0WMPXrQNwNJNZCGGVBex1vJ1wM93zKVy jV13BYciHIEOQdRl6NhfRLBDPbAbSQxx5P5GlKkoymIIl4hwBg/40tjDh8XUGCZLHzYP B5v/D0G6LsZE80WiSYEjEnAvAcKTaYoxI+BT+I70lU/0BQEnbKNeY0ZMMGu6dUGFSO14 oyaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date; bh=4xRgo/74zHKKJhwxH+fQ/nFVPcnPmtJYXx/AFCrcwSs=; b=r4B1b7hJcKbZEuBw6gnU941SDc8fl0iWjzI/AMIXgziUO5GSrdLVHOrJhyzCAZDFRI IeXFuY0cI/zaXklksOZoEseMLOcGXNMrPrv2/llTxpfHoaXoxzrZrXK1BNshzXYF4GyL v15ogBY0dMy8Bv/oNhbH91Y6eHLSgIE7nBwrclnPijKm3rxIIgkyAjZQwzUl4rQ7RJ0V q7ntOvzAVJ4T7SWKxbjMhlDsuXTfg572RaBcKyRd1Uxp2KB8FngvfcV4JEPEyOixmJBp +jD+jjgbrJoP3BlM77n66Oh2pCV/DYqX55iiBXTRpLhdEiM4dPMhyRZ3toXUKMy6ipa9 795g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com. [192.55.52.93]) by mx.google.com with ESMTPS id n15-v6si26885651pgc.143.2018.11.15.00.38.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 00:38:54 -0800 (PST) Received-SPF: pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aaron.lu@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 fmsmga102.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-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Michal Hocko --- 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);