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=-11.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 BDA33C4363A for ; Tue, 20 Oct 2020 15:04:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9668421481 for ; Tue, 20 Oct 2020 15:04:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9668421481 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 08B036B006C; Tue, 20 Oct 2020 11:04:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 013E76B0070; Tue, 20 Oct 2020 11:03:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E479A6B0072; Tue, 20 Oct 2020 11:03:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B24E06B006C for ; Tue, 20 Oct 2020 11:03:59 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2EA0B362C for ; Tue, 20 Oct 2020 15:03:58 +0000 (UTC) X-FDA: 77392623756.17.star79_220fe8d27240 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 06791180D0180 for ; Tue, 20 Oct 2020 15:03:57 +0000 (UTC) X-HE-Tag: star79_220fe8d27240 X-Filterd-Recvd-Size: 2823 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 20 Oct 2020 15:03:57 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 54F47ABE3; Tue, 20 Oct 2020 15:03:56 +0000 (UTC) To: Nikita , linux-mm@kvack.org Cc: Andrew Morton References: <20201012160911.6282-1-sh1r4s3@mail.si-head.nl> <92411D90-AD5D-44B9-8F52-C2FA222BB4EB@mail.si-head.nl> From: Vlastimil Babka Subject: Re: [PATCH] mm/msync: exit early when the flags is an MS_ASYNC and start < vm_start Message-ID: <75def548-28a2-729a-96b7-56ba91bfc94c@suse.cz> Date: Tue, 20 Oct 2020 17:03:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: <92411D90-AD5D-44B9-8F52-C2FA222BB4EB@mail.si-head.nl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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 10/20/20 4:38 PM, Nikita wrote: > Hi! >=20 >> On 20 Oct 2020, at 13:19, Vlastimil Babka wrote: >>=20 >> 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 >>=20 >> AFAICS it can still return -EBUSY if there's MS_INVALIDATE and a mlock= ed vma. This is all subtle and I don't think we should risk breaking some= thing for this optimization. >>=20 > Yes, it could. But in this patch the optimization works only in the cas= e if the flag is MS_ASYNC. If the flag is (MS_ASYNC | MS_INVALIDATE). Ah, right, it compares "=3D=3D MS_ASYNC" not "& MS_ASYNC" so it's correct= . A comment=20 would be nice, such as: We found an unmapped range and with MS_ASYNC and no MS_INVALIDATE there's= =20 nothing to do and the result will always be -ENOMEM, so we can return imm= ediately. >>> --- >>> 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 >=20