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 DAF22C433F5 for ; Thu, 10 Feb 2022 03:21:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 381BA6B0073; Wed, 9 Feb 2022 22:21:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 334406B0074; Wed, 9 Feb 2022 22:21:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D29F6B0075; Wed, 9 Feb 2022 22:21:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 0BA766B0073 for ; Wed, 9 Feb 2022 22:21:44 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AD8C08F6DB for ; Thu, 10 Feb 2022 03:21:43 +0000 (UTC) X-FDA: 79125420486.26.8A3F0C7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 2549B120002 for ; Thu, 10 Feb 2022 03:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644463302; 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=17Oj7nthiIWNQvcRVQOrz83IgfpkiF/YXs0dTC+pb6Y=; b=EFSWy6DoRI4cP8obdIuNqZO/Oykeqh3OYic9YdVxWZ2gIuRnbc0EhZk6xsSiy56ImhDafH RP2GoPiQGr9BEkd2pTk8HIln9NV/M78yl0azKw3FAqTqG65D+J4uApz5S/fBzg8h0k5eHX ScU2uxAxPIZoJznuKgkjNOIn+ueWLnw= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-252-8aczAz_VPLqSXvCab0OtRQ-1; Wed, 09 Feb 2022 22:21:41 -0500 X-MC-Unique: 8aczAz_VPLqSXvCab0OtRQ-1 Received: by mail-pl1-f199.google.com with SMTP id t14-20020a1709027fce00b0014d5ddc9dfbso546387plb.22 for ; Wed, 09 Feb 2022 19:21:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=17Oj7nthiIWNQvcRVQOrz83IgfpkiF/YXs0dTC+pb6Y=; b=o5knu4ki6HFV0M6w8PHUYfioZhQVCwUNcCDmqwRQ6pgZF7SsI0AfeysW7KTwFecHJP SWQmv4c8GVBM1q3fC3zhWRYLwDUdMUk8SH1HzJzVWveCRraAFAf8Fq4BOiUzbmEVFnIy GuK3k6tQK+22lAqobjA+3zlrviluSApSDkFlz7XcCwRLHa7RI7UwyEJkGOT5zYnosNd0 EkXGE/lxFnlonf3lsSdLh/dsvzDsPGLI8a3++DfZ5/CDD048/EBYltKwRfIuiWpyamLM 3M+PF2wRUp2ZOmZiIQ7S6jiSuZR5dTILjwLmIK7fYc+OLCdFT5XQpLhQeGBzvh2K2ZPg kV2Q== X-Gm-Message-State: AOAM5301KPazPUn4mxkCl8bkkRC5SL7vaUmZOHGs1ochslFEqgA5cjZJ 1N0GpAAUdEjGqEJHLJ3ilOyd+6cUeLo6kGmFa2BEzm+5jhxxyQgB/fUptSDNa30lFFjhDgkGM5A ibaxD+LV7tsE= X-Received: by 2002:a17:902:b708:: with SMTP id d8mr5305537pls.67.1644463300123; Wed, 09 Feb 2022 19:21:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxy8H0sudq262065i30E8DJVWmFQT9Q0V7k6OqW7821GAtFa+RDZqCorSow+O0e3x2bAI9ILA== X-Received: by 2002:a17:902:b708:: with SMTP id d8mr5305511pls.67.1644463299814; Wed, 09 Feb 2022 19:21:39 -0800 (PST) Received: from xz-m1.local ([94.177.118.72]) by smtp.gmail.com with ESMTPSA id z1sm21169985pfh.137.2022.02.09.19.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 19:21:39 -0800 (PST) Date: Thu, 10 Feb 2022 11:21:30 +0800 From: Peter Xu To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Michal Hocko , Andrea Arcangeli , Shuah Khan , Andrew Morton Subject: Re: [PATCH v2 1/3] mm: enable MADV_DONTNEED for hugetlb mappings Message-ID: References: <20220202014034.182008-1-mike.kravetz@oracle.com> <20220202014034.182008-2-mike.kravetz@oracle.com> MIME-Version: 1.0 In-Reply-To: <20220202014034.182008-2-mike.kravetz@oracle.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Stat-Signature: pwz81rors6wn5wwjbggkc1q3ghw4gcrs Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EFSWy6Do; spf=none (imf29.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2549B120002 X-HE-Tag: 1644463302-975396 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: (Sorry for the late comment) On Tue, Feb 01, 2022 at 05:40:32PM -0800, Mike Kravetz wrote: > MADV_DONTNEED is currently disabled for hugetlb mappings. This > certainly makes sense in shared file mappings as the pagecache maintains > a reference to the page and it will never be freed. However, it could > be useful to unmap and free pages in private mappings. > > The only thing preventing MADV_DONTNEED from working on hugetlb mappings > is a check in can_madv_lru_vma(). To allow support for hugetlb mappings > create and use a new routine madvise_dontneed_free_valid_vma() that will > allow hugetlb mappings. Also, before calling zap_page_range in the > DONTNEED case align start and size to huge page size for hugetlb vmas. > madvise only requires PAGE_SIZE alignment, but the hugetlb unmap routine > requires huge page size alignment. > > Signed-off-by: Mike Kravetz > --- > mm/madvise.c | 24 ++++++++++++++++++++++-- > 1 file changed, 22 insertions(+), 2 deletions(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index 5604064df464..7ae891e030a4 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -796,10 +796,30 @@ static int madvise_free_single_vma(struct vm_area_struct *vma, > static long madvise_dontneed_single_vma(struct vm_area_struct *vma, > unsigned long start, unsigned long end) > { > + /* > + * start and size (end - start) must be huge page size aligned > + * for hugetlb vmas. > + */ > + if (is_vm_hugetlb_page(vma)) { > + struct hstate *h = hstate_vma(vma); > + > + start = ALIGN_DOWN(start, huge_page_size(h)); > + end = ALIGN(end, huge_page_size(h)); > + } > + Maybe check the alignment before userfaultfd_remove()? Otherwise there'll be a fake message generated to the tracer. > zap_page_range(vma, start, end - start); > return 0; > } > > +static bool madvise_dontneed_free_valid_vma(struct vm_area_struct *vma, > + int behavior) > +{ > + if (is_vm_hugetlb_page(vma)) > + return behavior == MADV_DONTNEED; > + else > + return can_madv_lru_vma(vma); > +} can_madv_lru_vma() will check hugetlb again which looks a bit weird. Would it look better to write it as: madvise_dontneed_free_valid_vma() { return !(vma->vm_flags & (VM_LOCKED|VM_PFNMAP)); } can_madv_lru_vma() { return madvise_dontneed_free_valid_vma() && !is_vm_hugetlb_page(vma); } ? Another use case of DONTNEED upon hugetlbfs could be uffd-minor, because afaiu this is the only api that can force strip the hugetlb mapped pgtable without losing pagecache data. Thanks, -- Peter Xu