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 48DE8C47DA9 for ; Tue, 16 Jan 2024 15:07:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D28906B007E; Tue, 16 Jan 2024 10:07:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD8906B0081; Tue, 16 Jan 2024 10:07:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B78EC6B0082; Tue, 16 Jan 2024 10:07:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9A79A6B007E for ; Tue, 16 Jan 2024 10:07:36 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6CE7CA05DE for ; Tue, 16 Jan 2024 15:07:36 +0000 (UTC) X-FDA: 81685503312.20.1BCF37D Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP id 9337F1C0021 for ; Tue, 16 Jan 2024 15:07:33 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705417654; a=rsa-sha256; cv=none; b=g5FDDpUQAT862r5FbXI+0MYqjb3bRCn58smPzdueE774qNWee63ubpCegxFAZr9GphnfsW zmW0UQgIG8y/Va8QY4UVwPnRaiYA7iv7dNs6QiuhboyT3Drpa4uWZUajkgd02BMNzUylY8 t3IlCbfKBdtmXs9N10AfkzZCqFtZABA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705417654; 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; bh=jAPXcxJVXub+pUutrrQKSsBmA+mqQLYrq1aYnHid2DU=; b=VwUZR3RmhiDtkUxa83GsL+RpMrybf9W8eKDforR9lqecGDlia3ISXECY6ix1Zs4CcOqeeL F+qaN1zyCo0phIzexbDh0miQNDjLSj9bpXC8l0F69b696A8gmN1JqOBZPKGTBrmNiCA7Rx l97R1H+PDZ38Bez89ctKOI5uQshCMLc= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 58FB02F4; Tue, 16 Jan 2024 07:08:18 -0800 (PST) Received: from [10.1.38.190] (XHFQ2J9959.cambridge.arm.com [10.1.38.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 500193F766; Tue, 16 Jan 2024 07:07:30 -0800 (PST) Message-ID: Date: Tue, 16 Jan 2024 15:07:28 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: memory: move mem_cgroup_charge() into alloc_anon_folio() Content-Language: en-GB To: Matthew Wilcox Cc: Kefeng Wang , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Hildenbrand References: <20240116071302.2282230-1-wangkefeng.wang@huawei.com> <2c24afdf-5103-4c1b-a649-2eeed185f3fb@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9337F1C0021 X-Stat-Signature: rj9cui7t3ajr4rrjep9awsfxp79y3wi8 X-HE-Tag: 1705417653-121741 X-HE-Meta: U2FsdGVkX18wCXF3LI1a59uBshbM1nsLnNns+j2FEzLWnQbWQS3PmPL+Up+wkUX4A6VKt1nDehafzQdgwYGdJK5aJfI3ns2oOpRiZI5NAIaCLZqWWgvwrmrFjPmgWxxYwmsu6Cq4TmXM8OYTJGMV+kDiExBzs5ani9Xp9z2uggzM8M7H3kmxcAihjUEohSCzk4WUb/+bgI1l6KhCDQoYedzk3Woa45DPVvFM1DqWHpFIfLCVZChzmTxhR4EZpwDU2oPv390il25MSSETjV7Uj5qOhFYKLc6V7tGM6lTINhnB/LtwJd363hdb44i3cFo923j/QBHyyVIp1IZ/cFMUMsjWpDMJLgLvvZWLaGO+OWquzWbADb+DiLYs5OAUY5iUP5txSi9OpTIKF966k2ENR1+PvCI32Tv0Urbu0FbNBtTFiIBLqn/Ren/54Pb+vZpmnln5Lntu4sMvvjfTIvoL0lLelreVj+GSIvNmnXSN0H5RYXIL3uD3UQIe/WKDIB+y42YzjJo8irnUkEnXhrgfEkMF/HHXRBTgMfmEsKGNbZjoLT3ua9G/X4U3okAeD/bMgTjAjXQ2ImavWysEJNkuS3rBLbPwR7Km5ySVfdbRv4j7NwFgcDLiDTU2sfy79+Fu27lHxKOHt9CJv6cIXm2kk3o5STLB0lN2QDUCSmQGV/1dD2vqaagp3/7pVt5TB7Br2mkByRbNBys2S/QN7WSlee2dCEh0T3T/1mlJavp0TDUE6+q5qwW/yzKaEfMbRljq6sF5o3ZqZJ71pzAvKwfWlfnIwE7Dbp6hUTxEd2zE+/REIIDHFsv3Izi6JVS/9PA2rj4ge7Ub2n+LgvoJqaNeGSK2u41YgaUKcv7Pd465wWcn2/LLAvrl+LIRsTgyNPMkx/kuVOkuS57rwfV6EEyVm52T6/Agybnn4WESgBk6Y22vFrW2fMepKqazv9oCuleU9dWx7KAFphPO7hH3XDe JxlodGCv ERX6Y9csEYVMfl4/RadmhcslOGGtPr/RJ3HhfskS6PoRmHgODGXoPXIUKVIcPss/Hw0KEYDQpwC3IPYSnUspJVRgN5TBniMulqZsCx77NqUFdtyiBfdEZtSvYRkuxN3CPpMZULAi3v0nidfRviF3ZVvYUssPgcV++IwHnKMkdi3tnMqitHDPEX7rj4w56W9xZ5yHZ 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 16/01/2024 14:51, Matthew Wilcox wrote: > On Tue, Jan 16, 2024 at 02:35:54PM +0000, Ryan Roberts wrote: >> On 16/01/2024 07:13, Kefeng Wang wrote: >>> In order to allocate as much as possible of large folio, move >>> the mem charge into alloc_anon_folio() and try the next order >>> if mem_cgroup_charge() fails, also we change the GFP_KERNEL >>> to gfp to be consistent with PMD THP. >> >> I agree that changing gfp gives you consistency. But it's not entirely clear to >> me why THP should use one set of flags for this case, and since pages another. >> Why does this difference exist? > > I think it needs to be spelled out much better in the changelog. Here's > my attempt at explaining why we might want this change. > > mem_cgroup_charge() uses the GFP flags in a fairly sophisticated way. > In addition to checking gfpflags_allow_blocking(), it pays attention to > __GFP_NORETRY and __GFP_RETRY_MAYFAIL to ensure that processes within > this memcg do not exceed their quotas. Using the same GFP flags ensures > that we handle large anonymous folios correctly, including falling back > to smaller orders when there is plenty of memory available in the system > but this memcg is close to its limits. Thanks for the explanation. Please add to the commit log. Essentially you are saying that previously, all mTHP allocations would cause reclaim from the memcg if the allocation caused the quota to be used up. But with this change, it might now avoid that reclaim and just OOM, if the flags are as such? So then we retry with the next lowest available size. Makes sense! > > ... I remain not-an-expert in memcg and anonymous memory and welcome > improvements to that text. Me too...