Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp153357ybm; Wed, 27 May 2020 22:35:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznR+HlGn2x3WoPx6O2oKDrcFqAjfVdkjh9srRt/ptXHeuZLO2rQcGvaQp5Nggr7Xz3W0/7 X-Received: by 2002:a17:906:63c9:: with SMTP id u9mr1500808ejk.439.1590644125893; Wed, 27 May 2020 22:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590644125; cv=none; d=google.com; s=arc-20160816; b=ZDJIaKx27YOQeu8qOAt3TE3VcAcE4lfNvZn3qLv+BltcpYc87gl5iDZy+Ulu1m9aWh EdSQXFUdZ+gCYqhPT/J85vigphnmSyBMozPudTXbJj3gvUGo8TKFVoaFxcS2Y8ulf46w pBa0ksW6iyINPVm1BOvCKcYjeqC2iOGcqhmryWXBPRlCTk5JuGLy8Nmg1r4ShbpsaKRm ixpeqrRD0QxHisP3N/J8KS1kBjdHj/HbUTK1Yx8eDvadOrFHpOqqb/xcsp78pHkpAz3a bJPTv1D8rQoivlDajYppWOpEUaoo+KA5jbvWGar844EHxgC60dI5ynIyzFfQ8HtAuZ2/ fmnw== 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=fDkn6qzQjzkRTtHN8YkuzyZALpjdw5udnw14DVboDPU=; b=P9VYAgAhMKVdJuSqmrLTSheNFKjYL4IgOIhd7V5yGxrY/x3fbwGLvp4FKXPy69Y8+/ ph6hGEH9dXWfpuWBXVRbvPQ4T0KucNlKKIcwHyxyDZn1xdFoabt8Oc1gcMNLUxapTFPA wTjgd+4AfE6Mx2HPAiqaePkSubIoTSsQecbhHLc641kl42Mt6MuJ6Vfdvv152r5DUYDZ 2+WS/TG5PPnvH0u8l0YgU0gHXTPtcwFG3BoQ/Le8Efib5txTa9N6i4EUU6Jx2//ghV+2 1cmKNEcICI/It83ZO4D6tV0Y1zfoHS6WsLSMCcXCP2aJ8h+ixW+V4MYQkG5mmIiWSOgt osXA== 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 z23si3228443ejb.144.2020.05.27.22.35.03; Wed, 27 May 2020 22:35:25 -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 S1727084AbgE1Fco (ORCPT + 99 others); Thu, 28 May 2020 01:32:44 -0400 Received: from mga11.intel.com ([192.55.52.93]:54187 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgE1Fco (ORCPT ); Thu, 28 May 2020 01:32:44 -0400 IronPort-SDR: LJS73g4EG92pLliactKOujehg4ZS5JpcVpX/5Ezug9iZyD8FyQp1iD+apQLdfaQmwiuyqfMoe7 6IuG6NhFiYAA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 22:32:43 -0700 IronPort-SDR: bsfo8pNe49nYQ0/GNqtd3UEJUSoRZQDa1Pbp2efFOQ3mivCF3w9mSiPALYXhivu/kWEdUkT6Oc 1E4/2DVdFfOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,443,1583222400"; d="scan'208";a="291877792" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.23]) by fmsmga004.fm.intel.com with ESMTP; 27 May 2020 22:32:41 -0700 From: "Huang\, Ying" To: Daniel Jordan Cc: Andrew Morton , , , Michal Hocko , Minchan Kim , Tim Chen , Hugh Dickins Subject: Re: [PATCH -V3] swap: Reduce lock contention on swap cache from swap slots allocation References: <20200525002648.336325-1-ying.huang@intel.com> <20200528013724.flx6pwcmaazpek32@ca-dmjordan1.us.oracle.com> Date: Thu, 28 May 2020 13:32:40 +0800 In-Reply-To: <20200528013724.flx6pwcmaazpek32@ca-dmjordan1.us.oracle.com> (Daniel Jordan's message of "Wed, 27 May 2020 21:37:24 -0400") Message-ID: <87h7w0hbev.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 Mon, May 25, 2020 at 08:26:48AM +0800, Huang Ying wrote: >> diff --git a/mm/swapfile.c b/mm/swapfile.c >> index 423c234aca15..0abd93d2a4fc 100644 >> --- a/mm/swapfile.c >> +++ b/mm/swapfile.c >> @@ -615,7 +615,8 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si, >> * discarding, do discard now and reclaim them >> */ >> swap_do_scheduled_discard(si); >> - *scan_base = *offset = si->cluster_next; >> + *scan_base = this_cpu_read(*si->cluster_next_cpu); >> + *offset = *scan_base; >> goto new_cluster; > > Why is this done? As far as I can tell, the values always get overwritten at > the end of the function with tmp and tmp isn't derived from them. Seems > ebc2a1a69111 moved some logic that used to make sense but doesn't have any > effect now. If we fail to allocate from cluster, "scan_base" and "offset" will not be overridden. And "cluster_next" or "cluster_next_cpu" may be changed in swap_do_scheduled_discard(), because the lock is released and re-acquired there. The code may not have much value. And you may think that it's better to remove it. But that should be in another patch. >> } else >> return false; >> @@ -721,6 +722,34 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, >> } >> } >> >> +static void set_cluster_next(struct swap_info_struct *si, unsigned long next) >> +{ >> + unsigned long prev; >> + >> + if (!(si->flags & SWP_SOLIDSTATE)) { >> + si->cluster_next = next; >> + return; >> + } >> + >> + prev = this_cpu_read(*si->cluster_next_cpu); >> + /* >> + * Cross the swap address space size aligned trunk, choose >> + * another trunk randomly to avoid lock contention on swap >> + * address space if possible. >> + */ >> + if ((prev >> SWAP_ADDRESS_SPACE_SHIFT) != >> + (next >> SWAP_ADDRESS_SPACE_SHIFT)) { >> + /* No free swap slots available */ >> + if (si->highest_bit <= si->lowest_bit) >> + return; >> + next = si->lowest_bit + >> + prandom_u32_max(si->highest_bit - si->lowest_bit + 1); >> + next = ALIGN(next, SWAP_ADDRESS_SPACE_PAGES); >> + next = max_t(unsigned int, next, si->lowest_bit); > > next is always greater than lowest_bit because it's aligned up. I think the > intent of the max_t line is to handle when next is aligned outside the valid > range, so it'd have to be ALIGN_DOWN instead? Oops. I misunderstood "ALIGN()" here. Yes. we should use ALIGN_DOWN() instead. Thanks for pointing this out! > > These aside, patch looks good to me. Thanks for your review! It really help me to improve the quality of the patch. Can I add your "Reviewed-by" in the next version? Best Regards, Huang, Ying