From patchwork Fri Apr 3 07:08:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11471933 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 F358C92A for ; Fri, 3 Apr 2020 07:09:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C0187206A3 for ; Fri, 3 Apr 2020 07:09:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dAnLP0l8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0187206A3 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 EE90E8E0008; Fri, 3 Apr 2020 03:09:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E98D48E0007; Fri, 3 Apr 2020 03:09:01 -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 D8ABD8E0008; Fri, 3 Apr 2020 03:09:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id BAF718E0007 for ; Fri, 3 Apr 2020 03:09:01 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7A73A8245578 for ; Fri, 3 Apr 2020 07:09:01 +0000 (UTC) X-FDA: 76665666882.18.sheet27_6bd871510fd05 X-Spam-Summary: 2,0,0,9f6a36f81c192854,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:3353:3865:3866:3867:3868:3870:3871:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6117:6261:6653:7576:7903:9025:9413:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13138:13161:13229:13231:14181:14394:14721:21067:21080:21444:21451:21524:21627:21666:21972:30034:30054:30070:30090,0,RBL:209.85.216.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:33,LUA_SUMMARY:none X-HE-Tag: sheet27_6bd871510fd05 X-Filterd-Recvd-Size: 5071 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Fri, 3 Apr 2020 07:09:00 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id z3so2555029pjr.4 for ; Fri, 03 Apr 2020 00:09:00 -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=hUeMyZXwhEwxA2pTgUgOHD5pi6gNLXqmjrpmUkxG2Wo=; b=dAnLP0l83oyhGTyako6RaKdhUPYM2sm93cFTRTBhIxQwG5GVot90Q23ASOMXNYeaCc e3WpsdPG8GrvftSALir2ZwM8f00E0JikYGnknSkgRwcKz6dM34OtYW97TRArgSu5Ec8u 1MBPKYB1v58iJvAbow7BPLttK1QcM8N/xpnxaz1OgDp60bD4lgR4bzg/qZgKXi6LXd+f nvpBIQdHEOjz9Cc7fwtZGEaRNXrEL//pRXlWX+lIxeNAtN+bv0jNYAqZfD6le/ot9ltz ft7QtAMulDGSFlZ2UFn53jB87BWpha02sO3OxTd6KBi175QEewIpNyWdwvtCqZ+pV3nv snww== 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=hUeMyZXwhEwxA2pTgUgOHD5pi6gNLXqmjrpmUkxG2Wo=; b=REVslgq9yljkNfJ1GdCkqHQ9GqgRfaMi+hrmjKI3aCGDGNMy06TTQGZ4RJbyYiWHH8 7AIHrz7SA52YkL/1OevhRm59FOS+yPz1rVBGfI4LfMK7nbIoz+d1+5lc1SLP47z1F4AH tQlA1FTyPJbUJgig9HuYr8FhELtMYgmUx5/ivVD1FedfO5NU1+mfZCsLVekB3HTep0jF F0x6l4rK/INTeHgGuaV03yn34k+ZHcVcXliOdpKRfkMi+SlFgFmkm7rqD9bDWphx8w6M zI2HQRz4bmqWY2dvaXHh9oEfYnb7/LFYsPuXJUNkft0Xwc1NOXoE5DDneAG38lw3ScgM RwsQ== X-Gm-Message-State: AGi0PubrzUBPGj8kDIWCuPKPbQM1MIW+QPmuoc1ZqjHPKiG2hV5edYpn 5nDqJKahum/BMzZySMB0aZc= X-Google-Smtp-Source: APiQypIyc29p12oIot4LSR0q+gQoJiZn73WcptRl8o42ruSnFvv5GeHdiTxoejBZZ6WRIPj6eQ4efw== X-Received: by 2002:a17:902:aa08:: with SMTP id be8mr6119717plb.299.1585897739827; Fri, 03 Apr 2020 00:08:59 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id y131sm5135908pfb.78.2020.04.03.00.08.58 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 03 Apr 2020 00:08:59 -0700 (PDT) From: qiwuchen55@gmail.com To: akpm@linux-foundation.org Cc: alexander.h.duyck@linux.intel.com, willy@infradead.org, vbabka@suse.cz, pankaj.gupta.linux@gmail.com, bhe@redhat.com, mhocko@kernel.org, linux-mm@kvack.org, chenqiwu Subject: [PATCH 1/2] mm: Replace zero-length array with flexible-array member Date: Fri, 3 Apr 2020 15:08:52 +0800 Message-Id: <1585897733-4696-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 --- include/linux/mm.h | 2 +- include/linux/mmzone.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index c54fb96..8dc699a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1528,7 +1528,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 462f687..0e3c685 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1187,7 +1187,7 @@ static inline unsigned long section_nr_to_pfn(unsigned long sec) struct mem_section_usage { DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION); /* 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); From patchwork Fri Apr 3 07:08:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 11471935 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 DEB8992A for ; Fri, 3 Apr 2020 07:09:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ABC7120CC7 for ; Fri, 3 Apr 2020 07:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f/6GCu/g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ABC7120CC7 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 AF0668E0009; Fri, 3 Apr 2020 03:09:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AA2098E0007; Fri, 3 Apr 2020 03:09:04 -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 9B8F78E0009; Fri, 3 Apr 2020 03:09:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0107.hostedemail.com [216.40.44.107]) by kanga.kvack.org (Postfix) with ESMTP id 7C8118E0007 for ; Fri, 3 Apr 2020 03:09:04 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3B80A6103 for ; Fri, 3 Apr 2020 07:09:04 +0000 (UTC) X-FDA: 76665667008.26.cover41_6c437ece8543b X-Spam-Summary: 2,0,0,3e16afeba4270733,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:4321:5007:6119:6261:6653:7576:9413:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:14181:14394:14721:21080:21444:21451:21627:21666:30012:30054:30070,0,RBL:209.85.214.196:@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:23,LUA_SUMMARY:none X-HE-Tag: cover41_6c437ece8543b X-Filterd-Recvd-Size: 4977 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Fri, 3 Apr 2020 07:09:03 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id w3so2364329plz.5 for ; Fri, 03 Apr 2020 00:09:03 -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=LGvDKN0ALlk06+d1xgRhJlTW8R5sXEolJFf66toYiqA=; b=f/6GCu/gEfuskjFM3bNjp231yE9H2aQu64vsB5XTBpQkB/Y3IuWQsctWR0HGU3/6F3 SgCT4g5RU5vTAA2va3djFIec4yR0BgWi+wkT1T+nNbIuOxyPCEKzpnj32D00n5dlhGB2 jYRmfNd4T+RMIL+UpD2KTQuRjwME/OQNokUM/F6VPz/KISxUq+n+NU+jfl8COozPMg9E VEnE4JxBs0JCAZl98L+8b2eOkahD4ltyKuD5gSXZfymoAfAPIlC2UPmS1MxhG3+HQjWn rA01ZoNQ+pJCdQbTyW8WjKS6u35iVs2sqPzRDV8/XQYwE193yJykmn/jPF7zgzlty+HE U7xw== 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=LGvDKN0ALlk06+d1xgRhJlTW8R5sXEolJFf66toYiqA=; b=aijIEDLwzHRi3+uva7Ex+WEb/mnAi6wq+rqU0Dl+eveCrcB7ErKzqcc/nZb2CJ5Tqm o/mRTpxOQumKAfdghtLLO8iPklqh+gc4e9GIl6D3z+7MU2ebdgpjH+/y8M4y3rhdjM4o Ef23HgkBQpyhXjOHL7hdSMYTLgQ27eROfhHi9OmZsNUoAxxstv3B1pWhZDjrJvFtgpCK F4PcOxQdHGXn6HNFKV0CwgzaA7+Hcnf0iN7upYamVojW52sP6MBHNvC5NC6WqTAL+6Si T9/3imZMw53B5NI8D2VIa48riFg6Gh+TYMZ6DYsidmtGunX0GXDpgyATjQf6yAzHjc6g 1MYw== X-Gm-Message-State: AGi0PuZNXe8fYt/oaLp0u/YDnOQwnkPNZ/a5z+qQpJzHHyoNslGrnZUC ieM0dAXJSxUzeeRSgh2Fxko= X-Google-Smtp-Source: APiQypISuOsRz719Ls1APINfCWFvTRXPMcNlw1E1YhVLv9Ni/xZcZvE69A9h2wK+QgcxggQFNXCkvw== X-Received: by 2002:a17:90a:5d96:: with SMTP id t22mr8399663pji.132.1585897742785; Fri, 03 Apr 2020 00:09:02 -0700 (PDT) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id e187sm5171287pfe.50.2020.04.03.00.09.01 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 03 Apr 2020 00:09:02 -0700 (PDT) From: qiwuchen55@gmail.com To: akpm@linux-foundation.org Cc: alexander.h.duyck@linux.intel.com, willy@infradead.org, vbabka@suse.cz, pankaj.gupta.linux@gmail.com, bhe@redhat.com, mhocko@kernel.org, linux-mm@kvack.org, chenqiwu Subject: [PATCH 2/2] mm/vmscan: make several optimizations for isolate_lru_pages() Date: Fri, 3 Apr 2020 15:08:53 +0800 Message-Id: <1585897733-4696-2-git-send-email-qiwuchen55@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1585897733-4696-1-git-send-email-qiwuchen55@gmail.com> References: <1585897733-4696-1-git-send-email-qiwuchen55@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 for initializing some variables. 1) Add const modifier to decorate the mode variable. 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 8763705..cf90e8b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1639,16 +1639,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); @@ -1658,9 +1657,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; } @@ -1678,7 +1678,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;