From patchwork Tue Apr 21 21:38:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11502241 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2FD492C for ; Tue, 21 Apr 2020 21:38:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AEC50206D5 for ; Tue, 21 Apr 2020 21:38:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ny1jxqte" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AEC50206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4F11E8E0007; Tue, 21 Apr 2020 17:38:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 42B7C8E0003; Tue, 21 Apr 2020 17:38:52 -0400 (EDT) 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 340A18E0007; Tue, 21 Apr 2020 17:38:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 1A3EF8E0003 for ; Tue, 21 Apr 2020 17:38:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C7E7D180AD81F for ; Tue, 21 Apr 2020 21:38:51 +0000 (UTC) X-FDA: 76733177262.15.bomb83_1326ad204851f X-Spam-Summary: 2,0,0,3acc0c358261ba9a,d41d8cd98f00b204,richard.weiyang@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3868:3871:5007:6119:6120:6261:6653:7514:7901:7903:9413:10004:11026:11658:11914:12043:12297:12438:12517:12519:12555:12895:13069:13161:13229:13255:13311:13357:14181:14384:14687:14721:14819:21080:21444:21627:21666:21740:30012:30054:30070,0,RBL:209.85.221.66:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: bomb83_1326ad204851f X-Filterd-Recvd-Size: 4107 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Tue, 21 Apr 2020 21:38:51 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id f13so18263525wrm.13 for ; Tue, 21 Apr 2020 14:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sSR5r/wajhT1lzrVFFeM0Q886ybMNfo5cBVQSVOnGIM=; b=Ny1jxqtehmWMDptZW60CSQE8CJkfg1lEhguzt9FOAlo742lBQ+gpgvLZRcG141kIgz KAlnPIUkhknP0kf48niP1Al398vZoJx1gVz0ep+zcZtaH9hIbgLjijUcQ6tj6yTudBtc Qqrvx92zv4Hp+o8V1lNo0GEDDa9aQ+iCWzcdbkgDcHL2fXsADwwLFWzQv6UFcwqBbWSh z1h1c5YaFkV0jA75VPqYkiIy/i9wlONCA1Y/HR0x214ZrgKJfxRXBQT6dK7n0iBV3rRl eeRbYllFkQQ+1cbS7rpxHfAgq3oYrW5uGrkmLoJ6iO00f6Wbk6yHgJztIufyb2jCJMC5 Un3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sSR5r/wajhT1lzrVFFeM0Q886ybMNfo5cBVQSVOnGIM=; b=fw3q9GQbCCTKdllC+/be5ZzPCITBW8MahE9vm8LiXz6KSO6NGqp7cyygWe1+8wfwUW IqSMWTvLcs/rspkXa219dRbgxgyIuITgn8N4SduyKnX49bcsTomA7fgZ4VpEkF48jaoY 7uy2x8VI7lcMpFsO2rrpEXGP0+gBEpE36yJatCNQta4qX985Ke8lKJPE6cAPB95CTf6a E57GBrKsO5U3N64xxCaOFgRyPRTw+KbqlH921IQkJpvH/esQQhk5cWCFy8vDSO8ZBuLt 02tCoJyIxdmAUrruzLIrDng5dDr+A1uavhx5ZmZ4oE2bnqcznD8dR/QXCiEX/t6/OUAP KLHA== X-Gm-Message-State: AGi0PuYUk4jV2uf4/20VWOOyLI1NqgrIlYEmX3RgJ8IwaGpa6Qz1itWs SuFRYa4/wVTg3GbLgTidpV8= X-Google-Smtp-Source: APiQypJ6Wah3T29xpCEPhuLy6v6b3AoGB+41adC9U4sLqRp+MhkBYpyo6Snc9Cw4/xQsOOUaKOcukQ== X-Received: by 2002:a5d:48cc:: with SMTP id p12mr27664497wrs.170.1587505130600; Tue, 21 Apr 2020 14:38:50 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id i5sm5242518wrw.77.2020.04.21.14.38.49 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Apr 2020 14:38:50 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, tim.c.chen@linux.intel.com, ying.huang@intel.com, Wei Yang Subject: [Patch v2 3/3] mm/swapfile.c: omit a duplicate code by compare tmp and max first Date: Tue, 21 Apr 2020 21:38:24 +0000 Message-Id: <20200421213824.8099-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200421213824.8099-1-richard.weiyang@gmail.com> References: <20200421213824.8099-1-richard.weiyang@gmail.com> 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: There are two duplicate code to handle the case when there is no available swap entry. To avoid this, we can compare tmp and max first and let the second guard do its job. No functional change is expected. Signed-off-by: Wei Yang --- v2: Huang Ying suggest to do this check to avoid lock contention --- mm/swapfile.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index bc435c2eb916..f3eee6d8cddf 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -629,17 +629,15 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si, tmp = cluster->next; max = min_t(unsigned long, si->max, (cluster_next(&cluster->index) + 1) * SWAPFILE_CLUSTER); - if (tmp >= max) { - cluster_set_null(&cluster->index); - goto new_cluster; - } - ci = lock_cluster(si, tmp); - while (tmp < max) { - if (!si->swap_map[tmp]) - break; - tmp++; + if (tmp < max) { + ci = lock_cluster(si, tmp); + while (tmp < max) { + if (!si->swap_map[tmp]) + break; + tmp++; + } + unlock_cluster(ci); } - unlock_cluster(ci); if (tmp >= max) { cluster_set_null(&cluster->index); goto new_cluster;