Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp491871rdb; Tue, 16 Jan 2024 06:51:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHoLoKndDIu90fjobsB6ysRr/U1CzrSsJc4dKgOxoOV+jr/MaOaRvn/GGQTTVqIW5zt2/FM X-Received: by 2002:a05:6402:78e:b0:559:205e:6ea4 with SMTP id d14-20020a056402078e00b00559205e6ea4mr2285277edy.4.1705416697599; Tue, 16 Jan 2024 06:51:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705416697; cv=none; d=google.com; s=arc-20160816; b=ixFA7uWh52AAAGZy+SjgTenf54syfVxroRDOGwPoUd5LWyH93Fy5mOa8S52B2VHaXA k32BTlJtUGiyMz8q/xI2MApV2XWfy7l1pYVm6Jz5uhQkMD6N3To6Y6yWiZpGhkaiytEp uc/iut94uUZG+gCm1GFsfLkIcpO5DhYQlLj5rNLMTnzK17yJVZcGfW8MhTNlKE4Sl6w/ cvkpnFEN/X8eWXBLGj8Vs0tMVFhKDtk8uAY8EE5RMwGEvCRHrybvKujZqLHM0u1CrI6f +Lw+4k7NvKZKxpSm2YlrIEioXS4bRBKPvCFPsZo07xgQrBVm4wjGDRitKadCCb/s29+S 6Wbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bzeqtQrfvVWqUxDWgwkWD87ZBMwUoyk439OaRZ4bHs0=; fh=YCP4iL8OXDHKFU3DXGH4WlrhkLs20lgzdMpJcyUt1RI=; b=ORlupEVoei24XH9neMhYdyXsxDZq9PTABHjJnrBq8IEd70CTOQYELnRqGxHuwyv9NH CAZMw2j39godZWcFVeZ2A81tk12qemw2yzvCLbpV3v4YZBEowHuKJw/3lsXQWSg63vCi 562BpiSBR2j87SBOBbU/Xz4dSLnbGmRBgsmEh0C02gVQIhpcrqmK27eriAAg2P6TAz3a GoF+5n17AgOseqGkLpJ8aq+WsIhzIEED4Quiy3SC62OKqY2InXTuwxfmoBJm93p3abrn 6VGnHw+8rCjcHaon/0OEntuxCtF6gsiIOBFTe6fYQ1bgXfAm//DNXwjcBDRjOS0up9xi Cbbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=casper.20170209 header.b=TN4d9eK3; spf=pass (google.com: domain of linux-kernel+bounces-27482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27482-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m12-20020a056402510c00b00553aa22b332si5075540edd.341.2024.01.16.06.51.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 06:51:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=casper.20170209 header.b=TN4d9eK3; spf=pass (google.com: domain of linux-kernel+bounces-27482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27482-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 333531F23E50 for ; Tue, 16 Jan 2024 14:51:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98CC51BF3A; Tue, 16 Jan 2024 14:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="TN4d9eK3" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17FD11BF33 for ; Tue, 16 Jan 2024 14:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org 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=Wo2ZeZzHWLKlJAoyYAf4I5Hw6H08g/lJvj5SWxry/6I=; b=TN4d9eK3eibLenJuYp8+drrwvC 2Qfn400Q7FkqyxnyUf/mn2VxsLmkOHhWen4/grB9bSWT7cXHS73tbrcJlJBDJpVcJVdb+Iuo7YQkN yS2XiLfdCz6TTDGzaxQC0jQKpArEgjk0aJEic+GwPOfjFUiuh5KBo2+/kwyIB2D5Jp0FIj+YLj762 nJTPM2dvMaH4xPpsItTkXPo3VqYfXsUahUIDjmIZqank7qlxTb2mmbSQj5L+9XIzQQXFkfQ48IXQu 02S5FAs1NcrKwZVSCAbtK/kivgzfl7jSjMRYrF8/Wp53msfJL59BN1UzJn/ncA8KdHAvCdArnLNJT TDMH/klg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rPkmX-00DJEv-IU; Tue, 16 Jan 2024 14:51:13 +0000 Date: Tue, 16 Jan 2024 14:51:13 +0000 From: Matthew Wilcox To: Ryan Roberts Cc: Kefeng Wang , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Hildenbrand Subject: Re: [PATCH] mm: memory: move mem_cgroup_charge() into alloc_anon_folio() Message-ID: References: <20240116071302.2282230-1-wangkefeng.wang@huawei.com> <2c24afdf-5103-4c1b-a649-2eeed185f3fb@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2c24afdf-5103-4c1b-a649-2eeed185f3fb@arm.com> 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. .. I remain not-an-expert in memcg and anonymous memory and welcome improvements to that text.