From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3525BC433DF for ; Fri, 22 May 2020 05:58:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0343120757 for ; Fri, 22 May 2020 05:58:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0343120757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9912A80008; Fri, 22 May 2020 01:58:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9410380007; Fri, 22 May 2020 01:58:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82F3580008; Fri, 22 May 2020 01:58:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 6AE3B80007 for ; Fri, 22 May 2020 01:58:46 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 26FD0180AD820 for ; Fri, 22 May 2020 05:58:46 +0000 (UTC) X-FDA: 76843301052.22.thumb17_122342eaa964f X-HE-Tag: thumb17_122342eaa964f X-Filterd-Recvd-Size: 3146 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 05:58:44 +0000 (UTC) IronPort-SDR: UxEyQYptSPTavHuvRBzLYPU03bGo8brWvU2I1GqKcW9vD68jp+AJfpA47aYOktpf0vlu47Lrwo s8w+guuRADAw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.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 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: 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 >> >>