From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A54B4315A for ; Fri, 21 Nov 2025 21:32:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763760735; cv=none; b=bUlo09w3hdDWFLMfYB0D2Ut2pPfnWHKlQBnz+9S3x275G9TAXk3wtL9gL5PxYoLCKldEPPOBf5mNtebejWh80CsDDd3V4MdNwi2MqmZlsew5F8/O0JBM8KkhsxG6d5yIs/bCqhuua4zD2QAP38n0zA/mVQM4bRpB1/Fohai8DW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763760735; c=relaxed/simple; bh=9CXYMqrOIm+Q10uDMB/uyJplbeY1MEE5pftnNW81HpY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SwlZqw9turW2VhYLVQ4L2uDDo17oz7uDki7/KhYzvi+jYGSzl98/mD4r3qn7AwBfTR172CetRMRkJ3KT3C51hW9I2oxKOH0CYUtduuFav0pkxmaJkxgN8ysB7CY/gH1Er5WBdiQkZGB3RJvbcTKKaRJgjFCBsRAvshsw2Ptm/tA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nMjYo/da; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nMjYo/da" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97986C116C6; Fri, 21 Nov 2025 21:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763760734; bh=9CXYMqrOIm+Q10uDMB/uyJplbeY1MEE5pftnNW81HpY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nMjYo/daf/v/pGj0zjIz0yC1qxreOE5r1ZeyyiYlLQdzropLyAJ+/yphoLIMuv6TJ BhAP7mLvOh7w+8zluIiEo6BXH6fGDEm4vhqfy1PBRhHQ8/JFiSsAMD2QKR1NiXUFSR Hudl6H6y91ltl/SzecKQRISdewodQrHyUhPxoYFFyFAp5Qwl3F8akL63ZNMlaaynfh 3ZPiz4q+DyPSwD7A+uzmjRnF+d7hMor4x+nFinc9hzvHFYsSTW63+turuEU7tDK5H5 Jjw2NxFk1Fg6gN8m3E5Gcflh9I1Mq2kNOqIx/ZtH9Oyb2gtDIpX7+cwWjN8CI9fdIm 97xU5Kq4GIQSA== Date: Fri, 21 Nov 2025 21:32:12 +0000 From: Jaegeuk Kim To: Matthew Wilcox Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Christian Brauner Subject: Re: [PATCH] [RFC] mm/fadvise: introduce POSIX_FADV_MLOCK Message-ID: References: <20251121032718.1993528-1-jaegeuk@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On 11/21, Matthew Wilcox wrote: > On Fri, Nov 21, 2025 at 07:52:02PM +0000, Jaegeuk Kim wrote: > > On 11/21, Jaegeuk Kim wrote: > > > On 11/21, Matthew Wilcox wrote: > > > > On Fri, Nov 21, 2025 at 04:46:14AM +0000, Jaegeuk Kim wrote: > > > > > On 11/21, Matthew Wilcox wrote: > > > > > > On Fri, Nov 21, 2025 at 03:27:18AM +0000, Jaegeuk Kim wrote: > > > > > > > This patch introduces a new POSIX_FADV_MLOCK which 1) invalidates the range of > > > > > > > cached pages, 2) sets the mapping as inaccessible, 3) POSIX_FADV_WILLNEED loads > > > > > > > pages directly to the inaccessible mapping. > > > > > > > > > > > > ... what? > > > > > > > > > > > > This seems like something which is completely different from mlock(). > > > > > > So it needs a different name. > > > > > > > > > > > > But I don't understand the point of this, whatever it's called. Need > > > > > > more information. > > > > > > > > > > So, the sequence that I'd like to optimize is mmap(MAP_POPULATE) followed > > > > > by mlock(). For example, mmap() takes 1 second to load 4GB data, and mlock() > > > > > takes 330ms additionally in order to migrate all the pages into inaccessible > > > > > map, IIUC. > > > > > > > > Oh, so the MLOCK part is right, but the inaccessible() part is wrong. > > > > Inaccessible is special weird guest_memfd crap that has all kinds of > > > > side-effects that you don't want. > > > > > > > > Wouldn't you get the same effect by calling mlock2(MLOCK_ONFAULT) and > > > > then calling readahead() for the desired range? > > > > > > Oh, thank you. Let me try. > > > > After checking the code and experiment, I don't think that gives what we need. > > That flag skips populate_vma_page_range only, but we need to allocate pages > > in the inaccessible mapping and fill the pages afterwards. > > Then either I don't understand what you're trying to do, or you don't > understand what the inaccessible mapping is for. Is this just for > speeding up mlock() as you suggested earlier, or are you genuinely > trying to do something with the inaccessible mapping? The latter. I'd like to propose a new read flow with the inaccessible mapping. As-Is: mmap() -> fadvise(fd, POSIX_FADV_WILLNEED) -> mlock() 1. fadvise() proposal mmap() -> fadvise(fd, POSIX_FADV_MLOCK) : all the pages will be loaded into inaccessible page cache directly 2. mlock2() proposal mmap() -> mlock2(MLOCK_ONFAULT) -> madvise(MADV_POPULATE_READ) If you mean #2, I need to find whether we can get the space for madvise, since we have only fd when reading the pages. And, also I need to find a way to handle the folio order directly instead of starging from 0 in madvise() path. Let me think about it.