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 05E03C433F5 for ; Fri, 18 Mar 2022 14:05:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BFAE8D0002; Fri, 18 Mar 2022 10:05:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6468A8D0001; Fri, 18 Mar 2022 10:05:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 499508D0002; Fri, 18 Mar 2022 10:05:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 3388C8D0001 for ; Fri, 18 Mar 2022 10:05:53 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 058A0221FB for ; Fri, 18 Mar 2022 14:05:53 +0000 (UTC) X-FDA: 79257680586.08.CA5D9D7 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by imf18.hostedemail.com (Postfix) with ESMTP id 2FB931C0035 for ; Fri, 18 Mar 2022 14:05:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1647612352; x=1679148352; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ffbZZDrcdGMKTpclOYncRs09YC3Awsec51kId4S+aIk=; b=vaPSdM+VS/SgP8YLXsxKlCblrNZcYdp6MKGJYHHC8LNKcDgbSOneSR6a W7unlkTPum5UBAvbCdcmJnOZhnWcg9Qi72OIlF1KDNVcxPhvU1N1ys0+C 3dczgxL4q98CrbTp84XDyFZq0HX3gBTzXeToo8QvlzoLW9UsK6E0Bmla4 0=; Received: from unknown (HELO ironmsg05-sd.qualcomm.com) ([10.53.140.145]) by alexa-out-sd-02.qualcomm.com with ESMTP; 18 Mar 2022 07:05:50 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg05-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2022 07:05:50 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 18 Mar 2022 07:05:49 -0700 Received: from [10.216.20.137] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Fri, 18 Mar 2022 07:05:45 -0700 Message-ID: <74852e90-003b-84b8-9836-72258e3c5057@quicinc.com> Date: Fri, 18 Mar 2022 19:35:41 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH V2,2/2] mm: madvise: skip unmapped vma holes passed to process_madvise Content-Language: en-US To: Nadav Amit , Suren Baghdasaryan CC: Minchan Kim , Andrew Morton , Vlastimil Babka , David Rientjes , Stephen Rothwell , =?UTF-8?Q?Edgar_Arriaga_Garc=c3=ada?= , Michal Hocko , linux-mm , LKML , "# 5 . 10+" References: <4f091776142f2ebf7b94018146de72318474e686.1647008754.git.quic_charante@quicinc.com> <20220315164807.7a9cf1694ee2db8709a8597c@linux-foundation.org> <5428f192-1537-fa03-8e9c-4a8322772546@quicinc.com> <20220316142906.e41e39d2315e35ef43f4aad6@linux-foundation.org> From: Charan Teja Kalla In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Stat-Signature: 4zrzj9pnungxb6wn71yq7df45f9cbxrx Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=vaPSdM+V; spf=pass (imf18.hostedemail.com: domain of quic_charante@quicinc.com designates 199.106.114.39 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2FB931C0035 X-HE-Tag: 1647612351-948547 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: Thank you for valuable inputs. On 3/18/2022 2:08 AM, Nadav Amit wrote: >>>>>> IMO, it's worth to note in man page. >>>>>> >>>>> Or the current patch for just ENOMEM is sufficient here and we just have >>>>> to update the man page? >>>> I think the "On success, process_madvise() returns the number of bytes >>>> advised" behaviour sounds useful. But madvise() doesn't do that. >>>> >>>> RETURN VALUE >>>> On success, madvise() returns zero. On error, it returns -1 and errno >>>> is set to indicate the error. >>>> >>>> So why is it desirable in the case of process_madvise()? >>> Since process_madvise deal with multiple ranges and could fail at one of >>> them in the middle or pocessing, people could decide where the call >>> failed and then make a strategy whether they will abort at the point or >>> continue to hint next addresses. Here, problem of the strategy is API >>> doesn't return any error vaule if it has processed any bytes so they >>> would have limitation to decide a policy. That's the limitation for >>> every vector IO syscalls, unfortunately. >>> >>>> >>>> >>>> And why was process_madvise() designed this way? Or was it >>>> always simply an error in the manpage? >> Taking a closer look, indeed manpage seems to be wrong. >> https://elixir.bootlin.com/linux/v5.17-rc8/source/mm/madvise.c#L1154 >> indicates that in the presence of unmapped holes madvise will skip >> them but will return ENOMEM and that's what process_madvise is >> ultimately returning in this case. So, the manpage claim of "This >> return value may be less than the total number of requested bytes, if >> an error occurred after some iovec elements were already processed." >> does not reflect the reality in our case because the return value will >> be -ENOMEM. After the desired behavior is finalized I'll modify the >> manpage accordingly. > Since process_madvise() might be used in sort of non-cooperative mode, > I think that the caller cannot guarantee that it knows exactly the > memory layout of the process whose memory it madvise’s. I know that > MADV_DONTNEED for instance is not supported (at least today) by > process_madvise(), but if it were, the caller may want which exact > memory was madvise'd even if the target process ran some other > memory layout changing syscalls (e.g., munmap()). > > IOW, skipping holes and just returning the total number of madvise’d > bytes might not be enough. Then does the advised bytes range by default including holes is a correct design? Say the [start, len) range passed in the iovec by the user contains the layout like, vma1 -- hole-- vma2 -- hole -- vma3. Under ideal case, where all vma's are eligible for advise, the total bytes processed returning should be vma3->end - vma1->start. This is success case. Now, say that vma1 is succeeded but vma2(say VM_LOCKED) is failed at advise. In such case processed bytes will be vma2->start-vma1->start(still consider hole as bytes processed), so that user may restart/skip at vma2, then continue. This return type will be partially processed bytes. If the system doesn't found any VMA in the passed range by user, it returns ENOMEM as not a single advisable vma is found in the range. >