From patchwork Sat Apr 11 10:11:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11484061 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 EAAE6112C for ; Sat, 11 Apr 2020 10:12:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ABA2A20709 for ; Sat, 11 Apr 2020 10:12:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H5ghIjTE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ABA2A20709 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 DE3238E00A7; Sat, 11 Apr 2020 06:12:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D93DD8E0007; Sat, 11 Apr 2020 06:12:06 -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 CA8E98E00A7; Sat, 11 Apr 2020 06:12:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B08B08E0007 for ; Sat, 11 Apr 2020 06:12:06 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 66EF6181AEF0B for ; Sat, 11 Apr 2020 10:12:06 +0000 (UTC) X-FDA: 76695158652.22.rod31_86c52f6634014 X-Spam-Summary: 2,0,0,c607a2f543600004,d41d8cd98f00b204,qiwuchen55@gmail.com,,RULES_HIT:41:355:379:541:800:960:967:973:988:989:1260:1345:1437:1535:1542:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2525:2553:2559:2564:2682:2685:2693:2859:2901:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4384:4605:5007:6117:6261:6653:7576:7903:9010:9025:9413:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12895:12986:13138:13161:13229:13231:14181:14394:14721:21067:21080:21444:21451:21524:21627:21666:21740:21972:30034:30054:30070:30090,0,RBL:209.85.215.194:@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:25,LUA_SUMMARY:none X-HE-Tag: rod31_86c52f6634014 X-Filterd-Recvd-Size: 5622 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Apr 2020 10:12:05 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id m13so2071024pgd.8 for ; Sat, 11 Apr 2020 03:12:05 -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=OVzQqFEoc2Z1cD6F3AZ39C8HuvuCRfqRmrAizJDXF4k=; b=H5ghIjTE3dXCr9y268knH91Kmezn50JifUatYpjYW/SjfnecfvfCJupACkXfY5Dt+7 QePVwbm5NFQeKlpuNP5yH14tqL3hwqVW4BIaZvx3WSibHiPYnnaUFUj3xZAkzHw4HCcZ 7B7XPKyvLH4ljxx74OLtj5oTz6P1VsvWlfvtKzNvYW6QXzA7PmNSnfcctRql/jgOB8da J4hmEOJA08T+0Xj/oZ1RAtrjh5el9os6ARvSpfEjrKymCDixLYN2TFxd4quYmZ6LYmPM WWGONZXQrUqk4gb05UO//aetlh9p/KDRE7Vd8QWRfgwFTGpaPWCQnCl8OtOJqO7JCQEK EOaw== 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=OVzQqFEoc2Z1cD6F3AZ39C8HuvuCRfqRmrAizJDXF4k=; b=bhY3J2g9EqQ10zfFKGwqFDszYc9EotL3PcAj6JJFQCbHIGInsPrqVVCyJfLYQT8xz6 Agruk6I8o4ABGdd/3EmfoE7+vK24mx2ugNDOteWW/u0DvT4fjuUE4dfdPTGQYo2o5DmR +nb0lUfCdbU1p9GQIhU3gk67fYYgn2snKODcI/MsKaAOU0TX+aXUyPCES5vbjOdlliLy bWo7/iefozu8fKu/K6TVwu6mMOMx85kKx8xcVkVQBzF/n8zFF/qrUm8pCP7tNc6r45IU qKZ65cduz+kJQUiGADU+N668PtvauMk04gT7n36w1Eu0+R3W8nh/InT/H8CRRIkiXF7c zj6A== X-Gm-Message-State: AGi0PuaybgDJWyYZHMoEDVgH4uJWUO7pqBumGR4YPxxbnvvrvLkbNGIT W08GqIkUqV2NrR+ww2v0QWY= X-Google-Smtp-Source: APiQypKQbz8aTn1sfrN6BusDdI3Yq92Ca9ELoq+jUmugU5nBzKy0iBJ3q3eMxpQwQY8k9Tqpp4yzaQ== X-Received: by 2002:a63:e74b:: with SMTP id j11mr8598511pgk.145.1586599925068; Sat, 11 Apr 2020 03:12:05 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id my15sm4120276pjb.28.2020.04.11.03.12.03 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sat, 11 Apr 2020 03:12:04 -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 1/3] mm: Replace zero-length array with flexible-array member Date: Sat, 11 Apr 2020 18:11:54 +0800 Message-Id: <1586599916-15456-1-git-send-email-qiwuchen55@gmail.com> X-Mailer: git-send-email 1.9.1 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 The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: chenqiwu Reviewed-by: Wei Yang --- include/linux/mm.h | 2 +- include/linux/mmzone.h | 2 +- include/linux/swap.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5a32342..9831bb5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1718,7 +1718,7 @@ struct frame_vector { unsigned int nr_frames; /* Number of frames stored in ptrs array */ bool got_ref; /* Did we pin pages by getting page ref? */ bool is_pfns; /* Does array contain pages or pfns? */ - void *ptrs[0]; /* Array of pinned pfns / pages. Use + void *ptrs[]; /* Array of pinned pfns / pages. Use * pfns_vector_pages() or pfns_vector_pfns() * for access */ }; diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 1b9de7d..f6b9fa9 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1147,7 +1147,7 @@ struct mem_section_usage { DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION); #endif /* See declaration of similar field in struct zone */ - unsigned long pageblock_flags[0]; + unsigned long pageblock_flags[]; }; void subsection_map_init(unsigned long pfn, unsigned long nr_pages); diff --git a/include/linux/swap.h b/include/linux/swap.h index b835d8d..e1bbf7a 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -275,7 +275,7 @@ struct swap_info_struct { */ struct work_struct discard_work; /* discard worker */ struct swap_cluster_list discard_clusters; /* discard clusters list */ - struct plist_node avail_lists[0]; /* + struct plist_node avail_lists[]; /* * entries in swap_avail_heads, one * entry per node. * Must be last as the number of the 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; } From patchwork Sat Apr 11 10:11:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11484065 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 B8B4481 for ; Sat, 11 Apr 2020 10:12:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7B77520709 for ; Sat, 11 Apr 2020 10:12:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pf0JEOs4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B77520709 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 88B778E00A9; Sat, 11 Apr 2020 06:12:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 83CC68E0007; Sat, 11 Apr 2020 06:12:12 -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 752748E00A9; Sat, 11 Apr 2020 06:12:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id 5C78B8E0007 for ; Sat, 11 Apr 2020 06:12:12 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1E9B98245571 for ; Sat, 11 Apr 2020 10:12:12 +0000 (UTC) X-FDA: 76695158904.04.mask89_8795360fa6b53 X-Spam-Summary: 2,0,0,ee40108c18437d99,d41d8cd98f00b204,qiwuchen55@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3353:3865:3866:3867:4250:4321:5007:6119:6261:6653:7576:9413:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12895:13255:14181:14394:14721:21080:21444:21451:21627:21666:30012:30054:30070,0,RBL:209.85.216.66:@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: mask89_8795360fa6b53 X-Filterd-Recvd-Size: 5000 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Apr 2020 10:12:11 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id t40so1667383pjb.3 for ; Sat, 11 Apr 2020 03:12:11 -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=7s8+SiauSEv/YpKtd1pikErl5fNcXJDNTR96pshyq6o=; b=Pf0JEOs43MUlug9jc3fYtUZdvGWmMCgRI4gIdk4Bn3/f27seTwOurFVJ/uZK6Q3t+q e9/IPnqz2r+8wCcB4MVKdsGd/OvV+Orn1QIYofh185hZrlDpT0qXJYOZ0ArieFQcOcuW FaFkpVULTZTWhKxt+U5NtHYgVtT5a1O9Jq63htoZifVxM0Dati2xu+3y+3bJjEZFmAcG sA7AnOTUkeQfgeXIoEBbwTwatAhorzp9ahNSn9F4ZDFEBaBBe3ggZawYk/taT6naoEfa YvxebllJDbr8eZJHn3PK8UBK5BKMbvryzrElrhzdt34b7JjQPqb++/12EKu5DGw1cD2s 97BA== 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=7s8+SiauSEv/YpKtd1pikErl5fNcXJDNTR96pshyq6o=; b=aC4a0WYwO6dTV0WlsYXpurTmOnwR0I4EjHJAT+hAOl0D5IMQTdnTQCkH9QLJXy1Rxo 2Fp2fHi1FCwSWsWvDQr9sPl4T98VgTlzd2Xbk2BIiG3Lu03qYG4zW7rI5bPBKbo2xSzv 3SL4XWXmyBcwTA4z+C1WWYgbJctUN3neatn/NYXtLtYaD1hGC38Y3WIdI9muaiNlXsX5 0qBa1xk9OLWJS6eB5yWjuDn0c73/QKK2LACrYVxvqrRKjkcn3mOc71s0RxXA1nTAxCaw QStF7a2nPIVglbUnN6RCDtEa+gQbEpOcVNmvNl+E7/yQI4ExuidNYlIHOkzn9Ym4Yzut jKvg== X-Gm-Message-State: AGi0PuaR2BIFkXmMXVvz7sckm5B8nr0aJnpS/vz5W29ToJ5ZvB9ch637 mo6oRtXTqC1R44rqZzaWB3g= X-Google-Smtp-Source: APiQypJKO41SwoGYtMr0W78Iy4uRRnomN4YPjQ1CcHK8Gd4pMjlPVLol/r86FW15PfZ8WWS+pKcJNQ== X-Received: by 2002:a17:90a:a402:: with SMTP id y2mr10777507pjp.55.1586599930865; Sat, 11 Apr 2020 03:12:10 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id e143sm933711pfh.98.2020.04.11.03.12.10 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sat, 11 Apr 2020 03:12:10 -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 3/3] mm/vmscan: make several optimizations for isolate_lru_pages() Date: Sat, 11 Apr 2020 18:11:56 +0800 Message-Id: <1586599916-15456-3-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 1) Simplify the code of initializing some variables. 1) Constify the LRU isolation mode. 2) Define a page_zoneidx variable to reduce the redundant code of page_zonenum(). Signed-off-by: chenqiwu --- mm/vmscan.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index b06868f..2f65a91 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1638,16 +1638,15 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, struct list_head *src = &lruvec->lists[lru]; unsigned long nr_taken = 0; unsigned long nr_zone_taken[MAX_NR_ZONES] = { 0 }; - unsigned long nr_skipped[MAX_NR_ZONES] = { 0, }; + unsigned long nr_skipped[MAX_NR_ZONES] = { 0 }; unsigned long skipped = 0; - unsigned long scan, total_scan, nr_pages; + unsigned long scan = 0, total_scan = 0, nr_pages; LIST_HEAD(pages_skipped); - isolate_mode_t mode = (sc->may_unmap ? 0 : ISOLATE_UNMAPPED); + const isolate_mode_t mode = (sc->may_unmap ? 0 : ISOLATE_UNMAPPED); - total_scan = 0; - scan = 0; while (scan < nr_to_scan && !list_empty(src)) { struct page *page; + enum zone_type page_zoneidx; page = lru_to_page(src); prefetchw_prev_lru_page(page, src, flags); @@ -1657,9 +1656,10 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, nr_pages = compound_nr(page); total_scan += nr_pages; - if (page_zonenum(page) > sc->reclaim_idx) { + page_zoneidx = page_zonenum(page); + if (page_zoneidx > sc->reclaim_idx) { list_move(&page->lru, &pages_skipped); - nr_skipped[page_zonenum(page)] += nr_pages; + nr_skipped[page_zoneidx] += nr_pages; continue; } @@ -1677,7 +1677,7 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, switch (__isolate_lru_page(page, mode)) { case 0: nr_taken += nr_pages; - nr_zone_taken[page_zonenum(page)] += nr_pages; + nr_zone_taken[page_zoneidx] += nr_pages; list_move(&page->lru, dst); break;