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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 103F5C4332F for ; Wed, 13 Dec 2023 16:23:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 958B86B049B; Wed, 13 Dec 2023 11:23:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EC2E6B049A; Wed, 13 Dec 2023 11:23:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 783016B049B; Wed, 13 Dec 2023 11:23:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5D43C6B0499 for ; Wed, 13 Dec 2023 11:23:20 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2C5DF16036F for ; Wed, 13 Dec 2023 16:23:20 +0000 (UTC) X-FDA: 81562314960.16.ACD9484 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 6862240021 for ; Wed, 13 Dec 2023 16:23:18 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Op7617ny; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702484598; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EISI4/kf/Dz7Z6lVkd21mLFfzIYUgBRdcqpPAoblHZw=; b=RekMBV7rCE6jCrTgqUL5IQUz45NFJyGVzWNNAJ41rsXmw6JVzF3LGNUQTJLIO7yL1CB/QN k+QPKx6s79T8oIN29G0g4689ZqWD+W2WzQSzjUISGw+/vYODoOWrcR+h0E1VloJsuvqYC5 tG149xS2fr0HWxUjmKE+I71HOASOF4w= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Op7617ny; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702484598; a=rsa-sha256; cv=none; b=aQ63deqbJBQONKz9lFncYpMJk9toU0nkZbtecLzYNPJKb3hLGU77HmMmqJHNMh2d7Tg6VM 0M3hm/V3WnkIHkn7k4gzmyZk5wSbDzvPCbrsMM2MNs8OMAg+PD/Clj7MGWMlOvMYykHdIp JyrETjAtKiIK5Ev4cl7w+U5MfeRpkmY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=EISI4/kf/Dz7Z6lVkd21mLFfzIYUgBRdcqpPAoblHZw=; b=Op7617nyOzQzoi088HeVn4uU6m 8SDA13AdUVM4gmzm6QFlnh2s9XeMZlg8poKwMRam1eF5CRxT3vB39PInbw2xaWNiWw87idHJLEnHv ZBZ/4eZSRdttlgpfHLKXXkGGKbtoSBCF8DNdweKUUeIG67QXRQwsKz9EObjjG6f1eo/3m5E1aF4Vs Xa+4yJL51v3UtXc9Op+DXEskZA412F3miraYTMBes+IagVuedqOlptk7WOOc/rchxmDomoqjyaPeN vXJc0+04eP8+3Gs8oNvDxXNZGFhW/WEL69eArHm02ET2TI9kpe6jguuJwpeHtm2wflvZgqzeLisMu XbYTf4pA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rDS0q-002BLj-6q; Wed, 13 Dec 2023 16:23:08 +0000 Date: Wed, 13 Dec 2023 16:23:08 +0000 From: Matthew Wilcox To: Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , cgroups@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: memcg: remove direct use of __memcg_kmem_uncharge_page Message-ID: References: <20231213130414.353244-1-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 6862240021 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6oubdm15ih3bnc1j5ay5usr9ksdukdxb X-HE-Tag: 1702484598-965819 X-HE-Meta: U2FsdGVkX1/LHA84cowHOdliYfKUiMNpkJJX8o5jG18xz29mK6WchAPQB+1VSx1RlXYX9VYC1PC5+JUe/Em6+LDSkhc7+RPOE7a+nU+F+Y9+Yahr12T63vuPb4yZEO2YYqoLGtsoBYfe3JIE2rMfOohWdoHwmq9AwKR1Tf8yhOfCyKHceqfmRiMMKTEOReDUex0jmR62MdEdZpNp9htOcfNODBvm/lMcfzosLuAMu3ZiETP7oEM0IVEsEjhV2dIUEXJy+3nZGhQqDNOGqrrqDYFeE7sRKxP6hLNmqCGjJ0qu1Oq7FJukI4nnME7uIuJJcMHNI7UaLCBTmoJ0Ct0HNMGD+ok1Rbpq0lpYPrPDuN1TSLK/hmLJa0J5HS+ed8Jimk6m+w0tTbu0KGacovKlUj3SpPz2E1xY55NkcN7Kuwouwxw4rW9CNlB7KG/vDl5uYG1CbudcpPiYYE91/JVKQdiTeNOGcEgFsUG2b2T5rNgWKvw2BqqFuAapwVHA9HE7civLjKxltaMYcwnxQowvleIjD9naDvmfUSjQWAzoVJ0R7deENHWTkEmWcuGkCDI/RPy+V3D9v82CTAlwaji9fW4nrXMwNq6WBMZlWXpCF/afwJCdGnvTDlLqfw01VkcdnFbxoUABUWJJ1lYjobrQUE36HWM06bFUwif18/73sym2Sg2g7fz8jY4r1exN8NQAMNJ9w0AQN8rDyJT6Edq/WgNS/sif7aSYFkLI3ExZYtqLhIsPl1xbwwQZ4BrxTfhUNx1+fvpzegR3ddLjILwj9BRh9G8jWQBBTuI7uF/08y3Qe+0vc8FPfzI0hk+LPFyYPLqllA0+9Mj+tJ63/y5NXj1PeXBcswLrQVH6gm/kVIaMOtPrr+p95hUMEKESgN80wxoo5QE80T+vwiOnzGj0EcFv7NpOxLIeATwpCMuzZteSwTZSwdinXopGh3JDkUswy67kl/N0P9qM0iUj+gT ZzW6TjJJ aBeEYKQWMqLU8J2thQtTJfSHkwTdTaZGh0hIi3K3kKBSaB8XUzX6zBZQGwgN2PU5H2wmRlvJuqZIvVQY3OVtmUIYk4a6nEL5K8SR9eYJmemMfCTgyuT6x3/APY0OM3UNfpN7K/wImL/ntq/jToDoMSJmiqVPHHgiUJqDo80M+62JpbMdW+vIZsM/UCRq1129twbHwTP/Nwy+OD1rM9t+iCNxiBrjI9SGtSftb7guUhSgb2PxBTYsBR2tzxQ== 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: List-Subscribe: List-Unsubscribe: On Wed, Dec 13, 2023 at 07:42:44AM -0800, Yosry Ahmed wrote: > On Wed, Dec 13, 2023 at 7:38 AM Matthew Wilcox wrote: > > > > On Wed, Dec 13, 2023 at 07:08:52AM -0800, Yosry Ahmed wrote: > > > On Wed, Dec 13, 2023 at 7:01 AM Matthew Wilcox wrote: > > > > > > > > On Wed, Dec 13, 2023 at 01:04:14PM +0000, Yosry Ahmed wrote: > > > > > memcg_kmem_uncharge_page() is an inline wrapper around > > > > > __memcg_kmem_uncharge_page() that checks memcg_kmem_online() before > > > > > making the function call. Internally, __memcg_kmem_uncharge_page() has a > > > > > folio_memcg_kmem() check. > > > > > > > > > > The only direct user of __memcg_kmem_uncharge_page(), > > > > > free_pages_prepare(), checks PageMemcgKmem() before calling it to avoid > > > > > the function call if possible. Move the folio_memcg_kmem() check from > > > > > __memcg_kmem_uncharge_page() to memcg_kmem_uncharge_page() as > > > > > PageMemcgKmem() -- which does the same thing under the hood. Now > > > > > free_pages_prepare() can also use memcg_kmem_uncharge_page(). > > > > > > > > I think you've just pessimised all the other places which call > > > > memcg_kmem_uncharge_page(). It's a matter of probabilities. In > > > > free_pages_prepare(), most of the pages being freed are not accounted > > > > to memcg. Whereas in fork() we are absolutely certain that the pages > > > > were accounted because we accounted them. > > > > > > The check was already there for other callers, but it was inside > > > __memcg_kmem_uncharge_page(). IIUC, the only change for other callers > > > is an extra call to compound_head(), and they are not hot paths AFAICT > > > so it shouldn't be noticeable. > > > > How can you seriously claim that fork() is not a hot path? > > It's only called in fork() when an error happens. It's normally called > when a process is exiting. process exit is also a hot path. at least, there have been regressions reported that it's "too slow".