From: Luis Chamberlain <mcgrof@kernel.org>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Matthew Wilcox <willy@infradead.org>,
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
Date: Wed, 22 Feb 2023 17:35:51 -0800 [thread overview]
Message-ID: <Y/bC99QPYCFX9Ndd@bombadil.infradead.org> (raw)
In-Reply-To: <CAJD7tkYHHSaiZwU9Evu-4r5=4FjrmFc-=xMst63io-4AM9N6XA@mail.gmail.com>
On Wed, Feb 22, 2023 at 05:04:32PM -0800, Yosry Ahmed wrote:
> On Wed, Feb 22, 2023 at 4:53 PM Luis Chamberlain <mcgrof@kernel.org> 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 <willy@infradead.org> 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
prev parent reply other threads:[~2023-02-23 1:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 2:52 [RFC 0/2] tmpfs: add the option to disable swap Luis Chamberlain
2023-02-07 2:52 ` [RFC 1/2] shmem: set shmem_writepage() variables early Luis Chamberlain
2023-02-07 3:52 ` Matthew Wilcox
2023-02-08 16:08 ` Luis Chamberlain
2023-02-07 2:52 ` [RFC 2/2] shmem: add support to ignore swap Luis Chamberlain
2023-02-07 4:01 ` Matthew Wilcox
2023-02-08 16:01 ` Luis Chamberlain
2023-02-08 17:45 ` Matthew Wilcox
2023-02-08 20:33 ` Yosry Ahmed
2023-02-23 0:53 ` Luis Chamberlain
2023-02-23 1:04 ` Yosry Ahmed
2023-02-23 1:35 ` Luis Chamberlain [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y/bC99QPYCFX9Ndd@bombadil.infradead.org \
--to=mcgrof@kernel.org \
--cc=a.manzanares@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=ebiederm@xmission.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=p.raghav@samsung.com \
--cc=willy@infradead.org \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).