Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2268022pxb; Sat, 28 Aug 2021 09:21:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztvYCLkTXw8+cxx85jZaWNWPPfbwvTZuz4DJhI0Bf40FIOO2PCJBg9ZGTaT3BsTmE8m2nH X-Received: by 2002:a05:6638:250a:: with SMTP id v10mr13006796jat.21.1630167675947; Sat, 28 Aug 2021 09:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630167675; cv=none; d=google.com; s=arc-20160816; b=dxYQvEec0BlRGmq2NtdAPtfvn8v80mv4K7ddxMwks7ZFAauBJIvce4WkND2dk1kbSO g3izaQfpTE3epxt6YY0+nuGD8B5eSvaUNLVmQxra4oaAJCqBuo/bDqFhWenzUgKz/yK1 W7yjseabpNZK4ATcNd7GnrLiYEkqeNDowLavdhVc4uHpit8gL+uLnpVG4kVrgEQOrttp 4jA49nQ2xiZhD/rBwdLqemah6xHVIbJH1Sj20ysNgD7G32peaGsLBfvFwB2RokIborsa 3fYcDYv3qkzJwzyxyNBCt+0ddA86wnmtVuCdxPFO2WM6Hrlt7goGBP2SH1CX+owuyxrq +Y+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=KJjlhL+wu+SZnMSpzSjNoshjgIUDvLy0pU8sVpAAjyY=; b=NDkruHFujtw/fw3oryl192BcEGERPKKZDNdWPWqANdhjE0XoQ01ev0EixwZyj7iuyw 0HKsLAB5l6TEyuccSK7x74/1rOoB/enGYQZcgePmXI6xOjqmEkDQN0wdCO6QxmfI0042 mUiUe62lv37ESK9WKwKWcnZp7YYKdve4+7N2h73NQ9cwO2GsY3SqED3WI5oWR8XUYttE YBs7zAgAL/V0at/rWYNDr5D9Z7Foa7bCLi6I/XwHE7Ighq3+6qtyLwET1JJ9ZuW/71ul xAMrcpzpg/mqgglW4mm2Cl1wMddjIDiWrE5yk5gi1VF2TA3A33n7L6nN/iaEn0E2KUDW xR1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u+8fDKLk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si9377678ilj.61.2021.08.28.09.21.03; Sat, 28 Aug 2021 09:21:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u+8fDKLk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234557AbhH1QUw (ORCPT + 99 others); Sat, 28 Aug 2021 12:20:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229465AbhH1QUv (ORCPT ); Sat, 28 Aug 2021 12:20:51 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6A40C061756; Sat, 28 Aug 2021 09:20:00 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id j4so21247836lfg.9; Sat, 28 Aug 2021 09:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=KJjlhL+wu+SZnMSpzSjNoshjgIUDvLy0pU8sVpAAjyY=; b=u+8fDKLkjfXLvVTs0dE+JFc9+I0FiO54/wmMk8th90CEiOgkFBAGh/5xcM745TSfJl inKBOUjhDchGvwYvSC8CiN9D2QMegqM2VctXyKdTWd+1ETeVNzWxLg6mTjYtOQLkFPY2 8V/MIBPhQ+aeuqBJbDHbFqUlHSkTQUlUjDjk/PUjQSn8ILEFLSa/UDH4Xb65BRlRTei1 Nyjiuj+e49LRy1YzLMmP3pZKM7ln1AHyWy8Fn3BJjL3aF3y4t5Zq/GW7LqWoyF18YtW7 3gzXdINIcDHYPAQg1YnyGP6JKkV/9BMOrNZCjrl382MqJ5mEkVwX/U3xaYMJXVL9gCnK u0vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=KJjlhL+wu+SZnMSpzSjNoshjgIUDvLy0pU8sVpAAjyY=; b=Dxsv9b6w6c+YXZ95jdBtx0VH6cO2kQ+BN9h1fiqCcx+6Nxh1KevJHv+Wzr9XFYY+1u TKUqpLJ+0sAtEONnUwjF0ilIP/DcCaJJfEDmc39R+NyPadUPA9+hTkXwj9qCZPYQ11L+ vOc8eGVSlRAAk4ijHJ/w4B44XSJAmGi3+CosVgLRCsXslgGEQj2iH1s2jFxsrUDxySU3 tFPF9MzdUfEHwQblq41igziIaHwVGL72/q63D3ujl3xEtPHAmQGhHjWUIWIQXt/srIOM k4/QZQ9GwacBQc/SAc7p0GTD+kl7sG2gZVsb3gS2Owd0t1xOjExUEpZVX6A1nFLvI5lU zPMQ== X-Gm-Message-State: AOAM530WE3XhlY5/30Vyeey/8UTPI3aC5gIDIDkdDluJPTUs2ddWozNE 5CRYSF/rhal1eAzQnooVgnP5SJSaLNBoY8L0 X-Received: by 2002:a19:6a16:: with SMTP id u22mr10838618lfu.493.1630167599317; Sat, 28 Aug 2021 09:19:59 -0700 (PDT) Received: from grain.localdomain ([5.18.253.97]) by smtp.gmail.com with ESMTPSA id m1sm244759lfc.144.2021.08.28.09.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Aug 2021 09:19:59 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id AC9EF5A001E; Sat, 28 Aug 2021 19:19:46 +0300 (MSK) Date: Sat, 28 Aug 2021 19:19:46 +0300 From: Cyrill Gorcunov To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, ccross@google.com, sumit.semwal@linaro.org, mhocko@suse.com, dave.hansen@intel.com, keescook@chromium.org, willy@infradead.org, kirill.shutemov@linux.intel.com, vbabka@suse.cz, hannes@cmpxchg.org, corbet@lwn.net, viro@zeniv.linux.org.uk, rdunlap@infradead.org, kaleshsingh@google.com, peterx@redhat.com, rppt@kernel.org, peterz@infradead.org, catalin.marinas@arm.com, vincenzo.frascino@arm.com, chinwen.chang@mediatek.com, axelrasmussen@google.com, aarcange@redhat.com, jannh@google.com, apopple@nvidia.com, jhubbard@nvidia.com, yuzhao@google.com, will@kernel.org, fenghua.yu@intel.com, thunder.leizhen@huawei.com, hughd@google.com, feng.tang@intel.com, jgg@ziepe.ca, guro@fb.com, tglx@linutronix.de, krisman@collabora.com, chris.hyser@oracle.com, pcc@google.com, ebiederm@xmission.com, axboe@kernel.dk, legion@kernel.org, eb@emlix.com, songmuchun@bytedance.com, viresh.kumar@linaro.org, thomascedeno@google.com, sashal@kernel.org, cxfcosmos@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, Pekka Enberg , Ingo Molnar , Oleg Nesterov , Jan Glauber , John Stultz , Rob Landley , "Serge E. Hallyn" , David Rientjes , Rik van Riel , Mel Gorman , Michel Lespinasse , Tang Chen , Robin Holt , Shaohua Li , Sasha Levin , Minchan Kim Subject: Re: [PATCH v8 1/3] mm: rearrange madvise code to allow for reuse Message-ID: References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-2-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210827191858.2037087-2-surenb@google.com> User-Agent: Mutt/2.0.7 (2021-05-04) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 27, 2021 at 12:18:56PM -0700, Suren Baghdasaryan wrote: ... > > +/* > + * Apply an madvise behavior to a region of a vma. madvise_update_vma > + * will handle splitting a vm area into separate areas, each area with its own > + * behavior. > + */ > +static int madvise_vma_behavior(struct vm_area_struct *vma, > + struct vm_area_struct **prev, > + unsigned long start, unsigned long end, > + unsigned long behavior) > +{ > + int error = 0; Hi Suren! A nitpick -- this variable is never used with default value so I think we could drop assignment here. ... > + case MADV_DONTFORK: > + new_flags |= VM_DONTCOPY; > + break; > + case MADV_DOFORK: > + if (vma->vm_flags & VM_IO) { > + error = -EINVAL; We can exit early here, without jumping to the end of the function, right? > + goto out; > + } > + new_flags &= ~VM_DONTCOPY; > + break; > + case MADV_WIPEONFORK: > + /* MADV_WIPEONFORK is only supported on anonymous memory. */ > + if (vma->vm_file || vma->vm_flags & VM_SHARED) { > + error = -EINVAL; And here too. > + goto out; > + } > + new_flags |= VM_WIPEONFORK; > + break; > + case MADV_KEEPONFORK: > + new_flags &= ~VM_WIPEONFORK; > + break; > + case MADV_DONTDUMP: > + new_flags |= VM_DONTDUMP; > + break; > + case MADV_DODUMP: > + if (!is_vm_hugetlb_page(vma) && new_flags & VM_SPECIAL) { > + error = -EINVAL; Same. > + goto out; > + } > + new_flags &= ~VM_DONTDUMP; > + break; > + case MADV_MERGEABLE: > + case MADV_UNMERGEABLE: > + error = ksm_madvise(vma, start, end, behavior, &new_flags); > + if (error) > + goto out; > + break; > + case MADV_HUGEPAGE: > + case MADV_NOHUGEPAGE: > + error = hugepage_madvise(vma, &new_flags, behavior); > + if (error) > + goto out; > + break; > + } > + > + error = madvise_update_vma(vma, prev, start, end, new_flags); > + > +out: I suppose we better keep the former comment on why we maps ENOMEM to EAGAIN? Cyrill