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 E9018C00144 for ; Sat, 30 Jul 2022 02:15:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 758FB8E0001; Fri, 29 Jul 2022 22:15:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 708636B0072; Fri, 29 Jul 2022 22:15:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CF5D8E0001; Fri, 29 Jul 2022 22:15:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4DD686B0071 for ; Fri, 29 Jul 2022 22:15:38 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EE98FA02C2 for ; Sat, 30 Jul 2022 02:15:37 +0000 (UTC) X-FDA: 79742149914.21.4200F94 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf19.hostedemail.com (Postfix) with ESMTP id 140B11A00C3 for ; Sat, 30 Jul 2022 02:15:36 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Lvntx1n7gzWfQd; Sat, 30 Jul 2022 10:11:37 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) 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.24; Sat, 30 Jul 2022 10:15:17 +0800 Subject: Re: [RFC PATCH v4 7/8] hugetlb: create hugetlb_unmap_file_folio to unmap single file folio To: Mike Kravetz CC: , , Muchun Song , Michal Hocko , Peter Xu , Naoya Horiguchi , David Hildenbrand , "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: <20220706202347.95150-1-mike.kravetz@oracle.com> <20220706202347.95150-8-mike.kravetz@oracle.com> <3557d5a9-231c-4007-3e7e-5a7bf34ecaa8@huawei.com> From: Miaohe Lin Message-ID: <9a4729f6-ca4d-0137-8d15-bbb1221bce52@huawei.com> Date: Sat, 30 Jul 2022 10:15:17 +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: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659147337; 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=zktAYWjm+VKuSwF3j0jxZKOmXaPTP8SRYZvk50wY/8E=; b=vTwXTR0aqLB238ZYt42VwBfpas3luf20uuV4qCFqy6BzB620jBgXgD3y8Q1WKzexGxnjNX ZCG4UiICKxICNZkts0bl6zCvimnOLPOK72mnsla9I6kzupUv/gAtwPM//lA0gf1fXC/3nQ p9AhglRc6Q0+BijFK0WDPMhF2FhNxAY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659147337; a=rsa-sha256; cv=none; b=zBYGDrUbsH+Z7EQNYoaEKmSbWKGnyEqurgvKuA/OTunR7Y0PRjWyStsq7P5TkIDuSsGYOw bpJ+9AlPRIHti1naIAQ3f5GjLwBchl9otrsOMC1pxbqH0CTEMKmUK4oaUDTIjBE3QNsy7u WGdZLae404g8EbhgtF530r58X5Y1QY0= X-Stat-Signature: zz1bk831t9gcd94nzff6i86bfd1uoroc X-Rspamd-Queue-Id: 140B11A00C3 X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam06 X-HE-Tag: 1659147336-818311 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/7/30 2:11, Mike Kravetz wrote: > On 07/29/22 10:02, Miaohe Lin wrote: >> On 2022/7/7 4:23, Mike Kravetz wrote: >>> Create the new routine hugetlb_unmap_file_folio that will unmap a single >>> file folio. This is refactored code from hugetlb_vmdelete_list. It is >>> modified to do locking within the routine itself and check whether the >>> page is mapped within a specific vma before unmapping. >>> >>> This refactoring will be put to use and expanded upon in a subsequent >>> patch adding vma specific locking. >>> >>> Signed-off-by: Mike Kravetz >>> --- >>> fs/hugetlbfs/inode.c | 124 +++++++++++++++++++++++++++++++++---------- >>> 1 file changed, 95 insertions(+), 29 deletions(-) >>> >>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c >>> index 31bd4325fce5..0eac0ea2a245 100644 >>> --- a/fs/hugetlbfs/inode.c >>> +++ b/fs/hugetlbfs/inode.c >>> @@ -396,6 +396,94 @@ static int hugetlbfs_write_end(struct file *file, struct address_space *mapping, >>> return -EINVAL; >>> } >>> >>> +/* >>> + * Called with i_mmap_rwsem held for inode based vma maps. This makes >>> + * sure vma (and vm_mm) will not go away. We also hold the hugetlb fault >>> + * mutex for the page in the mapping. So, we can not race with page being >>> + * faulted into the vma. >>> + */ >>> +static bool hugetlb_vma_maps_page(struct vm_area_struct *vma, >>> + unsigned long addr, struct page *page) >>> +{ >>> + pte_t *ptep, pte; >>> + >>> + ptep = huge_pte_offset(vma->vm_mm, addr, >>> + huge_page_size(hstate_vma(vma))); >>> + >>> + if (!ptep) >>> + return false; >>> + >>> + pte = huge_ptep_get(ptep); >>> + if (huge_pte_none(pte) || !pte_present(pte)) >>> + return false; >>> + >>> + if (pte_page(pte) == page) >>> + return true; >>> + >>> + return false; /* WTH??? */ >> >> I'm sorry but what does WTH means? IIUC, this could happen if pte_page is a COW-ed private page? >> vma_interval_tree_foreach doesn't exclude the private mapping even after cow? > > My apologies, I left that comment in during development and should have removed > it. WTH is an acronym for 'What the Heck?". I added it because I did not > think we should ever get to this return statement. > That's all right. Thanks for your hard work. > I am not sure if your COW of a private page would get us to this return > statement. In any case, if we get there we need to return false. > > Thank you for your analysis and comments! >