From patchwork Tue Feb 14 13:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13140178 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 E84ABC05027 for ; Tue, 14 Feb 2023 13:59:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56C426B0075; Tue, 14 Feb 2023 08:59:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CCD76B007B; Tue, 14 Feb 2023 08:59:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 393BA6B007D; Tue, 14 Feb 2023 08:59:50 -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 21E1D6B007B for ; Tue, 14 Feb 2023 08:59:50 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F3617C0A81 for ; Tue, 14 Feb 2023 13:59:49 +0000 (UTC) X-FDA: 80466055698.02.3A6BAA2 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by imf01.hostedemail.com (Postfix) with ESMTP id E3AB44000A for ; Tue, 14 Feb 2023 13:59:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676383188; a=rsa-sha256; cv=none; b=wMbE7aSAvDXZkBucrRHtlgmtx8qSwWm4LFO6NiO858fspADso9N2h1RgCuRaz4kG1tjdN5 Va1htHrNgdtUuWjlmDHj9mwWKm3IFlsutl0UlqD6YUPbQxDIwqm+Vb1+xgspK/nCRpMlIu fiL1zdbW4qt3KM7ZcaYnyYmLXn+KVno= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676383188; 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:in-reply-to:references:references; bh=tavTW6mS6LWW8vN024hVsoRg4fwkLBzVbpZuJzXonoI=; b=1i8xIX6vLQ39TRjUfhz+AQVPnucEBh/CZ2RAFSnamMtb9T7XZ5omFKjohf47w31rC/k/gg /loSnMJO0zG1yRaZnXW00gXqQu423uTi/Gv/0lKROF1Ii04E8EwzquizHnILsdlSJaIKPp kdUzjPOpuAH7Im0thW3uhRAUI2Sqe4M= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R531e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0VbgLy.7_1676383182; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VbgLy.7_1676383182) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 21:59:43 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, sj@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, naoya.horiguchi@nec.com, linmiaohe@huawei.com, david@redhat.com, osalvador@suse.de, mike.kravetz@oracle.com, willy@infradead.org, baolin.wang@linux.alibaba.com, damon@lists.linux.dev, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] mm: hugetlb: change to return bool for isolate_hugetlb() Date: Tue, 14 Feb 2023 21:59:31 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: E3AB44000A X-Rspamd-Server: rspam01 X-Stat-Signature: odyzzfxj8p9skyg39wzdarxiapknzg5r X-HE-Tag: 1676383187-38362 X-HE-Meta: U2FsdGVkX19dF74LM6dAag2wzRDG/08n3DN8eFwj12HlaY2llJsMh7BjcAwIG0fqYDWgkyUzt/yt32ROuW1C7iu0MyreVOFyCSEVwO7FAH8XkcvIeZYUBhBZt8DxfcwAX2ads1Jy1o9bF9UCBV0jdVNTOMzBplPjznChHKwuRsXsOffP07EBOfFU8VgVHLzlpFdJDYRhJd49aYsRT0/MyZhKT0yvGot3fFAJ1t5X7Y3qxX504Y5p3VY1yMlzkF7el0+USLsvsQl/maGvmbS5uwIyUqmH+9iJyw0gldRegb2rd3CqfzqkNtIxiu0SMG3dOMp8e5QTapYQWSftY3M/q8Z1Or6mq0mbb83EAhDNDTuW8mJGz6rFPNFlU7s9MSR92CAQmkpUo+69wtgYAoIU1XcIDiZDBB3iEpEi4iDPBGw5fLSCVGRsL0vPcpD7LBMdbQUgy6oxcvGIil0D+I5B/y0TcLty9oEUrz9hXbalwk3ErIkJKbDr334Yz9dLxOkuYNwQtSvxCbxTYKNYUSFFibCvTDxRzYQvfrWuBCACNMuCinq5bFxPrpB/f/cetqepeeapCWhDRGAsYE8h/m0YFP02LLgXvGmr913yftjFWvK+w2QD1IPIHVD9V62K8uPLobTLEFOLXXWguLDzgz6JXN0Q7HSNzI39IVQ3yo/30CkCCRpOQcSRcnOH7bLpTf17c0JwH8lkCtUjB0ySv/+T0fAeHVqRQU4GeI3egtZyoOuRtnH7A8DTpoExMStz/X+SVRWaoBLriHtyX1sfFYDYBusOQqMszL97QlOXRcR0A8Sl2HSBbi5o6LPfcEvGj85Cm30F58J/S0BDuenH1hr/kzTTZbdb7SFFfEx0mPFJq+A1xrW+Ryrnf5tYIycK+LwfbOKDp0qlwEWIfz4ZUZcw/leWh3C/N9md55XLn3CumbgB8h0YIsb6KYGyE1cxJDm8kaG1WPudvubjWiLtoTa H/oqrbJV oeGzpW/DyPy/r6XmccijqfXg3NB25caedyA9lVMLbL6U4Gaa+zVXojeiVAdeAliHonlEDcmimSK9o7GVhFQoteocOWiOEY/xWpOPgzY3X4kUysN19E1y4jqAT0glTDDcDnARa3ukI0fLsPZtEXOzoeFecxBR7KNFIRMZ739+JizyE+DTQn1MUCCTlz4DAGhSHa1HpeSN0+PYjJh7lwO8SVbZTDWjXFQxWgMOd9eZaDxB5RF4VBXUktdaP+nx3m9nGsqMV 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: Now the isolate_hugetlb() only returns 0 or -EBUSY, and most users did not care about the negative value, thus we can convert the isolate_hugetlb() to return a boolean value to make code more clear when checking the hugetlb isolation state. Moreover converts 2 users which will consider the negative value returned by isolate_hugetlb(). No functional changes intended. Signed-off-by: Baolin Wang --- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 12 ++++++++---- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index df6dd624ccfe..5f5e4177b2e0 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -171,7 +171,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, vm_flags_t vm_flags); long hugetlb_unreserve_pages(struct inode *inode, long start, long end, long freed); -int isolate_hugetlb(struct folio *folio, struct list_head *list); +bool isolate_hugetlb(struct folio *folio, struct list_head *list); int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison); int get_huge_page_for_hwpoison(unsigned long pfn, int flags, bool *migratable_cleared); @@ -413,9 +413,9 @@ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, return NULL; } -static inline int isolate_hugetlb(struct folio *folio, struct list_head *list) +static inline bool isolate_hugetlb(struct folio *folio, struct list_head *list) { - return -EBUSY; + return false; } static inline int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3a01a9dbf445..75097e3abc18 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2932,6 +2932,10 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, spin_unlock_irq(&hugetlb_lock); ret = isolate_hugetlb(old_folio, list); spin_lock_irq(&hugetlb_lock); + if (!ret) + ret = -EBUSY; + else + ret = 0; goto free_new; } else if (!folio_test_hugetlb_freed(old_folio)) { /* @@ -3005,7 +3009,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list) if (hstate_is_gigantic(h)) return -ENOMEM; - if (folio_ref_count(folio) && !isolate_hugetlb(folio, list)) + if (folio_ref_count(folio) && isolate_hugetlb(folio, list)) ret = 0; else if (!folio_ref_count(folio)) ret = alloc_and_dissolve_hugetlb_folio(h, folio, list); @@ -7251,15 +7255,15 @@ __weak unsigned long hugetlb_mask_last_page(struct hstate *h) * These functions are overwritable if your architecture needs its own * behavior. */ -int isolate_hugetlb(struct folio *folio, struct list_head *list) +bool isolate_hugetlb(struct folio *folio, struct list_head *list) { - int ret = 0; + bool ret = true; spin_lock_irq(&hugetlb_lock); if (!folio_test_hugetlb(folio) || !folio_test_hugetlb_migratable(folio) || !folio_try_get(folio)) { - ret = -EBUSY; + ret = false; goto unlock; } folio_clear_hugetlb_migratable(folio); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index e504362fdb23..8604753bc644 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2508,7 +2508,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist) bool isolated = false; if (PageHuge(page)) { - isolated = !isolate_hugetlb(page_folio(page), pagelist); + isolated = isolate_hugetlb(page_folio(page), pagelist); } else { bool lru = !__PageMovable(page); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 2751bc3310fd..a256a241fd1d 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -609,7 +609,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask, if (flags & (MPOL_MF_MOVE_ALL) || (flags & MPOL_MF_MOVE && folio_estimated_sharers(folio) == 1 && !hugetlb_pmd_shared(pte))) { - if (isolate_hugetlb(folio, qp->pagelist) && + if (!isolate_hugetlb(folio, qp->pagelist) && (flags & MPOL_MF_STRICT)) /* * Failed to isolate folio but allow migrating pages diff --git a/mm/migrate.c b/mm/migrate.c index 53010a142e7f..c5136fa48638 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2128,7 +2128,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, if (PageHead(page)) { err = isolate_hugetlb(page_folio(page), pagelist); if (!err) - err = 1; + err = -EBUSY; } } else { struct page *head;