From patchwork Sat Apr 11 10:11:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11484063 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 E9EB381 for ; Sat, 11 Apr 2020 10:12:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD6B72087E for ; Sat, 11 Apr 2020 10:12:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kC6MD1xU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD6B72087E 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 BC19D8E00A8; Sat, 11 Apr 2020 06:12:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B98608E0007; Sat, 11 Apr 2020 06:12:09 -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 AD4568E00A8; Sat, 11 Apr 2020 06:12:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 9A2C18E0007 for ; Sat, 11 Apr 2020 06:12:09 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5545B8245571 for ; Sat, 11 Apr 2020 10:12:09 +0000 (UTC) X-FDA: 76695158778.12.books90_872d54f04511c X-Spam-Summary: 2,0,0,165ff4d43e9a4845,d41d8cd98f00b204,qiwuchen55@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1359:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3354:3866:4321:5007:6114:6261:6642:6653:7576:9413:10004:11026:11473:11658:11914:12048:12296:12297:12438:12517:12519:12555:12679:12895:13255:14096:14181:14394:14721:21080:21444:21451:21627:21666:30012:30054,0,RBL:209.85.214.194:@gmail.com:.lbl8.mailshell.net-62.50.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: books90_872d54f04511c X-Filterd-Recvd-Size: 5612 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Apr 2020 10:12:08 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id h11so1502365plk.7 for ; Sat, 11 Apr 2020 03:12:08 -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=RpZZhmESw7UBiFNZ9aiqIiBYivpobHxEFMPYoj/b4Y4=; b=kC6MD1xUox0U+VECTE16FjmB2DLvP8QDLIO47bX4RDU1mZI9Uk+2C1WYbp3xC5EG27 +wVfq19O+lxbC/y+D+mCnXUb5hJMVmpuakbQJ8gzF3FY1+pul1wR+Ib/xXkz8DPa+lIr cLciJkhK6JcTQiFl6/DOY6NAE4sDnJRRM21o1LmPkAQKBnnzkEwKWI8CRynx+wpW/72o zG7y1qBL5530bq96slqTGU21fpbAeHwkN7xkS9o7wlm/zuvO/kpaGMVhkF4bCvMVyhjy DYiB6a4vXKFPaU0a1OpJJfVjT2Qq0K3OCbd08C6+Kyirw8EhTmiJ/SWW3X7EJQLijGn3 fRbA== 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=RpZZhmESw7UBiFNZ9aiqIiBYivpobHxEFMPYoj/b4Y4=; b=I5uBGHeC5JqggW+SBzzCfXuRTXqU8Rx31S9fcxqkgvb64COHFLB5D0HxBz25VTpc4U Ix2Fgxv6SXloNciRPPKR/G7+vAX/Le52We1PPJIb41TaLzaMKMmwd0wDAyV0JmhzRdpY rF8GMT2mmyBTSmGKQGfoEQAEoEso2P/7pomL+A60oMvXl6ecDOyWOVqebgnBiOKO0qAj vvJRoPBhzbLZOrK11MrXT1rEYNidoY9UmqXKrS7HSqOFI/gPCXtIRgDR7fsniKam/kuv B+BELLo/hB0/XF3K+LJxim2zXxSyslldbbGClS4Od21Jn9FJabfFogvXT3wSN5C/RMv9 HPpA== X-Gm-Message-State: AGi0PuakUoe8CYouzaW87xAzJEEJJ7jX7859Skdjzn6dTO2EaKtcWAHj F0PpSVGuR97m9EkOPk7P5+I= X-Google-Smtp-Source: APiQypLjVau19fCUDsMlm/j46O4zv4Wky+zzujEBK1drnvytTIhPmkn1isYPpSdiZ3sjuj+bkrvDRg== X-Received: by 2002:a17:902:a5cc:: with SMTP id t12mr8847625plq.322.1586599927999; Sat, 11 Apr 2020 03:12:07 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id a129sm3875802pfb.127.2020.04.11.03.12.07 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sat, 11 Apr 2020 03:12:07 -0700 (PDT) From: qiwuchen55@gmail.com To: akpm@linux-foundation.org, willy@infradead.org, david@redhat.com, richard.weiyang@gmail.com, mhocko@suse.com, pankaj.gupta.linux@gmail.com, yang.shi@linux.alibaba.com, cai@lca.pw, bhe@redhat.com Cc: linux-mm@kvack.org, chenqiwu Subject: [RESEND PATCH 2/3] mm/swapfile: use list_{prev,next}_entry() instead of open-coding Date: Sat, 11 Apr 2020 18:11:55 +0800 Message-Id: <1586599916-15456-2-git-send-email-qiwuchen55@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1586599916-15456-1-git-send-email-qiwuchen55@gmail.com> References: <1586599916-15456-1-git-send-email-qiwuchen55@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: From: chenqiwu Use list_{prev,next}_entry() instead of list_entry() for better code readability. Signed-off-by: chenqiwu --- mm/swapfile.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 5871a2a..8d8dc67 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3654,7 +3654,7 @@ static bool swap_count_continued(struct swap_info_struct *si, spin_lock(&si->cont_lock); offset &= ~PAGE_MASK; - page = list_entry(head->lru.next, struct page, lru); + page = list_next_entry(head, lru); map = kmap_atomic(page) + offset; if (count == SWAP_MAP_MAX) /* initial increment from swap_map */ @@ -3666,13 +3666,13 @@ static bool swap_count_continued(struct swap_info_struct *si, */ while (*map == (SWAP_CONT_MAX | COUNT_CONTINUED)) { kunmap_atomic(map); - page = list_entry(page->lru.next, struct page, lru); + page = list_next_entry(page, lru); BUG_ON(page == head); map = kmap_atomic(page) + offset; } if (*map == SWAP_CONT_MAX) { kunmap_atomic(map); - page = list_entry(page->lru.next, struct page, lru); + page = list_next_entry(page, lru); if (page == head) { ret = false; /* add count continuation */ goto out; @@ -3682,12 +3682,10 @@ static bool swap_count_continued(struct swap_info_struct *si, } *map += 1; kunmap_atomic(map); - page = list_entry(page->lru.prev, struct page, lru); - while (page != head) { + while ((page = list_prev_entry(page, lru)) != head) { map = kmap_atomic(page) + offset; *map = COUNT_CONTINUED; kunmap_atomic(map); - page = list_entry(page->lru.prev, struct page, lru); } ret = true; /* incremented */ @@ -3698,7 +3696,7 @@ static bool swap_count_continued(struct swap_info_struct *si, BUG_ON(count != COUNT_CONTINUED); while (*map == COUNT_CONTINUED) { kunmap_atomic(map); - page = list_entry(page->lru.next, struct page, lru); + page = list_next_entry(page, lru); BUG_ON(page == head); map = kmap_atomic(page) + offset; } @@ -3707,13 +3705,11 @@ static bool swap_count_continued(struct swap_info_struct *si, if (*map == 0) count = 0; kunmap_atomic(map); - page = list_entry(page->lru.prev, struct page, lru); - while (page != head) { + while ((page = list_prev_entry(page, lru)) != head) { map = kmap_atomic(page) + offset; *map = SWAP_CONT_MAX | count; count = COUNT_CONTINUED; kunmap_atomic(map); - page = list_entry(page->lru.prev, struct page, lru); } ret = count == COUNT_CONTINUED; }