Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp11815pxk; Wed, 23 Sep 2020 20:30:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw33oJW6iA1zg5KCmsKOpoPJGWfxl9z0mvywQcRxn0cNi+BflvOPax8XjqThAGnil7vInXL X-Received: by 2002:aa7:d68c:: with SMTP id d12mr2557082edr.274.1600918235795; Wed, 23 Sep 2020 20:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600918235; cv=none; d=google.com; s=arc-20160816; b=t3CH2KAAcaC/f6Klhrx6gPe82KWEm8Vp0bGFUlLFyWaAtVFKOq3NSn/slVoKAHIcxw Im5aHp5aFjNe0KcLXmmaEGUYp3BiTO3XmOzF7AlyRqd31ipsbrDmszazATBM2WYLacKF D6ZHLEq8ITBtZE68oT7eb6pu5fLa42dgmjW8fNSvI6wzPX7FDdNED2y6XMGKNgjWpnRS T01rjJiJrFHbYqUQihhOV2WF73etBMpA+b2IpmEGwc7A6ppg6yqn0MOmAlWeQQbmd6At 1Rd8Uw1szki1G9VzK1ZBmRqTgRhbVHa3fTWGS0xi4AJwkl2I9Ssn5sBkgccrjNVQtIqB /dyQ== 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=GxQb+a4u8RyZsUMixStTu6hKeDbOKN5BiEFAmKOZ2rk=; b=EJ12okBe2rJCRkoM1OYMxtHp5oiMEGRxeqp4eT2u7kxZgeSGL3QKDeI3TExeECq+wL NgNpkJkC2HtlDOSp1uYaQ6wno560QEg740DYIeXb0K9qZcrwGvT1pS7hDDUTb89cwN11 3wBBtwdXNWYlzk3qwAoiBJGc4rhymdGWO7tNrx+CZM887wS91EDmfTEQpi8ckSP/ucbn L6FFm0XrbNr8tOpx2XaTDNChrp6lL1r769ZcZXhehYnxzTynFaLnfhBiKGxAu7B1TD4J keXp8PfY4Gg/7/fWadjT9rbg7Y59LFuRbEPOQy5PtiksM2w3eHadxG1227pCzw3Uf667 9wMw== 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 p25si1329978edw.585.2020.09.23.20.30.12; Wed, 23 Sep 2020 20:30:35 -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 S1727169AbgIXD3C (ORCPT + 99 others); Wed, 23 Sep 2020 23:29:02 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:39010 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726863AbgIXD2o (ORCPT ); Wed, 23 Sep 2020 23:28:44 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=23;SR=0;TI=SMTPD_---0U9w0Ss1_1600918116; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U9w0Ss1_1600918116) by smtp.aliyun-inc.com(127.0.0.1); Thu, 24 Sep 2020 11:28:39 +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, aaron.lwe@gmail.com Cc: =?UTF-8?q?Mika=20Penttil=C3=A4?= Subject: [PATCH v19 05/20] mm/thp: Simplify lru_add_page_tail() Date: Thu, 24 Sep 2020 11:28:20 +0800 Message-Id: <1600918115-22007-6-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600918115-22007-1-git-send-email-alex.shi@linux.alibaba.com> References: <1600918115-22007-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 fa0753229b52..8b92cd197218 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2326,25 +2326,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