From patchwork Mon Feb 5 03:54:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13544955 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 7F0ECC48291 for ; Mon, 5 Feb 2024 03:54:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2DA36B0074; Sun, 4 Feb 2024 22:54:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDDE26B0075; Sun, 4 Feb 2024 22:54:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCC2A6B0078; Sun, 4 Feb 2024 22:54:35 -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 BA65F6B0074 for ; Sun, 4 Feb 2024 22:54:35 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EE618C0372 for ; Mon, 5 Feb 2024 03:54:34 +0000 (UTC) X-FDA: 81756383268.20.3C66ABD Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf13.hostedemail.com (Postfix) with ESMTP id AE9F020010 for ; Mon, 5 Feb 2024 03:54:31 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=NHYvol7b; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707105273; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=vSiJJMfX52mmBCYj2MFQe+6cAYIwJlgaq+HlVSo63jQ=; b=S7x+kYnJ9USHc6yobTak951NhZMyS7Kmn/U6/34/euPtxLqF+4JlTk3ykZ5IbhK+SWCuWP MKXXfC+YUrZv7GKXeWNIa/23NUcjbVtHZm9RhRkrCAmy+/xmDr7zd/GVimVnrQfgXrnP/+ 49ucbQHn0nH/u/7coez8cQ6TZ/yQdbE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707105273; a=rsa-sha256; cv=none; b=gi5WPM5gGD4EvbA1uhXEgaQ27BbHYScxBnLBF54D7Lc6E/8RLtP36jDV7PDzydgCMkLPL0 IdzxCx2JnCcMvn31ZbpX/+MgfyVS2bP0969Pjmzy9o+MNiI/PSepTe1u4DD0nEKTKnJ62y ZzVD7M2vvrmR1bfCNoeefdOCBxQa+M8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=NHYvol7b; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1707105264; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=vSiJJMfX52mmBCYj2MFQe+6cAYIwJlgaq+HlVSo63jQ=; b=NHYvol7bg00zAaCnJPV4ZwVTis7vOVPIuPROeF2sPhy6guUfHJNY1ZzteqyjO+Ww6CpC/pAZCnB9lq6X4vFBV07cgw/cfTpmUm4C4BOPYKuy1CzdwrTVHTHrQd1XVYeJskkMQkqyXC5g90ZCY3wi+v+XMIUKni8xbeVlxGPuHkA= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0W02KW8o_1707105262; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W02KW8o_1707105262) by smtp.aliyun-inc.com; Mon, 05 Feb 2024 11:54:23 +0800 From: Baolin Wang To: akpm@linux-foundation.org, muchun.song@linux.dev Cc: osalvador@suse.de, david@redhat.com, mhocko@kernel.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: hugetlb: fix hugetlb allocation failure when handling freed or in-use hugetlb Date: Mon, 5 Feb 2024 11:54:17 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: AE9F020010 X-Rspam-User: X-Stat-Signature: tkco9cahfcs9abeb7qroprif89m6ppx6 X-Rspamd-Server: rspam03 X-HE-Tag: 1707105271-332135 X-HE-Meta: U2FsdGVkX180Boaotasetf6UMCe2wC1kzY0M9Zd6a5OVOhngfvIMAavJeNB72LRXechPZeysvc617E7/RZlarMhpKvfTmsvMrptJ8fubd7bYmPX/y+aKBneG/xEycd3kKskZ7ijHGKZbSBUstJkYVuExZN1rMmuCqZA0BA3S1e1lw0jeBpMXGGVurb8RpxmYWczhQxUomCmF7mZJdQO1wYvVb+P+jR4UYO8Azz48/G29sJO6qbU6nQPX1+i2aUubtiIRK5Mz9mpj0djBqc4fEhJW8hOD6/QZVi534nuA/EJzL1uYzNYvy3VwkU2eb8KglDfpmNmr+K0yJ9NY1XFeJIn/Le3wmTYkwQQ9YTkftqLU8wsDBc+vgd/iUdy9FbDDxF832mIeHHtg5E1bs6g7D3jnl1qEg08Kse5TTUeKKHw5srWkLYo+kEJxIS14LcM2eyVpXkFQK3Qv6P6qhDB0d3vofra8KIpBo340OqXuCJ5bNvMpdQWJue2Bejv3KdhN8d84n/t2kOyVSyxUPUsP7KjUxW14o/3t8HFN7DTFpn2WynXcvQgAS871hLUarAjdQJC6RxGwDNwUNp7E0IVgCxdlrfKHslQRbGpf9Dckt2neH1zIwRkDZziwCu99v1rdLp0Ss090+c+o4mklH42PhTocgl8wNtvVA/XYeIvV6thSfB6hUp1UG/Bp/4RQhoTrH0Sr2/wKmANJNnDa6VGAlWUMpEiZzT4C3TjCgmoq6kG4JArVxGppXqt9gNvGfUIWBxUQpjaZbFvoz5iejcFJ9ZYyc4yYt+NSLEb8BTT0cJUooBv7GbzQZrHIhS3NabeyjLW9y093jGwOApBFyWrSFp5/UpsJf5u2vIv/kMIDy1aSqeTkqq8S+PaERKhBuwY24QYssu7pwFv9+dPBYwD6dYMIkoPsv+9XOPyRrWqKiPYvlkD8LVEUPo4vV7szJVMc6zq1ZNtcEsarzohrMun kKlUvkag DvP2Edb5/8s4tbr1Kqw/k3QMmzDXuRke1ahDhSiGcm7FXRvRIPLUSCnPiecAnmtffG8g28NTF9XN/VQ3e4FE5Z0tEeIx1hhbgCsOU06+wvqxG1P/WofJKmmnPxMMxYQbQnh1vZmr3xlnH/AJiHnVmIeYmhwTFBqw54Wrv3X/afxv/lwomvXxIGZiW2A== 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: When handling the freed hugetlb or in-use hugetlb, we should ignore the failure of alloc_buddy_hugetlb_folio() to dissolve the old hugetlb successfully, since we did not use the new allocated hugetlb in this 2 cases. Signed-off-by: Baolin Wang Reviewed-by: Muchun Song --- mm/hugetlb.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9d996fe4ecd9..212ab331d355 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3042,9 +3042,8 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, * under the lock. */ new_folio = alloc_buddy_hugetlb_folio(h, gfp_mask, nid, NULL, NULL); - if (!new_folio) - return -ENOMEM; - __prep_new_hugetlb_folio(h, new_folio); + if (new_folio) + __prep_new_hugetlb_folio(h, new_folio); retry: spin_lock_irq(&hugetlb_lock); @@ -3075,6 +3074,11 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, cond_resched(); goto retry; } else { + if (!new_folio) { + ret = -ENOMEM; + goto free_new; + } + /* * Ok, old_folio is still a genuine free hugepage. Remove it from * the freelist and decrease the counters. These will be @@ -3102,9 +3106,11 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, free_new: spin_unlock_irq(&hugetlb_lock); - /* Folio has a zero ref count, but needs a ref to be freed */ - folio_ref_unfreeze(new_folio, 1); - update_and_free_hugetlb_folio(h, new_folio, false); + if (new_folio) { + /* Folio has a zero ref count, but needs a ref to be freed */ + folio_ref_unfreeze(new_folio, 1); + update_and_free_hugetlb_folio(h, new_folio, false); + } return ret; }