Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2441849pxb; Sat, 28 Aug 2021 15:05:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/gMFl3DEqTWmJViPDnVA7jjbDlTr5PU4dePgNA7JjiN8IcUURloLO90yI5NqfHRR3hoLB X-Received: by 2002:a05:6402:5249:: with SMTP id t9mr16049104edd.260.1630188299847; Sat, 28 Aug 2021 15:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630188299; cv=none; d=google.com; s=arc-20160816; b=O3f4mE5a3U6abZFyZPIUMfDVOctIwmSbCNOm8N0QdfRuvhZfJgPjj1f1QwC93zhEIY jCwlQP5GgRKePvVdFIojF5kHhh+LYhex6kB45lWIfrT1ppMeGJN7H4deazispedhwNCs HduEuj9xD5fUW96KK54Q//a+nDJAq1Egb3HGl2mKfsrsRfzXmKkqwl6psqXcBpGtEFsr b6pLE+afRuUHgxEoildrSLYVMXXUmOYlqwLXwiiZBeHEFsvdDc7GOWXEtoY3NAM6KRyx eyp3+MyYHLEwEFN24rGHkB88Zj+AtJxDPSrlMyv9RLQYKW1vQomJDbV4x2i1F//4L7lI huSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pyWbJNHHz8eg8MTD7gm92l9NEwd2/uLCVNwtVRUk+N8=; b=A+uIPlfomMGy7CpT91S56Ib1w2/T1yWinyJuXju9Vha/LiCeoPAK/Imy/vXV/T6esJ AmS15rvYt0B4R6PYgiDI0ZaNeo+pbGwbfqm5HQTzVU3CHzbcCK/naY061VdTwa2BZ13z F4RnM/VbpS4jcyS4MV0UIOo/FnZf/G2oBdERh6r6wiU+1h5S/v8Zqvg3BeB39hquK6Lh nv1tkswxyHdypp8emezQRUnDn0C9i7pp/Rd41WnQk0XnwyZhyLIcsUqEGX6ieG6E50ZA MfaVrGU93xPHuqNImW8ONR26UGzb6m+mkQs/04Q3fuiiKct/7rSeVSGsHJgvMDold9WI ryGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RtWc0eUL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si7651870ejy.380.2021.08.28.15.04.32; Sat, 28 Aug 2021 15:04:59 -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=@google.com header.s=20161025 header.b=RtWc0eUL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234650AbhH1WAh (ORCPT + 99 others); Sat, 28 Aug 2021 18:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234697AbhH1WAc (ORCPT ); Sat, 28 Aug 2021 18:00:32 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07865C0612A7 for ; Sat, 28 Aug 2021 14:59:28 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id r4so19901169ybp.4 for ; Sat, 28 Aug 2021 14:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pyWbJNHHz8eg8MTD7gm92l9NEwd2/uLCVNwtVRUk+N8=; b=RtWc0eULZASFS2c8UT3utLEPhZqsSiVw4hdmjvsPupSThfmle1yxbAmgOSFLM1o7lV 7X72oEIxSujnXwjV8bx2uMA4uZgDJ5sYemIqpxhRKsyJZJr6OEjZbWXiXnBE7GiPSS7e gDC2jE+VsDNNpvIxQfR/v1D46KuGZfJO/lyuifEhSVr8GTZbrc9XmwRcFat4Ght4g83P j5lsNBhkGkRZGyKtF9aPiYaNts0GyiDAxnqG68VrxKwwwqP5usAYcy6aBN7avZicL7CR bYoDwqQf4ZtSk8C66XQOP04BnHYF+fnfJCGDzn8ZriiSkUjhboIZQ+ijtZZgiFhDd6vC OElg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pyWbJNHHz8eg8MTD7gm92l9NEwd2/uLCVNwtVRUk+N8=; b=CEP3ZmBlfCxQ0F1/SgDKA/GGQg/shW+LCdNQyN/S1ni+CyR6u/EIF/n0OkRZ3SgUZD v/E7EqEuUvg2vPjeToL5fKaSTbL74R1vzDI+twErT5zQqSMKtZlYmQQeBZhiHj3upQuD cVbTUQqvbTyuQLfCrePsGskQVLz2yUqJ9XR4C8J5T67oRi9sF7wGDaPD0006Als8JQMl pyJbZUb3JbQd5NRSfdY3p7CQUh6VhqG2u/RC9uMFkshw/uTU0TK0nddnCaIKTHXfHc3I OLIE1dd9aeTn2n+16DDL1h8Yk/rgNXYWmGtJQdyu9XFI0MdxkK7nGL7mzQs8M1eT3jdo Hcmg== X-Gm-Message-State: AOAM533qFAA2LLXGWLYfez1tjB2n19RWBguwHN+XMxGlZtu9eEhKnQbT 5YHSz97Y4AKrrtzwc+xzjKxsilhq9XtiFpZtzWgnIg== X-Received: by 2002:a25:7ec4:: with SMTP id z187mr13867314ybc.136.1630187967034; Sat, 28 Aug 2021 14:59:27 -0700 (PDT) MIME-Version: 1.0 References: <20210827191858.2037087-1-surenb@google.com> <20210827191858.2037087-2-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Sat, 28 Aug 2021 14:59:16 -0700 Message-ID: Subject: Re: [PATCH v8 1/3] mm: rearrange madvise code to allow for reuse To: Cyrill Gorcunov Cc: Andrew Morton , Colin Cross , Sumit Semwal , Michal Hocko , Dave Hansen , Kees Cook , Matthew Wilcox , "Kirill A . Shutemov" , Vlastimil Babka , Johannes Weiner , Jonathan Corbet , Al Viro , Randy Dunlap , Kalesh Singh , Peter Xu , rppt@kernel.org, Peter Zijlstra , Catalin Marinas , vincenzo.frascino@arm.com, =?UTF-8?B?Q2hpbndlbiBDaGFuZyAo5by16Yym5paHKQ==?= , Axel Rasmussen , Andrea Arcangeli , Jann Horn , apopple@nvidia.com, John Hubbard , Yu Zhao , Will Deacon , fenghua.yu@intel.com, thunder.leizhen@huawei.com, Hugh Dickins , feng.tang@intel.com, Jason Gunthorpe , Roman Gushchin , Thomas Gleixner , krisman@collabora.com, chris.hyser@oracle.com, Peter Collingbourne , "Eric W. Biederman" , Jens Axboe , legion@kernel.org, eb@emlix.com, Muchun Song , Viresh Kumar , Thomas Cedeno , sashal@kernel.org, cxfcosmos@gmail.com, Rasmus Villemoes , LKML , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm , kernel-team , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 28, 2021 at 9:19 AM Cyrill Gorcunov wrote: > > 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? Thanks for the review Cyrill! Proposed changes sound good to me. Will change in the next revision. Suren. > > Cyrill