From patchwork Wed Mar 30 10:25:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Wandun X-Patchwork-Id: 12795637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EA0BC433F5 for ; Wed, 30 Mar 2022 10:06:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34DC88D0001; Wed, 30 Mar 2022 06:06:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B7918D0005; Wed, 30 Mar 2022 06:06:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08E298D0001; Wed, 30 Mar 2022 06:06:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id DFA078D0001 for ; Wed, 30 Mar 2022 06:06:44 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A24F62434C for ; Wed, 30 Mar 2022 10:06:44 +0000 (UTC) X-FDA: 79300623528.03.8500E5A Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf04.hostedemail.com (Postfix) with ESMTP id 5D9D040016 for ; Wed, 30 Mar 2022 10:06:43 +0000 (UTC) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KT28q5fk6zDq9W; Wed, 30 Mar 2022 18:04:27 +0800 (CST) Received: from dggpemm500002.china.huawei.com (7.185.36.229) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 30 Mar 2022 18:06:40 +0800 Received: from localhost.localdomain (10.175.112.125) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 30 Mar 2022 18:06:40 +0800 From: Chen Wandun To: , , , Subject: [PATCH v2 1/2] mm: fix contiguous memmap assumptions about split page Date: Wed, 30 Mar 2022 18:25:33 +0800 Message-ID: <20220330102534.1053240-2-chenwandun@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220330102534.1053240-1-chenwandun@huawei.com> References: <20220330102534.1053240-1-chenwandun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500002.china.huawei.com (7.185.36.229) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 18qnqdu5khh3m81nmeqdszk5ctz7oni6 Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.hostedemail.com: domain of chenwandun@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=chenwandun@huawei.com X-Rspamd-Queue-Id: 5D9D040016 X-HE-Tag: 1648634803-143598 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: It isn't true for only SPARSEMEM configs to assume that a compound page has virtually contiguous page structs, so use nth_page to iterate each page. Inspired by: https://lore.kernel.org/linux-mm/20220204195852.1751729-8-willy@infradead.org/ Signed-off-by: Chen Wandun --- mm/compaction.c | 6 +++--- mm/huge_memory.c | 2 +- mm/page_alloc.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index c3e37aa9ff9e..ddff13b968a2 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -87,7 +87,7 @@ static unsigned long release_freepages(struct list_head *freelist) static void split_map_pages(struct list_head *list) { unsigned int i, order, nr_pages; - struct page *page, *next; + struct page *page, *next, *tmp; LIST_HEAD(tmp_list); list_for_each_entry_safe(page, next, list, lru) { @@ -101,8 +101,8 @@ static void split_map_pages(struct list_head *list) split_page(page, order); for (i = 0; i < nr_pages; i++) { - list_add(&page->lru, &tmp_list); - page++; + tmp = nth_page(page, i); + list_add(&tmp->lru, &tmp_list); } } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2fe38212e07c..d77fc2ad581d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2297,7 +2297,7 @@ static void lru_add_page_tail(struct page *head, struct page *tail, static void __split_huge_page_tail(struct page *head, int tail, struct lruvec *lruvec, struct list_head *list) { - struct page *page_tail = head + tail; + struct page *page_tail = nth_page(head, tail); VM_BUG_ON_PAGE(atomic_read(&page_tail->_mapcount) != -1, page_tail); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f648decfe39d..855211dea13e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3513,7 +3513,7 @@ void split_page(struct page *page, unsigned int order) VM_BUG_ON_PAGE(!page_count(page), page); for (i = 1; i < (1 << order); i++) - set_page_refcounted(page + i); + set_page_refcounted(nth_page(page, i)); split_page_owner(page, 1 << order); split_page_memcg(page, 1 << order); }