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 96563C433FE for ; Wed, 2 Nov 2022 19:24:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01D868E0002; Wed, 2 Nov 2022 15:24:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0FEC8E0001; Wed, 2 Nov 2022 15:24:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7798E0002; Wed, 2 Nov 2022 15:24:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CEC4B8E0001 for ; Wed, 2 Nov 2022 15:24:12 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9173D1408B0 for ; Wed, 2 Nov 2022 19:24:12 +0000 (UTC) X-FDA: 80089477944.24.8AB3A5C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 1C83E18000B for ; Wed, 2 Nov 2022 19:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667417051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OnGbVU+pdLQrWU/4yKB9jRj3Qh2itknh7OkU6ci+FdA=; b=D7W6KrNrM4sEg9ABKIQMsC0ix3ENvXDr5t+qhhxJTaDhZNhNayCePvLYs8aFiGcuKvrvxh 7Zf5CmiMQw5sxK9IvfFm7KHUnf0udztLKCSLiPfERkfPPZL1t4vvXGX0tAivpSJ0lD1FpH GphqRBXwthl14y30KgFfGOt6Ki4jrRM= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-625-gAGr2H_BPmizR-y0PfBzwA-1; Wed, 02 Nov 2022 15:24:08 -0400 X-MC-Unique: gAGr2H_BPmizR-y0PfBzwA-1 Received: by mail-qv1-f72.google.com with SMTP id q16-20020a0ce210000000b004ba8976d3aaso10484417qvl.5 for ; Wed, 02 Nov 2022 12:24:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OnGbVU+pdLQrWU/4yKB9jRj3Qh2itknh7OkU6ci+FdA=; b=pcQuFbgb1wjg/4pXVuU8oJ6IswOk2Kw+BzQqp8FjmU1Y3Ijq6L99H8mUZnJxDMccdb 1zu6/n75ee4OfEWlio4ZZWXVm/r71hg/Rz9x2j9Mnfks7Ymljwf5nwc3Xn8QBzBxczcH 66JXeLlL3ony5X97GyNoRcGVIYPNpEASWm/UKCmu4rz4l2TNLFThriijbUpxVEDis4oM qudyQzz1jOJae5TqIUVk0brqTrc8T1ccOq2UWvfKh/o6FTeaf+ZtHqRUNFdSA8D79E16 uKj84WFfIpB/+Mv03vgCYNwLEztpr4BpmmMhi4vnqupXcZ2zCrCrJScMkUa0etS6nQ9H hRNw== X-Gm-Message-State: ACrzQf2lDd0vvFV1lLXYz8SYyju4MoKpLUWGelkafJouluzXwPAab7NV UGkZqO1BTDnurciX9KHpH6hT1oDLzCsmBDRpFpnPx5ABbn9x+dHwK/ZTSxjWyythRlUhb+BwVBv aCKhSSJLYVck= X-Received: by 2002:a05:622a:650:b0:39c:fa98:2de9 with SMTP id a16-20020a05622a065000b0039cfa982de9mr21087125qtb.535.1667417047838; Wed, 02 Nov 2022 12:24:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uiQZAjRp0CGfRjAPj7RfUT9NoUSAoNE0Xwu/NemCkgaG2/DG20QwO4j35n5PAKhn2onbQfA== X-Received: by 2002:a05:622a:650:b0:39c:fa98:2de9 with SMTP id a16-20020a05622a065000b0039cfa982de9mr21087096qtb.535.1667417047578; Wed, 02 Nov 2022 12:24:07 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id m17-20020ae9e711000000b006e42a8e9f9bsm2788884qka.121.2022.11.02.12.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 12:24:07 -0700 (PDT) Date: Wed, 2 Nov 2022 15:24:05 -0400 From: Peter Xu To: Mike Kravetz Cc: Nadav Amit , Linux-MM , kernel list , Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Rik van Riel , Vlastimil Babka , Matthew Wilcox , Andrew Morton , Wei Chen , "# 5 . 10+" , Linus Torvalds Subject: Re: [PATCH v2] hugetlb: don't delete vma_lock in hugetlb MADV_DONTNEED processing Message-ID: References: <7048D2B5-5FA5-4F72-8FDC-A02411CFD71D@gmail.com> <3232338E-77BB-42A8-9A25-5A4AD61FD4B2@gmail.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667417052; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OnGbVU+pdLQrWU/4yKB9jRj3Qh2itknh7OkU6ci+FdA=; b=4Frfmn+nw3MATB0IiJKy/yARxm8shZJ7NeN5vEUwbKlzWUAwC92+AE8Kz35TUE8/6Mgbgb 9rsLJWE3tPNaiXcDyY/Z+No5+ZRRC9kVhkNO8GD6znLRGe22Kqd12QwwA5+mKljiR1B/Cn fSq/YO6ChddfAsJvYVpIeQfrz4VyMR8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D7W6KrNr; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667417052; a=rsa-sha256; cv=none; b=LUJX8J9udCZG4ztEnbR9Kl/dsrlrUSR54kAU/e/HnQYKDEA2sigBCagd9lLVtCDT6D7Jbl XwApfYqydAweNv4xqOj3uwFjUtbBymdaLnm6MSHqndapimrPipg3gvpNO5FHgm2X9ui2uL fVHKPVtJUmTjWZYDx4Rgdtp4iOkoToo= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D7W6KrNr; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1C83E18000B X-Stat-Signature: rc7xp67am1ttj86134bbjgjdg3qnowbg X-HE-Tag: 1667417051-446297 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 Sun, Oct 30, 2022 at 06:44:10PM -0700, Mike Kravetz wrote: > On 10/30/22 11:52, Nadav Amit wrote: > > On Oct 30, 2022, at 11:43 AM, Peter Xu wrote: > > > > > The loop comes from 7e027b14d53e ("vm: simplify unmap_vmas() calling > > > convention", 2012-05-06), where zap_page_range() was used to replace a call > > > to unmap_vmas() because the patch wanted to eliminate the zap details > > > pointer for unmap_vmas(), which makes sense. > > > > > > I didn't check the old code, but from what I can tell (and also as Mike > > > pointed out) I don't think zap_page_range() in the lastest code base is > > > ever used on multi-vma at all. Otherwise the mmu notifier is already > > > broken - see mmu_notifier_range_init() where the vma pointer is also part > > > of the notification. > > > > > > Perhaps we should just remove the loop? > > > > There is already zap_page_range_single() that does exactly that. Just need > > to export it. > > I was thinking that zap_page_range() should perform a notification call for > each vma within the loop. Something like this? I'm boldly guessing what Nadav suggested was using zap_page_range_single() and export it for MADV_DONTNEED. Hopefully that's also the easiest for stable? For the long term, I really think we should just get rid of the loop.. > > @@ -1704,15 +1704,21 @@ void zap_page_range(struct vm_area_struct *vma, unsigned long start, > MA_STATE(mas, mt, vma->vm_end, vma->vm_end); > > lru_add_drain(); > - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm, > - start, start + size); > tlb_gather_mmu(&tlb, vma->vm_mm); > update_hiwater_rss(vma->vm_mm); > - mmu_notifier_invalidate_range_start(&range); > do { > - unmap_single_vma(&tlb, vma, start, range.end, NULL); > + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, > + vma->vm_mm, > + max(start, vma->vm_start), > + min(start + size, vma->vm_end)); > + if (is_vm_hugetlb_page(vma)) > + adjust_range_if_pmd_sharing_possible(vma, > + &range.start, > + &range.end); > + mmu_notifier_invalidate_range_start(&range); > + unmap_single_vma(&tlb, vma, start, start + size, NULL); > + mmu_notifier_invalidate_range_end(&range); > } while ((vma = mas_find(&mas, end - 1)) != NULL); > - mmu_notifier_invalidate_range_end(&range); > tlb_finish_mmu(&tlb); > } > > > One thing to keep in mind is that this patch is a fix that must be > backported to stable. Therefore, I do not think we want to add too > many changes out of the direct scope of the fix. > > We can always change things like this in follow up patches. > -- > Mike Kravetz > -- Peter Xu