From patchwork Wed Feb 15 10:39:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13141510 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 4D117C64EC7 for ; Wed, 15 Feb 2023 10:39:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC6A36B0078; Wed, 15 Feb 2023 05:39:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E77446B007B; Wed, 15 Feb 2023 05:39:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA1B26B007D; Wed, 15 Feb 2023 05:39:56 -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 BC5686B0078 for ; Wed, 15 Feb 2023 05:39:56 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8B6E2C0542 for ; Wed, 15 Feb 2023 10:39:56 +0000 (UTC) X-FDA: 80469180792.22.B6BA0CB Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf29.hostedemail.com (Postfix) with ESMTP id BBBEE120012 for ; Wed, 15 Feb 2023 10:39:52 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 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=1676457593; a=rsa-sha256; cv=none; b=MejWmwcEE0nnEdR40/qGS22Onzezt382E39EGCEbp80Qc+RLvh5Q8dJxmiQXlcIF+2cIKX xbjCUhh2MTh2Yx/gTnNM97O4ssWfYgLe8i8jl+Ofq3t53+WQTBMQiOr+1EOKBrW6LHpuw0 xewvjFgpX9ehcKabPUBmma+cieUkktA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 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=1676457593; 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=H1sG5taYyZ/A/W6aoOcRboqx/jTVS57pdG5LJ508OIE=; b=1zMmFKcRjmu08h0II9JtMpfspf2N9jDjeXEo5oGhUb16bomkn/7S8DxuXQCg1baUFOrRGc /e2D5lvQw8HqUGUy3pbStKn0xbfDWLPC2OSsS2WDkz6dc1bhUzv/NpnGTZ+z7MItbattoT 6LWxN0uEVWpjP+RH24R1zXwx3qR+uq4= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0Vbk1biH_1676457587; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vbk1biH_1676457587) by smtp.aliyun-inc.com; Wed, 15 Feb 2023 18:39:48 +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 v3 3/4] mm: hugetlb: change to return bool for isolate_hugetlb() Date: Wed, 15 Feb 2023 18:39:36 +0800 Message-Id: <12a287c5bebc13df304387087bbecc6421510849.1676424378.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: BBBEE120012 X-Rspamd-Server: rspam01 X-Stat-Signature: m9hcw9ajo9c5nshsxdq4bcekryaigunf X-HE-Tag: 1676457592-140529 X-HE-Meta: U2FsdGVkX19SUOm0gTOVvGrd7ne9cLq/IJ5gjF9CkfTswsMfOXpL+p4YNxq+d6ydKS/kxHA2E8lx3oKyNDs6w11+41+9lZsJyGLMEySeOsfCAk0+NPJxNYVQ7ajaC/Ibp2BZDi6gFRGiytmalN70fBfyOoTWbrb0tToMIZkA2Yo/wLrxL9ES1KYlHIrj8YBBivXRmfet8eJD6FgOOMDFSz5YVZE/UM+kAL/CgxebZpbAZ3Jk1R3z816PT8uOwxT5kPEBM9AtO1Td6tKBaopZiD+l4WQwjVQNr3ZQ7QSTlxRxwtzcB6qDrWHtRNm0taUDdV9ehSnIQq1RejVFoIt8jdmn8fP2KoHPGDp0yedAt4yTMrVcxLulfXhHW4L/SHFZCnHQ40v1DezGA1+t9K9YkSpTc3OA292MLf5h6RaVdTkgEPIPjObovvfEoF+8IHp5Iyh0SGtXPJ4tu5PHFuQFj1Sp5mpwFxJTwaB496QymRRVJprVS7KOVCYi6caIWXOa6U5PHXgS6QKR2FznkmmgzcvYD/1r4BsRteUI8Pe8vRagDVuUaAHfsdOJoFPI7y0M0CahOESjLwVPKuXzwx6n1mJls4a2RNJM6eEGz8L4s+fbIAX+lDnwO23D5C7vXzW6l6o9Dsw+INHkbUs1tdOFj/xArkR7HnH//m0nKSSpnyIx0ptC159dIK29EvnpP/B0b348hPxVjCbMWrkx235ZAIYRByrns815MuNuLVtJFMK9A7yOjoEiQOhLYAXeNF9GkXbZJW2DECmHCj8G83vZqV445sojkBuh6CF5E9ppzTIPLc8gTrv55elKRhqUM0rEmcaC/8tDsvioHhZXQM9tCu1krNNH4/Ws9JKEx2v0G72G/YPl81lZdkJzqb7Z/vu1LvWO0EfYvFiG+mFCF45hnlkq8eMd3s6PJtqbXXQhDXRLdFtpIhhcV0uvr0admfQwtCLJRWtCzyHgWrRNNdw dOxV0hit o4GkmrMYcsmZRNtDxCtlkE817qM8ff+Iv1W5rdUMa1o36KRnDILdVYiwZInoODf3xXu3eJrR/jMlC0u8gjkIR7dsKoBdi3fR7xGFl6Hym2T0k3n+6TMhVXoKS/vSapbHFFNqvAoi1G5qajKs4yhobuj3AR2hERuwI1oyTKiq4dGq1YZeZAALrfP0HJMgEdKklnwMF 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 Acked-by: David Hildenbrand Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Mike Kravetz --- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 13 ++++++++----- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 7 +++---- 5 files changed, 16 insertions(+), 14 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..16513cd23d5d 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2925,13 +2925,16 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, */ goto free_new; } else if (folio_ref_count(old_folio)) { + bool isolated; + /* * Someone has grabbed the folio, try to isolate it here. * Fail with -EBUSY if not possible. */ spin_unlock_irq(&hugetlb_lock); - ret = isolate_hugetlb(old_folio, list); + isolated = isolate_hugetlb(old_folio, list); spin_lock_irq(&hugetlb_lock); + ret = isolated ? 0 : -EBUSY; goto free_new; } else if (!folio_test_hugetlb_freed(old_folio)) { /* @@ -3005,7 +3008,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 +7254,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..2db546a0618c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2095,6 +2095,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, struct vm_area_struct *vma; struct page *page; int err; + bool isolated; mmap_read_lock(mm); err = -EFAULT; @@ -2126,13 +2127,11 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, if (PageHuge(page)) { if (PageHead(page)) { - err = isolate_hugetlb(page_folio(page), pagelist); - if (!err) - err = 1; + isolated = isolate_hugetlb(page_folio(page), pagelist); + err = isolated ? 1 : -EBUSY; } } else { struct page *head; - bool isolated; head = compound_head(page); isolated = isolate_lru_page(head);