From patchwork Fri Dec 17 11:30:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 525333 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1E93C433F5 for ; Fri, 17 Dec 2021 11:33:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235466AbhLQLdy (ORCPT ); Fri, 17 Dec 2021 06:33:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27311 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235464AbhLQLdx (ORCPT ); Fri, 17 Dec 2021 06:33:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639740832; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UOrVV2NFx26u84MVGLWI5jLwDTFzF180mJVk+c6k5Rs=; b=b3h1DYf8FJmQyhXxN8DyCyrjxglmBWl0trfcWY8kagaD+rH/a2jk8v4dX0DfTc+sBR/EYd 27u3Yw9w6p23nR9+BCGHxWtw7n6a1ROvHItItVtnccGrmbJlNgDNSmkbk94rJHHtf1UhYM grqLjvyFPmXyPgf+dn5mW7LlaYniknU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-rZlAI3i2NSemwQWONFDUoA-1; Fri, 17 Dec 2021 06:33:47 -0500 X-MC-Unique: rZlAI3i2NSemwQWONFDUoA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E0C61018723; Fri, 17 Dec 2021 11:33:45 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.193.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id C61F08ACF7; Fri, 17 Dec 2021 11:33:37 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , Linus Torvalds , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, David Hildenbrand Subject: [PATCH v1 04/11] mm: thp: simlify total_mapcount() Date: Fri, 17 Dec 2021 12:30:42 +0100 Message-Id: <20211217113049.23850-5-david@redhat.com> In-Reply-To: <20211217113049.23850-1-david@redhat.com> References: <20211217113049.23850-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Let's simplify a bit, returning for PageHuge() early and using head_compound_page() as we are only getting called for HEAD pages. Note the VM_BUG_ON_PAGE(PageTail(page), page) check at the beginning of total_mapcount(). This is a preparation for further changes. Reviewed-by: Peter Xu Signed-off-by: David Hildenbrand Reviewed-by: Yang Shi Acked-by: Kirill A. Shutemov --- mm/huge_memory.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4751d03947da..826cabcad11a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2506,12 +2506,11 @@ int total_mapcount(struct page *page) if (likely(!PageCompound(page))) return atomic_read(&page->_mapcount) + 1; + if (PageHuge(page)) + return head_compound_mapcount(page); - compound = compound_mapcount(page); nr = compound_nr(page); - if (PageHuge(page)) - return compound; - ret = compound; + ret = compound = head_compound_mapcount(page); for (i = 0; i < nr; i++) ret += atomic_read(&page[i]._mapcount) + 1; /* File pages has compound_mapcount included in _mapcount */