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 4814EC4707B for ; Thu, 18 Jan 2024 15:59:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C66716B0085; Thu, 18 Jan 2024 10:59:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C23F56B0087; Thu, 18 Jan 2024 10:59:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADF616B0088; Thu, 18 Jan 2024 10:59:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9D8306B0085 for ; Thu, 18 Jan 2024 10:59:32 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6B98D1402A7 for ; Thu, 18 Jan 2024 15:59:32 +0000 (UTC) X-FDA: 81692891784.20.F76AF4C Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf30.hostedemail.com (Postfix) with ESMTP id 53B4780024 for ; Thu, 18 Jan 2024 15:59:29 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=SWDlR3Ix; dkim=pass header.d=suse.com header.s=susede1 header.b=SWDlR3Ix; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf30.hostedemail.com: domain of mhocko@suse.com designates 195.135.223.131 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705593569; a=rsa-sha256; cv=none; b=v1Z+KpHjAb06/AYe43ikcm2YE2Bev8I5IcxAxyaBpLyfQZbNHMpiYZYwc8bVr7iJJjnaTP tLB7PoSbOmzaPRRrYHhjFurlh6sRBmxFHPhPLv8JOIkh4ywa6l8q1AvA4bDJVOiMAUoyw+ 9NLGRrn4+1/jTgQGzFynpE4y7mmcjjY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=SWDlR3Ix; dkim=pass header.d=suse.com header.s=susede1 header.b=SWDlR3Ix; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf30.hostedemail.com: domain of mhocko@suse.com designates 195.135.223.131 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705593569; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FL1eaVL1w8UaNCASvpod4Ss19US2yAmpTSN74Ny5W+M=; b=He6q/OsSeomwHtTWvx15e87q8lVOQ+Sf0KIYJeuXTdhTLBISpDlcf0+2hf+Sa8/OzA1qd8 Lcm8+DypMxr6ROFIIa7QIiNESGc4e6GlMtz5hlcZ4ywq7AcHTCWGWR5UxMkHUeJnnMZ/Zj zX511eLS3lbn/fiU2jdKK74MHNb0Krw= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 897801F78C; Thu, 18 Jan 2024 15:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1705593567; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FL1eaVL1w8UaNCASvpod4Ss19US2yAmpTSN74Ny5W+M=; b=SWDlR3IxAI/6JPFUk/Lb+u+Z3y7881rmXAJv+4Q0Mc8Gc5pMNFjLztkCdz8ifk5VZ6zSZe 68VizPMymw2RW/BKU/BMeYGq2vtJVFi+5EiQ+4uuVjuzZNgt8a7asVt6YmgZXmsSqhFciQ CmaICoSY85/ERTJ+KtTkG2+3NxwJRk4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1705593567; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FL1eaVL1w8UaNCASvpod4Ss19US2yAmpTSN74Ny5W+M=; b=SWDlR3IxAI/6JPFUk/Lb+u+Z3y7881rmXAJv+4Q0Mc8Gc5pMNFjLztkCdz8ifk5VZ6zSZe 68VizPMymw2RW/BKU/BMeYGq2vtJVFi+5EiQ+4uuVjuzZNgt8a7asVt6YmgZXmsSqhFciQ CmaICoSY85/ERTJ+KtTkG2+3NxwJRk4= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7346713874; Thu, 18 Jan 2024 15:59:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id a2YpGd9KqWXSOQAAD6G6ig (envelope-from ); Thu, 18 Jan 2024 15:59:27 +0000 Date: Thu, 18 Jan 2024 16:59:26 +0100 From: Michal Hocko To: Kefeng Wang Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, Matthew Wilcox , David Hildenbrand Subject: Re: [PATCH v2] mm: memory: move mem_cgroup_charge() into alloc_anon_folio() Message-ID: References: <20240117103954.2756050-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240117103954.2756050-1-wangkefeng.wang@huawei.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 53B4780024 X-Stat-Signature: u1h6qfd1eym4n4jwdqhqpqinxx6amceu X-HE-Tag: 1705593569-759920 X-HE-Meta: U2FsdGVkX1/ge1pRtkmdeLwidiSZZ54uEv7WuPABZfjECIAUzH5I+hNj5Z/ru2Xh5HNtrooOasRkvLUdp8O1BW8VUjis/s296pyjhKdD+82Zk/4Wr9Swh/Xu3E6oGT9wuAXdTJ/Y9pmdAEoWWEaWhtmXB7mQifDC5MtaaR1eic+RNYHcCf0BpMCPxdWNKV3M9qT7NMXPhIVx4TIKKZ7ifMOXUEZ8P7nkj5RE+FFDTAOhq8aYZk2Aab3lfHvgNm6Z1K0KFuBgE2tNKJ+E4LGPsraQuYwJxrlhYS2Cp/7sNUaR7UPPyD+XTpK1mzZEmnMvh1jP18ZvxVXZ8j9m8qVVtWmPC1GALrgBSm5VZVpuCyndRBTamJ2bpz9qh8PC+Y7gUImmpfpYGi45uYVoiYicF84LRbjQ6NMxZI79fXK0Ygye8Agq0LEZjZBk9cCMhyrDtFL6vlTFj8C96Leq0eAPoise/vyIrBmhBRfqBWwXE/Sq1BlCZ7cV/uuN5Rq1jxVBCk4l6czRX2SKs0vXDBROpM//l3W0LR5XucE36lsHqnlCq1n7c38Jy4fpx48l4cvzDXo8kq+8bPNxLa/cr8082ohntpjwBZOdbqb4btvBmGFF37e/0/Y6CY1tbXkTEycS5DSt0iwbEUkSp0GNPn1f1GhTFrDujxz/+2WUawwot6IdQkAE2seNw1CWH2hdjf4XuD4rd6UNVJAOftRndtAX74SPXjvxUNLOImazNZ+Obefyhz2a7rbPWB2r8lFYHmY2jsOWJIwMKTZeGvwixnFowG7qOQiZ8fqoIVsAX//myCDUhg8ECIgA6uHHa6HPwQsrrR8K3P11li05yALU2j19dHtz5L7fQRvqtQsNXl+F/QldUPBtzFselzB0+/MhiE4j0Rov+nn1GrTImvi5hYXKo1monM3iBMl45to91yb4x8OZJohHltgmI+jaI2z3kbWxqC1TGlzoZEFX8g7Ym5Q hjrDVyGs 96pooFhTR/wdJ9lSGzIU7yEQ1cArGNqiMdqvRscMI8juJFjfUugj7Xcm547d+3q1Eo6IVD3ViwHVe/jtgV9DbKDypyKAzGGhjlmA+whzvgGWBQI4Gkik/qhdg/kFO6k4wwUxzbuB2mPalWULSlcN64tyq5F2x3V4glxztPfep9hrJoA3hMtpTDEAooL16KBYJlHYEEd4PhS0Wquz8Hz/0djbogD03jzvOUtUFdE7QCMByVpb7LkuizoRcAu3DXC8U/ejo7Qw2JsD7FJzboeP+iIataLZ1V3F48TXV 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 17-01-24 18:39:54, Kefeng Wang wrote: > 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. The changelog is not really clear in the actual problem you are trying to fix. Is this pure consistency fix or have you actually seen any misbehavior. From the patch I suspect you are interested in THPs much more than regular order-0 pages because those are GFP_KERNEL like when it comes to charging. THPs have a variety of options on how aggressive the allocation should try. From that perspective NORETRY and RETRY_MAYFAIL are not all that interesting because costly allocations (which THPs are) already do imply MAYFAIL and NORETRY. GFP_TRANSHUGE_LIGHT is more interesting though because those do not dive into the direct reclaim at all. With the current code they will reclaim charges to free up the space for the allocated THP page and that defeats the light mode. I have a vague recollection of preparing a patch to address that in the past. Let me have a look at the current code... ... So yes, we still do THP charging the way I remember (do_huge_pmd_anonymous_page). Your patch touches handle_pte_fault -> do_anonymous_page path which is not THP AFAICS. Or am I missing something? > Signed-off-by: Kefeng Wang > --- > v2: > - fix built when !CONFIG_TRANSPARENT_HUGEPAGE > - update changelog suggested by Matthew Wilcox > > mm/memory.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 5e88d5379127..551f0b21bc42 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4153,8 +4153,8 @@ static bool pte_range_none(pte_t *pte, int nr_pages) > > static struct folio *alloc_anon_folio(struct vm_fault *vmf) > { > -#ifdef CONFIG_TRANSPARENT_HUGEPAGE > struct vm_area_struct *vma = vmf->vma; > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > unsigned long orders; > struct folio *folio; > unsigned long addr; > @@ -4206,15 +4206,21 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf) > addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << order); > folio = vma_alloc_folio(gfp, order, vma, addr, true); > if (folio) { > + if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) { > + folio_put(folio); > + goto next; > + } > + folio_throttle_swaprate(folio, gfp); > clear_huge_page(&folio->page, vmf->address, 1 << order); > return folio; > } > +next: > order = next_order(&orders, order); > } > > fallback: > #endif > - return vma_alloc_zeroed_movable_folio(vmf->vma, vmf->address); > + return folio_prealloc(vma->vm_mm, vma, vmf->address, true); > } > > /* > @@ -4281,10 +4287,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > nr_pages = folio_nr_pages(folio); > addr = ALIGN_DOWN(vmf->address, nr_pages * PAGE_SIZE); > > - if (mem_cgroup_charge(folio, vma->vm_mm, GFP_KERNEL)) > - goto oom_free_page; > - folio_throttle_swaprate(folio, GFP_KERNEL); > - > /* > * The memory barrier inside __folio_mark_uptodate makes sure that > * preceding stores to the page contents become visible before > @@ -4338,8 +4340,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > release: > folio_put(folio); > goto unlock; > -oom_free_page: > - folio_put(folio); > oom: > return VM_FAULT_OOM; > } > -- > 2.27.0 > -- Michal Hocko SUSE Labs