Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp328954pxx; Thu, 29 Oct 2020 03:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvNikTF/a9c5+JVsehbRBFTvujQ1Hss4B6uxlxEfUKPXoHVObpPAL6Dddp9g25gWXqgaFd X-Received: by 2002:a17:906:fa09:: with SMTP id lo9mr1077465ejb.411.1603968505306; Thu, 29 Oct 2020 03:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603968505; cv=none; d=google.com; s=arc-20160816; b=mZ2VfG+UQFI1Y4b/EDddbwVkkEJFacpXrRknOxOza4kDtc+0GZh3hr/8fPFMmWdv6P jQZpFjVs32NknGnK4gU3xUwUz9z2JmBcHhSDB3yGA17WM8QYVQbn3ZiI67loLJ3yk3Nv PU+rH3A/IUb7LSLJIt3xq+KOfWnPs4P8pUMWKkyb0gTDYNIBRAk5KL9RUGVEYVnzjMmZ kGRF7ypkxhCvpr+kYC8sWFmWWCbAgRkj25l6EQOLvuGR9f85FWDkyQYTxEMVHEZpAG6z +NIIt+ErBkgLmr96NojvF/MkZNQRt2G86q4mqF4n1nANg2CyuUE2GqDC7nhOCNuEl1e/ bWLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/jYbRu6SzXkt5mOnINfXPeTEhdfDCWW0RTfUkll+fak=; b=DJGqNw3QwrT/C+CFVc9JZ8gKimo3MRfcEb8rZ61XmyYVhLQCaffYbcdXIfV7SO/n5M COXpQKFSd1s/HFNoRm4meTJUCqoU+Y+VBmX3R1xZGnMtkuqXWXmGlD9FDDg88A2BJ5z8 bG/kZ8x8487TdpmC2OQm+BqB6eOix21S0eEccHlo9SMsqSgeZV7ImoQBTAi00Hs7daGj 5b+1oULnkAzW7AZAOC4DwGJOwYsjhyXJs+okIIq7ehEtLnGL3VNTxHn+01GA/oB0U5Qs vbVaiBC+3hLcSYivUB3XXpKcHZJS+6TsvS+Pgx8tP6osTFotGbaZvbTulwf5ysOlAzBf 2hUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r27si610360edi.304.2020.10.29.03.48.02; Thu, 29 Oct 2020 03:48:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbgJ2Kpo (ORCPT + 99 others); Thu, 29 Oct 2020 06:45:44 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:51553 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbgJ2Kpg (ORCPT ); Thu, 29 Oct 2020 06:45:36 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=22;SR=0;TI=SMTPD_---0UDXwDyN_1603968328; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UDXwDyN_1603968328) by smtp.aliyun-inc.com(127.0.0.1); Thu, 29 Oct 2020 18:45:30 +0800 From: Alex Shi To: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com, kirill@shutemov.name, alexander.duyck@gmail.com, rong.a.chen@intel.com, mhocko@suse.com, vdavydov.dev@gmail.com, shy828301@gmail.com Cc: =?UTF-8?q?Mika=20Penttil=C3=A4?= Subject: [PATCH v20 05/20] mm/thp: Simplify lru_add_page_tail() Date: Thu, 29 Oct 2020 18:44:50 +0800 Message-Id: <1603968305-8026-6-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603968305-8026-1-git-send-email-alex.shi@linux.alibaba.com> References: <1603968305-8026-1-git-send-email-alex.shi@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simplify lru_add_page_tail(), there are actually only two cases possible: split_huge_page_to_list(), with list supplied and head isolated from lru by its caller; or split_huge_page(), with NULL list and head on lru - because when head is racily isolated from lru, the isolator's reference will stop the split from getting any further than its page_ref_freeze(). So decide between the two cases by "list", but add VM_WARN_ON()s to verify that they match our lru expectations. [Hugh Dickins: rewrite commit log] Signed-off-by: Alex Shi Reviewed-by: Kirill A. Shutemov Acked-by: Hugh Dickins Cc: Kirill A. Shutemov Cc: Andrew Morton Cc: Johannes Weiner Cc: Matthew Wilcox Cc: Hugh Dickins Cc: Mika Penttilä Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/huge_memory.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 93c0b73eb8c6..4b72dd7b8b34 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2354,25 +2354,16 @@ static void lru_add_page_tail(struct page *head, struct page *page_tail, VM_BUG_ON_PAGE(PageLRU(page_tail), head); lockdep_assert_held(&lruvec_pgdat(lruvec)->lru_lock); - if (!list) - SetPageLRU(page_tail); - - if (likely(PageLRU(head))) - list_add_tail(&page_tail->lru, &head->lru); - else if (list) { + if (list) { /* page reclaim is reclaiming a huge page */ + VM_WARN_ON(PageLRU(head)); get_page(page_tail); list_add_tail(&page_tail->lru, list); } else { - /* - * Head page has not yet been counted, as an hpage, - * so we must account for each subpage individually. - * - * Put page_tail on the list at the correct position - * so they all end up in order. - */ - add_page_to_lru_list_tail(page_tail, lruvec, - page_lru(page_tail)); + /* head is still on lru (and we have it frozen) */ + VM_WARN_ON(!PageLRU(head)); + SetPageLRU(page_tail); + list_add_tail(&page_tail->lru, &head->lru); } } -- 1.8.3.1