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 1E558C433EF for ; Thu, 10 Feb 2022 13:09:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 947DF6B0073; Thu, 10 Feb 2022 08:09:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F7096B0074; Thu, 10 Feb 2022 08:09:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BF416B0075; Thu, 10 Feb 2022 08:09:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6A5796B0073 for ; Thu, 10 Feb 2022 08:09:24 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2C0F4180C800A for ; Thu, 10 Feb 2022 13:09:24 +0000 (UTC) X-FDA: 79126901448.31.144A2C6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 947F980002 for ; Thu, 10 Feb 2022 13:09:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644498563; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M/BVmK6ZEQDXgu6WLITH9xryIPWjvCSUhZcH2xVdXdE=; b=M7Dosj+33kBp8HV0T9oam1Pp98hVgTgfyDs4ONdcq07c38rM4Vd3KYsBfyNgav09AhW4pC 0yBcydAsnYD3QPEIyjz7y8ozR5pDRuhXUsh10XaxI5n9TAXNNOhJwFZ9xhZZ1KJrqZw7Na 92qIz1xvBWnXNbd3mgK6ffvxiJvJc+A= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-385-neC5A64UOl-DuNl3oWefGA-1; Thu, 10 Feb 2022 08:09:21 -0500 X-MC-Unique: neC5A64UOl-DuNl3oWefGA-1 Received: by mail-ed1-f70.google.com with SMTP id ed6-20020a056402294600b004090fd8a936so3287799edb.23 for ; Thu, 10 Feb 2022 05:09:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=M/BVmK6ZEQDXgu6WLITH9xryIPWjvCSUhZcH2xVdXdE=; b=yAWJnO2YPq0qb8g9i/U2tiTEBfiqCM3C5ltEstzziw/wck3qyIBoExan8230aCuq9I Ke0akovXtWZBTzKIfYz60fL44zgUEPnycvKHYspZLtFbQ0lEWwg63SKb8XoLvSXLg3PG cHy9ZlGg01ncADs6XIkHknWT5cOFSxE73jGPzOBASkg0XHmg3n+t1Mi4ggvVuZ/CX7Z6 d0EfSq1cyEb8rH72rk0Nf7fCzR2IksUFw808XujEbke7qVEqZJ2gf9jT6aoErgW+WEEs egkx21Paho/Iaa7dUUIB7WHE8lKudYzJ510VIRvtZKmOFMAgLa8D6ymeVKVKYrjdAEeJ q7kw== X-Gm-Message-State: AOAM531N3+jZ1HvxIozXylXLAvO8JE3uIWwn/5l6CH2PUxmhkUuWhbvE LQHR7oq+QHu+bUSrXi52BLbQ20rVaQ3SPUKafbkHo2Kpzow1xBDuil5czxBw9YZFk5lTppr726w ipswssOVGngI= X-Received: by 2002:a17:907:1c01:: with SMTP id nc1mr6554298ejc.659.1644498560754; Thu, 10 Feb 2022 05:09:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxA9WIx4q8U+5xgExPBsytlGv4dEUQkQQY+E5IEnfheqiHgyMsJL9Nla/bZ/c6l554DELMX6g== X-Received: by 2002:a17:907:1c01:: with SMTP id nc1mr6554276ejc.659.1644498560524; Thu, 10 Feb 2022 05:09:20 -0800 (PST) Received: from ?IPV6:2003:cb:c70b:f900:7b04:69ec:2caf:3b42? (p200300cbc70bf9007b0469ec2caf3b42.dip0.t-ipconnect.de. [2003:cb:c70b:f900:7b04:69ec:2caf:3b42]) by smtp.gmail.com with ESMTPSA id h7sm4477148ejb.40.2022.02.10.05.09.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Feb 2022 05:09:18 -0800 (PST) Message-ID: Date: Thu, 10 Feb 2022 14:09:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v2 1/3] mm: enable MADV_DONTNEED for hugetlb mappings To: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Naoya Horiguchi , Axel Rasmussen , Mina Almasry , Michal Hocko , Peter Xu , Andrea Arcangeli , Shuah Khan , Andrew Morton References: <20220202014034.182008-1-mike.kravetz@oracle.com> <20220202014034.182008-2-mike.kravetz@oracle.com> <20571829-9d3d-0b48-817c-b6b15565f651@redhat.com> <7b174c48-d368-43ba-7eab-13719a0d15ef@oracle.com> <6a82ea68-6e1e-8f5a-ca89-6744fc896a0b@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M7Dosj+3; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf30.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Rspamd-Queue-Id: 947F980002 X-Stat-Signature: cgw45cx4xpmqxdez61i4gam7ss8sum6r X-Rspamd-Server: rspam07 X-HE-Tag: 1644498563-606574 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 08.02.22 00:47, Mike Kravetz wrote: > On 2/4/22 00:35, David Hildenbrand wrote: >>> I thought this was simple. :) >> >> It really bugs me that it's under-specified what's supposed to happen >> when the length is not aligned. >> >> BUT: in the posix world, "calling posix_madvise() shall not affect the >> semantics of access to memory in the specified range". So we don't care >> too much about if we align up/down, because it wouldn't affect the >> semantics. Especially for MADV_DONTNEED/MADV_REMOVE as implemented by >> Linux this is certainly different and the alignment handling matters. >> >> So I guess especially for MADV_DONTNEED/MADV_REMOVE we need a clear >> specification what's supposed to happen if the length falls into the >> middle of a huge page. We should document alignment handling for >> madvise() in general I assume. >> >> IMHO we should have bailed out right from the start whenever something >> is not properly aligned, but that ship has sailed. So I agree, maybe we >> can make at least hugetlb MADV_DONTNEED obey the same (weird) rules as >> ordinary pages. >> >> So b) would mean, requiring start to be hugepage aligned and aligning-up >> the end. Still feels wrong but at least matches existing semantics. >> >> Hugetlb MADV_REMOVE semantics are unfortunate and we should document the >> exception. > > Thank you for all your comments David! > > So, my plan was to make MADV_DONTNEED behave as described above: > - EINVAL if start address not huge page size aligned > - Align end/length up to huge page size. > > The code I had for this was very specific to MADV_DONTNEED. I then thought, > why not do the same for MADV_REMOVE as well? Or even more general, add this > check and alignment to the vma parsing code in madvise. > > It was then that I realized there are several madvise behaviors that take > non-huge page size aligned addresses for hugetlb mappings today. Making > huge page size alignment a requirement for all madvise behaviors could break > existing code. So, it seems like it could only be added to MADV_DONTNEED as > this functionality does not exist today. We then end up with MADV_DONTNEED > as the only behavior requiring huge page size alignment for hugetlb mappings. > Sigh!!! :/ > > I am now rethinking the decision to proceed with b) as described above. > > With the exception of MADV_REMOVE (which we may be able to change for > hugetlb), madvise operations operate on huge page size pages for hugetlb > mappings. If start address is in the middle of a hugetlb page, we essentially > align down to the beginning of the hugetlb page. If length lands in the > middle of a hugetlb page, we essentially round up. Which MADV calls would be affected? The "bad" thing about MADV_DONTNEED and MADV_REMOVE are that they destroy data, which is why they heavily diverge from the original posix madvise odea. > > When adding MADV_REMOVE perhaps we should go with this align down start and > align up end strategy that is used everywhere else? I really wish we could > go back and change things, but as you know it is too late for that. I assume whatever we do, we should document it at least cleanly in the man page. Unfortunately, hugetlb is a gift that keeps on giving. Making it at least somehow consistent, even if it's "hugtlb being consistent in its own mess", that would be preferable I guess. -- Thanks, David / dhildenb