From mboxrd@z Thu Jan 1 00:00:00 1970 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 6D55EC07E9D for ; Sat, 24 Sep 2022 12:37:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 959B46B00C7; Sat, 24 Sep 2022 08:37:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E1CC6B00C8; Sat, 24 Sep 2022 08:37:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 782556B00C9; Sat, 24 Sep 2022 08:37:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6B4326B00C7 for ; Sat, 24 Sep 2022 08:37:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 380471A0292 for ; Sat, 24 Sep 2022 12:37:00 +0000 (UTC) X-FDA: 79946928600.03.574C377 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf01.hostedemail.com (Postfix) with ESMTP id 2B07B40021 for ; Sat, 24 Sep 2022 12:36:58 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MZT1l1V82zlWlj; Sat, 24 Sep 2022 20:32:43 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 24 Sep 2022 20:36:53 +0800 Subject: Re: [PATCH v2 4/9] hugetlb: create remove_inode_single_folio to remove single file folio To: Mike Kravetz , , CC: Muchun Song , David Hildenbrand , Sven Schnelle , Michal Hocko , Peter Xu , Naoya Horiguchi , "Aneesh Kumar K . V" , Andrea Arcangeli , "Kirill A . Shutemov" , Davidlohr Bueso , Prakash Sangappa , James Houghton , Mina Almasry , Pasha Tatashin , Axel Rasmussen , Ray Fucillo , Andrew Morton References: <20220914221810.95771-1-mike.kravetz@oracle.com> <20220914221810.95771-5-mike.kravetz@oracle.com> From: Miaohe Lin Message-ID: Date: Sat, 24 Sep 2022 20:36:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220914221810.95771-5-mike.kravetz@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664023019; a=rsa-sha256; cv=none; b=NFI7RTqdVfbQhQepQngkhgAK2Ym1tCjsa0xX3KOoYecEl0zpQYwS8LcwRE111ogyYfBfaH LrYQk70LSHWRUf1YAOJqqzAYtsTFame09HM356PnPdYAE1WLBW64hY8uWFhOYtx4E+u6Zm MAEbOqho/VxO1OGyGhlHcUf17bm0rzs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664023019; 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:in-reply-to:references:references; bh=QSnNqOvZcPJp4sDtPZgsnxes1qJxfqSRJCXJwpkSNkM=; b=lsPzXhe4HeAfWRKLiFP801ajib0FQODfgfo0MJh5mYYC+lsGzzxtxPpmMWIKoVNA2OvvSd 30mMolFW9J9virCe24+pbMdJvha++EDNercJuBqSn1ZGtjT80xFtJnCzih/JHi++nn4qXQ DER1lyujVgSyhuFngjfqpUtO0XDbPmo= Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-Stat-Signature: 9wnik1x7s4i8azxo7irebo9gswnhhfww X-Rspamd-Queue-Id: 2B07B40021 X-Rspamd-Server: rspam09 X-HE-Tag: 1664023018-854504 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: On 2022/9/15 6:18, Mike Kravetz wrote: > Create the new routine remove_inode_single_folio that will remove a > single folio from a file. This is refactored code from > remove_inode_hugepages. It checks for the uncommon case in which the > folio is still mapped and unmaps. > > No functional change. This refactoring will be put to use and expanded > upon in a subsequent patches. > > Signed-off-by: Mike Kravetz LGTM with one nit below. Reviewed-by: Miaohe Lin > --- > fs/hugetlbfs/inode.c | 105 ++++++++++++++++++++++++++----------------- > 1 file changed, 63 insertions(+), 42 deletions(-) > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index edd69cc43ca5..7112a9a9f54d 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -411,6 +411,60 @@ hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end, > } > } > > +/* > + * Called with hugetlb fault mutex held. > + * Returns true if page was actually removed, false otherwise. > + */ > +static bool remove_inode_single_folio(struct hstate *h, struct inode *inode, > + struct address_space *mapping, > + struct folio *folio, pgoff_t index, > + bool truncate_op) > +{ > + bool ret = false; > + > + /* > + * If folio is mapped, it was faulted in after being > + * unmapped in caller. Unmap (again) while holding > + * the fault mutex. The mutex will prevent faults > + * until we finish removing the folio. > + */ > + if (unlikely(folio_mapped(folio))) { > + i_mmap_lock_write(mapping); > + hugetlb_vmdelete_list(&mapping->i_mmap, > + index * pages_per_huge_page(h), > + (index + 1) * pages_per_huge_page(h), > + ZAP_FLAG_DROP_MARKER); > + i_mmap_unlock_write(mapping); > + } > + > + folio_lock(folio); > + /* > + * After locking page, make sure mapping is the same. > + * We could have raced with page fault populate and > + * backout code. Is this needed? remove_inode_single_folio() is called with hugetlb fault mutex held so it can't race with page fault code? Thanks, Miaohe Lin