From patchwork Tue Apr 21 21:38:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11502237 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 A66E792C for ; Tue, 21 Apr 2020 21:38:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 720A1206E9 for ; Tue, 21 Apr 2020 21:38:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G+kyl4n3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 720A1206E9 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 9F81E8E0005; Tue, 21 Apr 2020 17:38:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9A8968E0003; Tue, 21 Apr 2020 17:38:50 -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 8BDAC8E0005; Tue, 21 Apr 2020 17:38:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 70FB58E0003 for ; Tue, 21 Apr 2020 17:38:50 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 24791181AC9CB for ; Tue, 21 Apr 2020 21:38:50 +0000 (UTC) X-FDA: 76733177220.26.queen25_12e6a1ae58125 X-Spam-Summary: 2,0,0,5213713365f77617,d41d8cd98f00b204,richard.weiyang@gmail.com,,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3868:3870:3871:4385:4390:4395:5007:6119:6120:6261:6653:7514:7901:7903:9413:9592:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13069:13311:13357:14181:14384:14687:14721:21080:21324:21444:21627:21666:21990:30046:30054:30070,0,RBL:209.85.221.65:@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: queen25_12e6a1ae58125 X-Filterd-Recvd-Size: 4140 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 21 Apr 2020 21:38:49 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id j1so22379wrt.1 for ; Tue, 21 Apr 2020 14:38:49 -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; bh=QgHQYt+tSYmVX1FszAKxvpLA+NP+fPMv9Zm76RuSMDY=; b=G+kyl4n334TCZJ0kpD3OlF7g3uExQx5sGvCxzuEreMno1d9LZsTxQQGpRaQfmmcTr2 +tNWGLmqgt6B9XK230gc9C0rx5dMZ6PYeF+uAQ+EMgrGmIS9E1F2f67NpK3jw0QSSEXj D+dum1sm57swdZ8Y65LkRCXCRRddFOcIurynbAnJyN3Ei1Xt6zN5CSQmvV4HFQKkQ8ny dk+hES3vuLPeXma1MCbv6ZJpXdf/HDk0crpKTwQlOhfFHnuzYtL/gIrvWVNCNLgUDrCr 1GilaKl13y4DhBRJ2IlMM48Je6JjPuYSAgQ4S9ZTr7Umpfo8HbXFTUS5xdqAge8Ycugy EUTQ== 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; bh=QgHQYt+tSYmVX1FszAKxvpLA+NP+fPMv9Zm76RuSMDY=; b=qLTPCcSqfebdH0BSfALntxmW2PW8K4L0DejN/TFvVri28k6DS+y7Lk0hppfWTFOgh8 UxhVKzZLRMgioF0g1CVGeHnTiJFFpzM/TJU7+o85358mfIkUb61895dNH93BmLAYa5Md vWSKAXbNoxtrNG7g5DsOE4Hxt9Kl3vkbDN/oeDBBuP7EVnEBW4Ne6ut2tX6dE7kCNkqR kU9klqEW6zRu4QX+VNmmZjTDGGhts2dW5OMI4WDTYwgLfZMACXqwyw+QPImPVuLsfKeE Opwr1/CjRPZqLx+q+Oh3WnpPQNBO8ubGCIuLj386LdaSvB/3vFyL8h00HYoPb4UVvnKS EO+Q== X-Gm-Message-State: AGi0PuYqJPRtpODy6pz70II3+1nJR3Z7xl51dM8vekd4ou0+tqldOnoN WkvmFZvz2BVdzPDOyyhQpio= X-Google-Smtp-Source: APiQypLq6kd84+XIo3taeW1VrsqbybXePe+7oakneNj52RAHgTQ9SX7DCMV5m5610uW5+gYBcRYJ+Q== X-Received: by 2002:adf:f34e:: with SMTP id e14mr15160051wrp.193.1587505128647; Tue, 21 Apr 2020 14:38:48 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id m188sm4989305wme.47.2020.04.21.14.38.47 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Apr 2020 14:38:47 -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 1/3] mm/swapfile.c: found_free could be represented by (tmp < max) Date: Tue, 21 Apr 2020 21:38:22 +0000 Message-Id: <20200421213824.8099-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 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: This is not necessary to use the variable found_free to record the status. Just check tmp and max is enough. Signed-off-by: Wei Yang Reviewed-by: "Huang, Ying" --- mm/swapfile.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 469ab417ed43..d203cdc6750a 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -601,7 +601,6 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si, { struct percpu_cluster *cluster; struct swap_cluster_info *ci; - bool found_free; unsigned long tmp, max; new_cluster: @@ -623,8 +622,6 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si, return false; } - found_free = false; - /* * Other CPUs can use our cluster if they can't find a free cluster, * check if there is still free entry in the cluster @@ -638,21 +635,19 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si, } ci = lock_cluster(si, tmp); while (tmp < max) { - if (!si->swap_map[tmp]) { - found_free = true; + if (!si->swap_map[tmp]) break; - } tmp++; } unlock_cluster(ci); - if (!found_free) { + if (tmp >= max) { cluster_set_null(&cluster->index); goto new_cluster; } cluster->next = tmp + 1; *offset = tmp; *scan_base = tmp; - return found_free; + return tmp < max; } static void __del_from_avail_list(struct swap_info_struct *p) From patchwork Tue Apr 21 21:38:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 11502239 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 EA75281 for ; Tue, 21 Apr 2020 21:38:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B803A206D5 for ; Tue, 21 Apr 2020 21:38:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="giZgIw5h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B803A206D5 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 7AF498E0006; Tue, 21 Apr 2020 17:38:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7874F8E0003; Tue, 21 Apr 2020 17:38:51 -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 5B1A18E0006; Tue, 21 Apr 2020 17:38:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 406F78E0003 for ; Tue, 21 Apr 2020 17:38:51 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 001F51269 for ; Tue, 21 Apr 2020 21:38:50 +0000 (UTC) X-FDA: 76733177220.20.class45_130519815ca4b X-Spam-Summary: 2,0,0,6010a4e8628c9872,d41d8cd98f00b204,richard.weiyang@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1539:1568:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3867:3871:4321:5007:6119:6120:6261:6653:7514:7901:7903:9413:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13069:13311:13357:14181:14384:14687:14721:21080:21444:21627:21666:21990:30054,0,RBL:209.85.221.68:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.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: class45_130519815ca4b X-Filterd-Recvd-Size: 3459 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Tue, 21 Apr 2020 21:38:50 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id d17so18244436wrg.11 for ; Tue, 21 Apr 2020 14:38:50 -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=WRpu/B/BcLywABR29mrWPu2uoAJ9/VJSM0fTjNe1z1w=; b=giZgIw5hopQlDgtKbM9riyJzJFH2CshUYM5a8ilw8GDfxO7fvnRIz35dV6c4S9ZTGP g5Zvu4KLohGXerp9aeGi+jbrrm+jCMZabZDXciO4MIoPWXYB1UIij6xYX5Lj6QFU6pmD Rly5Uhtv4nF4j/MrhREuxYLanN5W7OTxFyVpoYScAjoeBmjOi+txL/N61zFkYpGlt+BT Yv56xufsafyun7YT4Vw61HblXzta/YJsyleo8Zb2aFpaEieWkXXWkO7ESQ+Aw/8iwdr5 b1e5VJyB6te6AFCfj3dk04MI43HP7HL6vUjIYthqeZrOn2N4Kxz0w5ZOfOYm1i2laqhV gd6A== 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=WRpu/B/BcLywABR29mrWPu2uoAJ9/VJSM0fTjNe1z1w=; b=aD8aBPpYuqwkWOfuskHMsxQlJgTBIWtbPCp1k1OIBt7xKHo85ITS3NfvgKgvS4c7+c 027eP2SXX2W/oP3usIKb576IPqF8zu61LZgsPpzC2HtKvhZ+qqGN/ucsbUBr1/qtXNAR bCmTS5wApgjoWwF3aQYhCCqb/E0A+J8trKOqR+abQ6m9nEekSX6CZhlIJMNQmwj0sMFw Dw2uLY2W7OnE6i5z2B7BlD1jxjrnMjLtK8XavgvyBugzviGD2ONCSHRZQXCVsLRJJEco K7zMyxmrMA5miq/uX5iyXs5l6tUioqf6hYlV/rJRe+4NlM5lxmJm0jTx0PPTuvcGr+q1 CNFg== X-Gm-Message-State: AGi0PubS8XsGlRIpQO5OsRHM3bqf9tIsIOTHrk5QE17UWTfkJDH5I35l i8hvEg9N0VV0HeyD8+dwJZxsWCDd X-Google-Smtp-Source: APiQypI2yjL9CchUqrZhpUBsV1FmNVI/ikALh8gb1VWRhyjQJx8cXksbomADqp9p5yVUDPC1mcfphg== X-Received: by 2002:adf:f30c:: with SMTP id i12mr27356377wro.426.1587505129723; Tue, 21 Apr 2020 14:38:49 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id t17sm5372085wro.2.2020.04.21.14.38.48 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Apr 2020 14:38:49 -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 2/3] mm/swapfile.c: tmp is always smaller than max Date: Tue, 21 Apr 2020 21:38:23 +0000 Message-Id: <20200421213824.8099-2-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.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If tmp is bigger or equal to max, we would jump to new_cluster. Return true directly. Signed-off-by: Wei Yang --- mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index d203cdc6750a..bc435c2eb916 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -647,7 +647,7 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si, cluster->next = tmp + 1; *offset = tmp; *scan_base = tmp; - return tmp < max; + return true; } static void __del_from_avail_list(struct swap_info_struct *p) 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;