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 06906C07E9D for ; Sat, 24 Sep 2022 13:11:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 596BA6B00CA; Sat, 24 Sep 2022 09:11:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5464A8E0005; Sat, 24 Sep 2022 09:11:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4346B6B00CC; Sat, 24 Sep 2022 09:11:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 35A4C6B00CA for ; Sat, 24 Sep 2022 09:11:55 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E59DB1608DC for ; Sat, 24 Sep 2022 13:11:54 +0000 (UTC) X-FDA: 79947016548.14.EF72923 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf12.hostedemail.com (Postfix) with ESMTP id EAA0740011 for ; Sat, 24 Sep 2022 13:11:53 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MZTnN6kMRzHtft; Sat, 24 Sep 2022 21:07:04 +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 21:11:48 +0800 Subject: Re: [PATCH v2 6/9] hugetlb: add vma based lock for pmd sharing 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-7-mike.kravetz@oracle.com> From: Miaohe Lin Message-ID: <2b1b6d09-0188-23a3-6ac3-6e81446a10e4@huawei.com> Date: Sat, 24 Sep 2022 21:11:48 +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-7-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: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664025114; a=rsa-sha256; cv=none; b=syzty37EiDKqzo3VF+qNJRX1cZ1lSVCmle0/vTaXkeN+4wyt0FtscC+qRkCr9BxHOv8VjB +ht4XrkSAYPNut9xixdRLi4ubq9bl5KLQvoDzIS7veEecPsk2Vc9NyE0F0IUVlEpWWH2/d eUSrLj9qaSimwVnS1ty3CF3ugWdV310= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 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=1664025114; 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=1k0IiJg0d1IMjgCS46Cjo5e1i7pBfuquqW/QDLVskuY=; b=3nRVuNO9UcGlv0PPIH0za6yl6ZizYDDirlU32OjFlNk28DE50IhWfJIUbEod3hdzc0ndM1 jGA9MhSQ+et+Cdz+xDu/QzKBEXJ/40vb3mk3Avg9DqK1T1rqlMs1ieJIF5hj1ReCg+x0Nu OE10qZL5+bIBSWppNJAh37uNyFcbT74= X-Rspam-User: X-Rspamd-Queue-Id: EAA0740011 X-Rspamd-Server: rspam08 X-Stat-Signature: 9sdft1mo9zgmpsa6z6zddf4tjb18an8g Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-HE-Tag: 1664025113-649762 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: > Allocate a new hugetlb_vma_lock structure and hang off vm_private_data > for synchronization use by vmas that could be involved in pmd sharing. > This data structure contains a rw semaphore that is the primary tool > used for synchronization. > > This new structure is ref counted, so that it can exist when NOT attached > to a vma. This is only helpful in resolving lock ordering issues where > code may need to obtain the vma_lock while there are no guarantees the > vma may go away. By obtaining a ref on the structure, it can be > guaranteed that at least the rw semaphore will not go away. > > Only add infrastructure for the new lock here. Actual use will be added > in subsequent patches. > > Signed-off-by: Mike Kravetz LGTM with some nits below. Thanks for your work, Mike. Reviewed-by: Miaohe Lin > -/* Reset counters to 0 and clear all HPAGE_RESV_* flags */ > -void reset_vma_resv_huge_pages(struct vm_area_struct *vma) > +void hugetlb_dup_vma_private(struct vm_area_struct *vma) > { > VM_BUG_ON_VMA(!is_vm_hugetlb_page(vma), vma); > + /* > + * Clear vm_private_data > + * - For MAP_PRIVATE mappings, this is the reserve map which does > + * not apply to children. Faults generated by the children are > + * not guaranteed to succeed, even if read-only. > + * - For shared mappings this is a per-vma semaphore that may be > + * allocated in a subsequent call to hugetlb_vm_op_open. > + */ > + vma->vm_private_data = (void *)0; > if (!(vma->vm_flags & VM_MAYSHARE)) > - vma->vm_private_data = (void *)0; > + return; This if block can be deleted ? It doesn't do anything here. > } > > /* > +static void hugetlb_vma_lock_free(struct vm_area_struct *vma) > +{ > + /* > + * Only present in sharable vmas. See comment in > + * __unmap_hugepage_range_final about how VM_SHARED could > + * be set without VM_MAYSHARE. As a result, we need to > + * check if either is set in the free path. > + */ > + if (!vma || !(vma->vm_flags & (VM_MAYSHARE | VM_SHARED))) > + return; > + > + if (vma->vm_private_data) { > + struct hugetlb_vma_lock *vma_lock = vma->vm_private_data; > + > + /* > + * vma_lock structure may or not be released, but it may or not be released? Thanks, Miaohe Lin