From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D6A9C433ED for ; Thu, 13 May 2021 14:54:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBB0C61435 for ; Thu, 13 May 2021 14:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234705AbhEMOzN (ORCPT ); Thu, 13 May 2021 10:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234823AbhEMOwh (ORCPT ); Thu, 13 May 2021 10:52:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50993C061346; Thu, 13 May 2021 07:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=H1NmysONfH93wRxMzbKIRXMjO3sQy9N1aOQConHhku0=; b=j0U7U0KxCjG8TbXLUokLW8ygK4 unQ5UMYf+It+N2ARfOjZrJUGd7raTpl84OmLbbydENw/nOS6I/ySHPrIBlTK86QPnCnT94yZL6lSY VCTmecp5NB+CiHdvaxcktwj55f2yaubMcP/6DD/23YUZ6z4xyk5FthNt7tHt6Skbas0IcEdD6D9fX WoxcuTkvUkO3e+w3qCeEqpHjXGt+X/OLX1t9sHVC9286L4izzDh1/EGdDGLQKESrIVIQ5Swz1T6TZ /RdWq8rD4m7LYJ5mwp1sRhlEPvk6v9rPITP6/Ch/Qn1NQ7q8FwC0xZAJhkTzR+lfcNx0H3oEMM+ip i/bpWC5A==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lhCfh-009W9H-1T; Thu, 13 May 2021 14:50:52 +0000 Date: Thu, 13 May 2021 15:50:41 +0100 From: Matthew Wilcox To: akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 00/33] Memory folios Message-ID: References: <20210511214735.1836149-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511214735.1836149-1-willy@infradead.org> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Tue, May 11, 2021 at 10:47:02PM +0100, Matthew Wilcox (Oracle) wrote: > We also waste a lot of instructions ensuring that we're not looking at > a tail page. Almost every call to PageFoo() contains one or more hidden > calls to compound_head(). This also happens for get_page(), put_page() > and many more functions. There does not appear to be a way to tell gcc > that it can cache the result of compound_head(), nor is there a way to > tell it that compound_head() is idempotent. I instrumented _compound_head() on a test VM: +++ b/include/linux/page-flags.h @@ -179,10 +179,13 @@ enum pageflags { #ifndef __GENERATING_BOUNDS_H +extern atomic_t chcc; + static inline unsigned long _compound_head(const struct page *page) { unsigned long head = READ_ONCE(page->compound_head); + atomic_inc(&chcc); if (unlikely(head & 1)) return head - 1; return (unsigned long)page; which means it catches both calls to compound_head() and page_folio(). Between patch 8/96 in folio_v9 and patch 96/96, the number of calls in an idle VM went down from almost 7k/s to just over 5k/s; about 25%.