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: 60270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp237603wrd; Tue, 21 Feb 2023 13:47:26 -0800 (PST) X-Google-Smtp-Source: AK7set9OValpDddT5Fpjylfl3/f2bUrX9xgB4AgCEIyw6RQogdteX4fgolTBFBNB/Bo4uMQJeRBc X-Received: by 2002:a17:903:11d0:b0:198:f8e2:2e33 with SMTP id q16-20020a17090311d000b00198f8e22e33mr9124064plh.30.1677016045950; Tue, 21 Feb 2023 13:47:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677016045; cv=none; d=google.com; s=arc-20160816; b=086pvvZWHY/EL6KN2c7YNJFDatSMoEZ8swsZIuyrXkYW+h+tr3sf1B5OjScdl9AvQc 3hpna4my3qWsQalRYudUuwpmb5+s4Ca5/EOKtRqEMUlFW8gNL6oDcnrHZygxQXLtRxT9 u0xJRGKQMrS/gB6osSa6DQCpx2g9j+0jRwUpig4/SKIS4VrMCy1hKp8Zaurew0XZjxDV 7xs0i/ofVcFhRziu+F3SOuF/3hTYj6SIKiu8wCLcxOoqyZ1zXZFT1pBLKiyu7pvWwOPX 6SregKopUMM8+3DNX31SE9sR85jKo4kJbvPBZI7Jzo1G7sOtztEXcpi6IswhM3wykb1H tx9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=34+UtMogjW73Ol6iiDYppo7y7ytBwPtcRfcoT5tMa8w=; b=IYe67mb6t6oCophiIuzzVqz+snLrqVlmnqtOqRIL12637xp8cEg2ZkQo8YXV5C/Dco UahoVsteiE/wzza4qewj8grdX4GvnLJ/xPi6d8MeJyTcnvbXEEAEwAnswqzndVWZZvVf 29rydt6kRiq1TgLjnbLKnIeVcvwkiUeSaNJlcpdBF3KMPzi4w10UXiOXGfHRM+hqAs5M K3kw5YPUSLcPzdhE0VvgWM5IbDsXtDPIoxCooGpT7YlNExcK9rCzE//YhYaKdneOJDTF MsouJqjhybqW6GTCpcEv2gu+0xyVp5jZ0RkeCiz3w/IVNsvsh6t0ERfXDCdnrOsfFwb/ uQWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GzvKwmL+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a170902db0f00b0019911aa50e7si7870162plx.368.2023.02.21.13.47.13; Tue, 21 Feb 2023 13:47:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GzvKwmL+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230052AbjBUVoh (ORCPT + 99 others); Tue, 21 Feb 2023 16:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbjBUVof (ORCPT ); Tue, 21 Feb 2023 16:44:35 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 172CF2DE40 for ; Tue, 21 Feb 2023 13:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677015829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=34+UtMogjW73Ol6iiDYppo7y7ytBwPtcRfcoT5tMa8w=; b=GzvKwmL+DeVQONq5fJVvo75zVv3VM1ACnsHDBLGHUYElFbxQ8nTg3/WyAWf2V2vMvFyXCV ZFLBpRnuGWRYHPq7z98vK/FHFQnVpWDRliZqpa3h0iQWZcJqcTEosOfpdYXKbJHCxNUe60 EQlBQAFb3yVTPzOm2HamwQV5NO5sxkU= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-224-HnjvKXN6OBKH5wPZsZIi6w-1; Tue, 21 Feb 2023 16:43:48 -0500 X-MC-Unique: HnjvKXN6OBKH5wPZsZIi6w-1 Received: by mail-qt1-f198.google.com with SMTP id z1-20020ac87ca1000000b003ba2a2c50f9so2412449qtv.23 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=Eu5kCl2qzB/1a1yOJv6vGpQSw9aS0GNIgY5/yrA8QpGLuauKy+f0CDadg+LN4SIVo9 kwmt4ClmmmCUMW6z0wdKmEMt7BmVgdeBKagAWm2obsKuK+j4qE0I2xqB4KXSPZsGSGVD cEIxQ7Uw46pvYPajbXeZrmdAziswhimk8oiVHy3+WvgnySdHom+S95sy8Tu2CIUASbBD 4AeXqCYKgEWLg09YIvVIW8guHJp3dQ4SNQJLNgWVwlhawWMr4YEi1hJUAp9E5tZ5UHCR BeaSBc1+s+AxwpKGaAKkwhyen8jZjoRMOacL98XOAjybKYeAd470GIOs0TLc7H0TXlFv 4vpg== X-Gm-Message-State: AO0yUKX2wSsRTu+bjJr0yF078tho5zllaiVL9AVoKKL/EOvW+ymvP1An XcP3lj4jqE6W20uzeBzB51sOeNE++tuJyoGum7IC39yU/40I7NiXffidkRDTTA/6mWqDYNdnUKC VTrAB5UlGEwqr37SMj6Cdvwdw5eGsw7BLQzYPYfcT88Z+1MEcG6knAPIlBK09M5ztRVEUH2oQHe rjKrQ= X-Received: by 2002:a05:622a:1002:b0:3b8:5199:f841 with SMTP id d2-20020a05622a100200b003b85199f841mr11179955qte.0.1677015827173; Tue, 21 Feb 2023 13:43:47 -0800 (PST) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758478777156567325?= X-GMAIL-MSGID: =?utf-8?q?1758478777156567325?= 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; }