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 5C16EC636D6 for ; Thu, 23 Feb 2023 01:36:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0F756B0072; Wed, 22 Feb 2023 20:35:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BBF336B0073; Wed, 22 Feb 2023 20:35:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A871F6B0074; Wed, 22 Feb 2023 20:35:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 993646B0072 for ; Wed, 22 Feb 2023 20:35:59 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7826DC0EF0 for ; Thu, 23 Feb 2023 01:35:59 +0000 (UTC) X-FDA: 80496840438.27.8B2C92F Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 5B1231C000B for ; Thu, 23 Feb 2023 01:35:57 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="jR/GpYpS"; spf=none (imf20.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677116157; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+JG1+kQ4CA3XXyr6PqDGRrx24SD/13lLGJOcUnu6X1M=; b=mNYSyYl5PDLIjM3W3l/Qi5Y+T168MOqqa5anlABeY38tTc7ZOwsKEZvr2E6tr/in5MDocL QYVP6r1SqB8ZCScJQLR6Clx4oPi4q+aAwdIV0RsxoO8G5Fu7MCYGabbFxjl+lihwOtI1IN LLdhg236/w9DBN1o7k7be4ptGRlIXkE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="jR/GpYpS"; spf=none (imf20.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677116157; a=rsa-sha256; cv=none; b=2ijzO6U4FWHNhYpFCcHfbje260BSX33Ylkb0goobXrbpEXX8qH5BvQwVlTltDK/lbW1Ri0 it6OidsNVFSCLWcCOX8VAhKquu/OepUro7WNVj/rNIkPb/hp0GigA15kjKQHF01F2S7SAS XJ5ue/O3a8T10ewGCs8eN6Bi/ya836w= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+JG1+kQ4CA3XXyr6PqDGRrx24SD/13lLGJOcUnu6X1M=; b=jR/GpYpSyNFz9kxg6zSaEOrxvx G/9wGKDje1D+wj64JDMqV7bS1mfNTjZcosy7vDphCWyx1EmBsQBN4UwroT1h0Jc2uUPfBKu7nucyD 7fyshIG1AECFvqxyKzIn8L8UpzEi8qb+n6NAtZLV/KzrgoZT2qO2XgmAIh4IbG15ffs1X+VGiK8TX r6WiQl/tbbtcrdpsE3Ft38tr5p2/iOqPW5xgJz/7LMM+0nlEAmLpVzxqLmDuC11wBSIrcbCtNnl7p wAXjirl58dDlfGtAUgAnFYyAYChDEFOvnuErdu6Kd6zHt1oyfmHpIOLwvB328qSkLr3xSlIRaoeId ktAilC+w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV0WV-00Ef9N-31; Thu, 23 Feb 2023 01:35:51 +0000 Date: Wed, 22 Feb 2023 17:35:51 -0800 From: Luis Chamberlain To: Yosry Ahmed Cc: "Eric W. Biederman" , Matthew Wilcox , hughd@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, p.raghav@samsung.com, dave@stgolabs.net, a.manzanares@samsung.com, linux-kernel@vger.kernel.org Subject: Re: [RFC 2/2] shmem: add support to ignore swap Message-ID: References: <20230207025259.2522793-1-mcgrof@kernel.org> <20230207025259.2522793-3-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5B1231C000B X-Stat-Signature: p33bp181dw78yrh6u38ptdquo7zcf89i X-HE-Tag: 1677116157-334809 X-HE-Meta: U2FsdGVkX1++OHJZz4ZiMjLS1C+Gzf2GeyvhX/PbK2Hx39UNr8Fz7NuJoo1dhVvfrcwtqfmCvNHokiCXOUJ68zx3mhs4y+OrtdV8E2ZLwOaBVxLlz1aKoxMaLb7pEYc48zqRYrJIle3UNBQWo3TugCBUs/5gWj4N6ivImjjMwKaZJQ1BuNvmBXIq5e3EYm5y1gs44RYHon7ItvxfmhPPhhRUHRUS+VsBJQJEdHTQz1mbAe+Lt7Gz7U0gFmlVPblQTJtVUafGQolQQuccr7h2e8Pud94By6en3+HISp2d8tzNwqtC9KcGwiOxiGGJpZgd6UVw1l0R2vZYgkbeRMIb4fwLUzhw5aUvLopiiJ1dV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7E 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 Wed, Feb 22, 2023 at 05:04:32PM -0800, Yosry Ahmed wrote: > On Wed, Feb 22, 2023 at 4:53 PM Luis Chamberlain wrote: > > > > On Wed, Feb 08, 2023 at 12:33:37PM -0800, Yosry Ahmed wrote: > > > On Wed, Feb 8, 2023 at 9:45 AM Matthew Wilcox wrote: > > > > > > > > On Wed, Feb 08, 2023 at 08:01:01AM -0800, Luis Chamberlain wrote: > > > > > On Tue, Feb 07, 2023 at 04:01:51AM +0000, Matthew Wilcox wrote: > > > > > > On Mon, Feb 06, 2023 at 06:52:59PM -0800, Luis Chamberlain wrote: > > > > > > > @@ -1334,11 +1336,15 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) > > > > > > > struct shmem_inode_info *info; > > > > > > > struct address_space *mapping = folio->mapping; > > > > > > > struct inode *inode = mapping->host; > > > > > > > + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); > > > > > > > swp_entry_t swap; > > > > > > > pgoff_t index; > > > > > > > > > > > > > > BUG_ON(!folio_test_locked(folio)); > > > > > > > > > > > > > > + if (wbc->for_reclaim && unlikely(sbinfo->noswap)) > > > > > > > + return AOP_WRITEPAGE_ACTIVATE; > > > > > > > > > > > > Not sure this is the best way to handle this. We'll still incur the > > > > > > oevrhead of tracking shmem pages on the LRU, only to fail to write them > > > > > > out when the VM thinks we should get rid of them. We'd be better off > > > > > > not putting them on the LRU in the first place. > > > > > > > > > > Ah, makes sense, so in effect then if we do that then on reclaim > > > > > we should be able to even WARN_ON(sbinfo->noswap) assuming we did > > > > > everthing right. > > > > > > > > > > Hrm, we have invalidate_mapping_pages(mapping, 0, -1) but that seems a bit > > > > > too late how about d_mark_dontcache() on shmem_get_inode() instead? > > > > > > > > I was thinking that the two calls to folio_add_lru() in mm/shmem.c > > > > should be conditional on sbinfo->noswap. > > > > > > > > > > Wouldn't this cause the folio to not show up in any lru lists, even > > > the unevictable one, which may be a strange discrepancy? > > > > > > Perhaps we can do something like shmem_lock(), which calls > > > mapping_set_unevictable(), which will make folio_evictable() return > > > true and the LRUs code will take care of the rest? > > > > If shmem_lock() should take care of that is that because writepages() > > should not happen or because we have that info->flags & VM_LOCKED stop > > gap on writepages()? If the earlier then shouldn't we WARN_ON_ONCE() > > if writepages() is called on info->flags & VM_LOCKED? > > > > While I see the value in mapping_set_unevictable() I am not sure I see > > the point in using shmem_lock(). I don't see why we should constrain > > noswap tmpfs option to RLIMIT_MEMLOCK > > > > Please correct me if I'm wrong but the limit seem to be designed for > > files / IPC / unprivileged perf limits. On the contrary, we'd bump the > > count for each new inode. Using shmem_lock() would also complicate the > > inode allocation on shmem as we'd have to unwind on failure from the > > user_shm_lock(). It would also beg the question of when to capture a > > ucount for an inode, should we just share one for the superblock at > > shmem_fill_super() or do we really need to capture it at every single > > inode creation? In theory we could end up with different limits. > > > > So why not just use mapping_set_unevictable() alone for this use case? > > Sorry if I wasn't clear, I did NOT mean that we should use > shmem_lock(), I meant that we do something similar to what > shmem_lock() does and use mapping_set_unevictable() or similar. Ah OK! Sure yeah I reviewed shmem_lock() usage and I don't think it and its rtlimit baggage makes sense here so the only thing to do is just mapping_set_unevictable(). > I think we just need to make sure that if we use > mapping_set_unevictable() does not imply that shmem_lock() was used > (i.e no code assumes that if the shmem mapping is unevictable then > shmem_lock() was used). The *other* stuff that shmem_lock() does is rlimit rlimit related to RLIMIT_MEMLOCK, I can't think off hand why we'd confuse the two use cases at the moment, but I'll give it another good luck with this in mind. I'll test what I have and post a v2 with the feedback received. Thanks, Luis