Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp503423rdb; Tue, 16 Jan 2024 07:08:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHy1+XNcUM4x05HxK33KoDv5btjzzTtEqlmo8Nmn3E813RkkFdONeelxPafpiOc0vFiBQUO X-Received: by 2002:a6b:4e03:0:b0:7bf:417b:255d with SMTP id c3-20020a6b4e03000000b007bf417b255dmr3867176iob.26.1705417707406; Tue, 16 Jan 2024 07:08:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705417707; cv=none; d=google.com; s=arc-20160816; b=dEEsgY4Zqu5fh7P+IIbReE4YfA8FyminaQwTHRP1QlbpZSrFmbz0Hn8/Lj2FmADUei 5QtoDubgH45t/0bzlA0RnvJgLZKUNj5mcUMdounrj6Lej7vwqjzDqZ6cQ+5hfz76+++u ViiGrXTc2DKSZCxnstyH1hdAYz8K7OMbMLdtSWZQvQzELO4cqhnEd+lumc6amnAZ5QHl eH3HDrUqkkPljzatNLlg3QXEsA48zlX+pTjfDh/EALkDXvzJxSHv22Ev3XC4nHIu6f7m sYhyZfs6MzUborU8wWjqXBV1Q8CuUHRUWGMP+0+e0+0cAitP9dHs9ksPVXUzzzY/F2Yh 64GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=jAPXcxJVXub+pUutrrQKSsBmA+mqQLYrq1aYnHid2DU=; fh=jH5yKi6OBFDhlLQKMpdqrDeEx14KE/Tbnw2O+PjkIZg=; b=DTAUW1ZFkiZ24WSJpUXNj4nY3dBxcAQoNS/Zd8NGYN56zIeCYkmz7gyGGUf8Ncy13B ZeolmWOSFw73LlZ6L0rUJvfj2NB5gGYsAQiINXXq/LYeM+eltUIfn/Illc2LuYWHf2xb zrvL33Bu4gS5nMdlJxWAawGbLXQ+XCY/HhWq6IKxWvtnZmgYaAV+anC6n7x3GKn+1a5k Az/Z4wy1VQ7rMkcJ05nJTP3qx4XXEK52/rqGK7i06hrNDhu2dd6Zx51rep+XsTJriEe6 noSJ5z3Hp71Efe2KFeNJKaGPaGOPnjwgkerdGrjuHsxwOwtKfblWL+wy0ocX4fnaik3K az5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s64-20020a635e43000000b005cee87f85b8si11238252pgb.348.2024.01.16.07.08.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 07:08:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7C7FEB2342A for ; Tue, 16 Jan 2024 15:07:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A2701BF46; Tue, 16 Jan 2024 15:07:36 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC8031C283 for ; Tue, 16 Jan 2024 15:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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...