Received: by 2002:a25:1104:0:0:0:0:0 with SMTP id 4csp8998ybr; Thu, 21 May 2020 23:00:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWCClkdy/BDnXFU7t2sEz3MEcFt8QLWci3BdYiUbM1+vdnhNzAh20g1jxWVLp/EZUDR9qs X-Received: by 2002:a17:906:24d8:: with SMTP id f24mr6474948ejb.215.1590127243378; Thu, 21 May 2020 23:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590127243; cv=none; d=google.com; s=arc-20160816; b=sSTSeg0ONDf/ya/rLtPMbQ5m3cGduOsX/VEcKnMksTHW78aLrozbO5BB6F5p2eOoku Ik2yEFi/UzCwj68ubbLg/v52EDU6gmgHIdiXTlf7bfzSyuZij96IIdIJLFzlnYY16KKq 1c4CoY2/SridLl9LSxa5s98tpHS494Nd1Gh37Owcq6WRBIojrJq+wAmabycWovQlgFwr YYWvFfGHKv7QBR+BtTywBdvx6u1QFwA1Me4TBeJM6zsHiusPtIxmwC/O/RUWcdf0NdFK 6YItZE2D+OaWFVnVcM7Oydegovv7lbO/l5FBy8JKWVZAD26Fm2ELLNiDSSBqE2Ztzc2t wuVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=ENxaKqM2maY+C8KOlPW0mGcSQKWBoaZs3nTd9+3iKRk=; b=m7DEWgUFQx7lMohzTqAYdaWHslX9DMMftIinoSsuSAYa+mPeBVfkrU+vJVwh+14gF7 2XK385YSljkKKiJ3TLSgVh9glp2ZoRzoZaVwuFktGYkbs30XyvowF17EV7QY9VgLnSQg fuU5cE2BrxwWqhtSsG8N2udvRnluZLUaYOZZ9+3d6VmXfU01V3Q7HsEoeNrfmX4HehzA UydSqAeGXIw3tEz/NHHYXBDgrafCSKB2yJ8MnvRb0afhTU8XJXUyGwlzCSyIgiq0sa9C cx8ctYzejji/kIyUyzy2GS0pqwwm0XKdFO2kt53vpQ/0KFTCkTeCNHg3PJxZCPcgIcEu 1Zeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id m20si4226953ejr.172.2020.05.21.23.00.20; Thu, 21 May 2020 23:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728036AbgEVF6n (ORCPT + 99 others); Fri, 22 May 2020 01:58:43 -0400 Received: from mga07.intel.com ([134.134.136.100]:43232 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbgEVF6n (ORCPT ); Fri, 22 May 2020 01:58:43 -0400 IronPort-SDR: o9/cl5+7WQDF8B2+B+6LXdOmKufFGpVwlfMoOlYZ52vVTqr27QuDWJZexwwRa2BJqZiPIYlv6K lEuUXOyeMQJg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2020 22:58:43 -0700 IronPort-SDR: FnnWhX2QZNStnp4GwA81W75zcQbEaKamW4ev5n8+EPijJ9cfzSYmwGD/2I7th8MrZ9l78uH74g cvux58dsWFxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,420,1583222400"; d="scan'208";a="440746731" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.23]) by orsmga005.jf.intel.com with ESMTP; 21 May 2020 22:58:40 -0700 From: "Huang\, Ying" To: Daniel Jordan Cc: Andrew Morton , , , Michal Hocko , Minchan Kim , Tim Chen , Hugh Dickins Subject: Re: [PATCH -V2] swap: Reduce lock contention on swap cache from swap slots allocation References: <20200520031502.175659-1-ying.huang@intel.com> <20200521133532.psckytr456eevs5j@ca-dmjordan1.us.oracle.com> Date: Fri, 22 May 2020 13:58:40 +0800 In-Reply-To: <20200521133532.psckytr456eevs5j@ca-dmjordan1.us.oracle.com> (Daniel Jordan's message of "Thu, 21 May 2020 09:35:32 -0400") Message-ID: <877dx4ik8f.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Daniel Jordan writes: > On Wed, May 20, 2020 at 11:15:02AM +0800, Huang Ying wrote: >> @@ -2827,6 +2865,11 @@ static struct swap_info_struct *alloc_swap_info(void) >> p = kvzalloc(struct_size(p, avail_lists, nr_node_ids), GFP_KERNEL); >> if (!p) >> return ERR_PTR(-ENOMEM); >> + p->cluster_next_cpu = alloc_percpu(unsigned int); >> + if (!p->cluster_next_cpu) { >> + kvfree(p); >> + return ERR_PTR(-ENOMEM); >> + } > > There should be free_percpu()s at two places after this, but I think the > allocation really belongs right... > >> @@ -3202,7 +3245,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) >> * select a random position to start with to help wear leveling >> * SSD >> */ >> - p->cluster_next = 1 + prandom_u32_max(p->highest_bit); > > ...here because then it's only allocated when it's actually used. Good catch! And yes, this is the better place to allocate memory. I will fix this in the new version! Thanks a lot! Best Regards, Huang, Ying >> + for_each_possible_cpu(cpu) { >> + per_cpu(*p->cluster_next_cpu, cpu) = >> + 1 + prandom_u32_max(p->highest_bit); >> + } >> nr_cluster = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER); >> >> cluster_info = kvcalloc(nr_cluster, sizeof(*cluster_info), >> -- >> 2.26.2 >> >>