Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932090AbdHRAm1 (ORCPT ); Thu, 17 Aug 2017 20:42:27 -0400 Received: from mga01.intel.com ([192.55.52.88]:28357 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932069AbdHRAm0 (ORCPT ); Thu, 17 Aug 2017 20:42:26 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,390,1498546800"; d="scan'208";a="301619811" Date: Fri, 18 Aug 2017 08:43:11 +0800 From: Aaron Lu To: Andrew Morton Cc: linux-mm , lkml , "Chen, Tim C" , Huang Ying , "Kleen, Andi" , Michal Hocko , Minchan Kim , Hugh Dickins Subject: Re: [PATCH v2] swap: choose swap device according to numa node Message-ID: <20170818004311.GB1996@intel.com> References: <20170814053130.GD2369@aaronlu.sh.intel.com> <20170814163337.92c9f07666645366af82aba2@linux-foundation.org> <20170815054944.GF2369@aaronlu.sh.intel.com> <20170815150947.9b7ccea78c5ea28ae88ba87f@linux-foundation.org> <20170816024439.GA10925@aaronlu.sh.intel.com> <20170817154408.66c37d2d84eccdb102b9e04c@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170817154408.66c37d2d84eccdb102b9e04c@linux-foundation.org> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1252 Lines: 34 On Thu, Aug 17, 2017 at 03:44:08PM -0700, Andrew Morton wrote: > On Wed, 16 Aug 2017 10:44:40 +0800 Aaron Lu wrote: > > ... > > > > +static int __init swapfile_init(void) > > +{ > > + int nid; > > + > > + swap_avail_heads = kmalloc(nr_node_ids * sizeof(struct plist_head), GFP_KERNEL); > > I suppose we should use kmalloc_array(), as someone wrote it for us. > > --- a/mm/swapfile.c~swap-choose-swap-device-according-to-numa-node-v2-fix > +++ a/mm/swapfile.c > @@ -3700,7 +3700,8 @@ static int __init swapfile_init(void) > { > int nid; > > - swap_avail_heads = kmalloc(nr_node_ids * sizeof(struct plist_head), GFP_KERNEL); > + swap_avail_heads = kmalloc_array(nr_node_ids, sizeof(struct plist_head), > + GFP_KERNEL); > if (!swap_avail_heads) { > pr_emerg("Not enough memory for swap heads, swap is disabled\n"); > return -ENOMEM; > > > + if (!swap_avail_heads) { > > + pr_emerg("Not enough memory for swap heads, swap is disabled\n"); > > checkpatch tells us that the "Not enough memory" is a bit redundant, as > the memory allocator would have already warned. So it's sufficient to > additionally say only "swap is disabled" here. But it's hardly worth > changing. Thanks Andrew for taking care of this.