From patchwork Tue Feb 21 21:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13148436 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 67FFBC61DA3 for ; Tue, 21 Feb 2023 21:43:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE34B6B0075; Tue, 21 Feb 2023 16:43:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6C486B007B; Tue, 21 Feb 2023 16:43:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBFB26B007D; Tue, 21 Feb 2023 16:43:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A36C46B0075 for ; Tue, 21 Feb 2023 16:43:52 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 73E101A03E0 for ; Tue, 21 Feb 2023 21:43:52 +0000 (UTC) X-FDA: 80492626704.07.5C54194 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 781562001C for ; Tue, 21 Feb 2023 21:43:49 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CM9VGb62; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677015829; 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: references:dkim-signature; bh=34+UtMogjW73Ol6iiDYppo7y7ytBwPtcRfcoT5tMa8w=; b=r4TdcJnTyyt1A/G9i/Os98kO7J/r5v4uQEKbDNmNJ0zQ9+HnGRadKQWkkxcFGOL/gY8fq9 BLkl09h8pEolYl81dz0NKj5/LjQDOfYhuEhcrXaiPc7EwmFIMWZ69CEfLF6CJDDbX3DmrW QFXtFUX5F3rj5jLv/uLOrZlUwkwUfbM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CM9VGb62; spf=pass (imf03.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677015829; a=rsa-sha256; cv=none; b=LrZ1pboYTKiJEA4C8MiYu0ON5yUZCboMxemLyUF80V0I/jWsNca6x4e8VMZUzCINDb/8rl IbfbzfPwiNS+lcNRHWwin214xhpJdwde1bsONV2SHcuw/b0UeS8tthqpxMERcnSGG4aVwo MGKNihDDtodmDNaqogFygzzHW5WqWJA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677015828; h=from:from: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; bh=34+UtMogjW73Ol6iiDYppo7y7ytBwPtcRfcoT5tMa8w=; b=CM9VGb62Pg5ey4U/Tg7qNJyWqOm+gMOC/ZDTrTqtXgiPMN82khaaqgZZf1D9oCqu4iMK1c kNh3l2s3q7EkeTVsi+LjDZs64RjsmqSX8aG+6iuSd/tmtttXJP9ZvnDx2Jta6ULQt+uCvt n4oGYaeclFHiMh5S3yuFUUF9fRMB9Fo= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-496-x8iHGbHUPnONWqjVghIX0Q-1; Tue, 21 Feb 2023 16:43:47 -0500 X-MC-Unique: x8iHGbHUPnONWqjVghIX0Q-1 Received: by mail-qk1-f198.google.com with SMTP id b1-20020a05620a126100b0073b2dc0e161so2576949qkl.12 for ; Tue, 21 Feb 2023 13:43:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=34+UtMogjW73Ol6iiDYppo7y7ytBwPtcRfcoT5tMa8w=; b=lj3FdVktjPV6J4C86rl/o0ooONnu2Yoz2jpnIUgGKi9E/OEFghy5HXARUyTBkCklYg uGZRq7ADGmvi5Ptu4b+fCeNQqp9/nPqgmeoBQ1RCiwK9Su64YRBpKOxLzKqnXryGLyjp 5AdTDLZX1mIlppmYeERExecI9zF8Shba2O+dCTgO4LsdL6DX382eMfDwHeSgTq0fCQyS E4V0Mv0RVVgiPFRAyjRcoDXDeKXssvW5bvUXe0EDlmk40tL3VIUMasr7nGwlNvKmSQre mieA0fvxZyyR5pfowcKXjXBAm9iEW9Ld6b7+m4aRKiH/z0M7RRlX3zD5uG/S8vqs+n75 MjKA== X-Gm-Message-State: AO0yUKVt7aZH0WNDl93ru2L8hgBvLKsw2lCHcmicZRU30KVocpuUwixj Po5xvFwi0gBBsI3+T8Ocs4VVw95P8pO9/2Ew7qlBO34Yc8B+7D3UsPTklS+luUHECVPl3SGCok1 rHtHjjoKAfuE= X-Received: by 2002:a05:622a:1002:b0:3b8:5199:f841 with SMTP id d2-20020a05622a100200b003b85199f841mr11179947qte.0.1677015827127; Tue, 21 Feb 2023 13:43:47 -0800 (PST) X-Google-Smtp-Source: AK7set9TjAz8/InPJTdc2s1mAVbPGVdOmao8Z1FprSX/1ePcDq6rM6cu8qZFayZuieS9/eTg0PTxfg== X-Received: by 2002:a05:622a:1002:b0:3b8:5199:f841 with SMTP id d2-20020a05622a100200b003b85199f841mr11179923qte.0.1677015826887; Tue, 21 Feb 2023 13:43:46 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-56-70-30-145-63.dsl.bell.ca. [70.30.145.63]) by smtp.gmail.com with ESMTPSA id t144-20020a37aa96000000b0073b79edf46csm8989100qke.83.2023.02.21.13.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 13:43:46 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , peterx@redhat.com, Johannes Weiner , Yang Shi , David Stevens , stable@vger.kernel.org Subject: [PATCH] mm/khugepaged: alloc_charge_hpage() take care of mem charge errors Date: Tue, 21 Feb 2023 16:43:44 -0500 Message-Id: <20230221214344.609226-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 781562001C X-Stat-Signature: 111zwrzuwbt3a5gmqwxqr1neokjn1r8b X-Rspam-User: X-HE-Tag: 1677015829-250992 X-HE-Meta: U2FsdGVkX19uQ20YjqObZGn1h3Lp+VcHQAEfozTxQPfgmBmHkVDn+oK+WkNfF3T8hIWFGgKGgh2dCVoKIS1Go8F5MhHMGHNVjQ7zgF20j2bl/JBWw6E6LDqczlD7W/CmZtvxHYwU5hc8bOIovN7xLfCpGGejebDky4+kll2stVOUOoKxMJr/PI1bRF32dJ4agW6rL4vdbphba8HmadpAEu/GWQk6CMjPDeeTNsdO/q1AFqiYE4c7gcIGg+sfJG2BM4Wd1GGgRPuZZ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iPoqffyEkxAi4ZdICL+5s3+zfBTt7genFngP2nfphS4/KY4WTW/hMsDo/PG56sjtFTN+JL6n1Y8fMYFm3wj5JI1wUy2YihtMv+Z2U2rGe137UNk+dtTe+rF8FJ+uazzaU9drTyuk/sM5xBuksTwDLBFTCgh1ohKFO2jDKEiCRSxoo7GLKJNzv6udOYU6jxT/EKpiR2LA77E1+p7lx6Sl6EsyaUx+tc4qkM/iy2NAGza9kLhsuVlkp7/MjiaIVGgUtqtbkJxqLkft4WRRUbS9nKj/mS0pmN/WXKZPOZ2hZRLf7moQeybMj3XyLLtfbx03M= 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: If memory charge failed, the caller shouldn't call mem_cgroup_uncharge(). Let alloc_charge_hpage() handle the error itself and clear hpage properly if mem charge fails. Cc: Johannes Weiner Cc: Yang Shi Cc: David Stevens Cc: stable@vger.kernel.org Fixes: 9d82c69438d0 ("mm: memcontrol: convert anon and file-thp to new mem_cgroup_charge() API") Signed-off-by: Peter Xu Reviewed-by: David Stevens Acked-by: Johannes Weiner --- mm/khugepaged.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 8dbc39896811..941d1c7ea910 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1063,12 +1063,19 @@ static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm, gfp_t gfp = (cc->is_khugepaged ? alloc_hugepage_khugepaged_gfpmask() : GFP_TRANSHUGE); int node = hpage_collapse_find_target_node(cc); + struct folio *folio; if (!hpage_collapse_alloc_page(hpage, gfp, node, &cc->alloc_nmask)) return SCAN_ALLOC_HUGE_PAGE_FAIL; - if (unlikely(mem_cgroup_charge(page_folio(*hpage), mm, gfp))) + + folio = page_folio(*hpage); + if (unlikely(mem_cgroup_charge(folio, mm, gfp))) { + folio_put(folio); + *hpage = NULL; return SCAN_CGROUP_CHARGE_FAIL; + } count_memcg_page_event(*hpage, THP_COLLAPSE_ALLOC); + return SCAN_SUCCEED; }