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 X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 254C0C388F7 for ; Tue, 20 Oct 2020 16:19:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1672B2224A for ; Tue, 20 Oct 2020 16:19:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1672B2224A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mail.si-head.nl Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 20D716B005C; Tue, 20 Oct 2020 12:19:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BBA36B0062; Tue, 20 Oct 2020 12:19:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 086C76B0068; Tue, 20 Oct 2020 12:19:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id CD4586B005C for ; Tue, 20 Oct 2020 12:19:18 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 58538180AD806 for ; Tue, 20 Oct 2020 16:19:18 +0000 (UTC) X-FDA: 77392813596.08.stone20_350637427241 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 222811819E766 for ; Tue, 20 Oct 2020 16:19:18 +0000 (UTC) X-HE-Tag: stone20_350637427241 X-Filterd-Recvd-Size: 3061 Received: from mail.si-head.nl (si-head.tilaa.cloud [37.252.121.114]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 20 Oct 2020 16:19:17 +0000 (UTC) Received: from [IPv6:::1] (si-head.tilaa.cloud [37.252.121.114]) by mail.si-head.nl (Postfix) with ESMTPSA id 7B2B3C16A0; Tue, 20 Oct 2020 19:19:15 +0300 (MSK) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: [PATCH] mm/msync: exit early when the flags is an MS_ASYNC and start < vm_start From: Nikita In-Reply-To: <75def548-28a2-729a-96b7-56ba91bfc94c@suse.cz> Date: Tue, 20 Oct 2020 19:19:14 +0300 Cc: Andrew Morton Content-Transfer-Encoding: quoted-printable Message-Id: <94E11FCB-AA03-490B-9F9E-2508DC8A15D1@mail.si-head.nl> References: <20201012160911.6282-1-sh1r4s3@mail.si-head.nl> <92411D90-AD5D-44B9-8F52-C2FA222BB4EB@mail.si-head.nl> <75def548-28a2-729a-96b7-56ba91bfc94c@suse.cz> To: Vlastimil Babka , linux-mm@kvack.org X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > On 20 Oct 2020, at 18:03, Vlastimil Babka wrote: >=20 > On 10/20/20 4:38 PM, Nikita wrote: >> Hi! >>> On 20 Oct 2020, at 13:19, Vlastimil Babka wrote: >>> On 10/12/20 6:09 PM, Nikita Ermakov wrote: >>>> Exit from the loop over the VMA in the case when the flags >>>> contain only an MS_ASYNC and start < vm_start. In this case msync() >>>> would return with -ENOMEM anyway so make it return early. >>>> Signed-off-by: Nikita Ermakov >>> AFAICS it can still return -EBUSY if there's MS_INVALIDATE and a = mlocked vma. This is all subtle and I don't think we should risk = breaking something for this optimization. >> Yes, it could. But in this patch the optimization works only in the = case if the flag is MS_ASYNC. If the flag is (MS_ASYNC | MS_INVALIDATE). >=20 > Ah, right, it compares "=3D=3D MS_ASYNC" not "& MS_ASYNC" so it's = correct. A comment would be nice, such as: >=20 > We found an unmapped range and with MS_ASYNC and no MS_INVALIDATE = there's nothing to do and the result will always be -ENOMEM, so we can = return immediately. >=20 Thanks for the comment! I should probably implement this comment to the patch description and = resubmit it as v2. >>>> --- >>>> mm/msync.c | 2 ++ >>>> 1 file changed, 2 insertions(+) >>>> diff --git a/mm/msync.c b/mm/msync.c >>>> index 69c6d2029531..ed20c3621d4c 100644 >>>> --- a/mm/msync.c >>>> +++ b/mm/msync.c >>>> @@ -69,6 +69,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, = size_t, len, int, flags) >>>> goto out_unlock; >>>> /* Here start < vma->vm_end. */ >>>> if (start < vma->vm_start) { >>>> + if (flags =3D=3D MS_ASYNC) >>>> + goto out_unlock; >>>> start =3D vma->vm_start; >>>> if (start >=3D end) >>>> goto out_unlock; >>>> base-commit: 6824a8a9b4861d7df7ee132a952bdf6f84a99cb8 >=20