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 EFAD5C61DA4 for ; Thu, 23 Feb 2023 01:05:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A4FF6B0072; Wed, 22 Feb 2023 20:05:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 82CC06B0073; Wed, 22 Feb 2023 20:05:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CCEB6B0074; Wed, 22 Feb 2023 20:05:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5CA526B0072 for ; Wed, 22 Feb 2023 20:05:14 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1EA1F1A0E5F for ; Thu, 23 Feb 2023 01:05:14 +0000 (UTC) X-FDA: 80496762948.25.20F414D Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf30.hostedemail.com (Postfix) with ESMTP id 45AFE80011 for ; Thu, 23 Feb 2023 01:05:12 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eMEr2KTi; spf=pass (imf30.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677114312; h=from:from: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=SHogG2LDNYMpKAnj+yA1kU5df/jIvMfB3AX9e8CKk5Q=; b=i3uGmf4ao9OjzPQxFBl68alsX6/ejClCho7Nimu4TsVXI7Z1Hnnuvgm2+JSYjyADKlFIIY clYbN+RBht9CT1UMhCJ9yEluiHwnRP3w/HKwnbJYVPMIegt1JYlKJ2ScUj1Oq2GbeW7m/Z DP0b18xiKV7aSbMTffs5BS9ePDQtbpg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eMEr2KTi; spf=pass (imf30.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677114312; a=rsa-sha256; cv=none; b=yryJXHqbitSgrXF+r9WlbElQDRp6TGKjXTaHwEf0ighfVZou/r9cbkjOJc6JIm1tllq1Mx u1l2bErNZ0MTnHoc4kOJKKZGkWhUBI+n+spik9KTOtRukuc2ud4L+Xz49Xvi85p9XoHoCm 1GUa0yQlJrOWwzxeTuTahOSU3ac4U3g= Received: by mail-ed1-f48.google.com with SMTP id b12so37595731edd.4 for ; Wed, 22 Feb 2023 17:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SHogG2LDNYMpKAnj+yA1kU5df/jIvMfB3AX9e8CKk5Q=; b=eMEr2KTiTgK78tcAXjNLifRF6IhRudaha/mQV40/EZp98wWqB3C4XPGo8J46TDVQuK 9Myt9kMvWCrEOe/SaNvOPIMclmFuS8vgmWgA3EZN0lRW3NmVeZNtfvxE+6NNyAltGVH/ YB1MxF7KzN2WhPp3SZazN8uDBfpRznfZN5azAZl8E0fgnhETkEf4FUuAYJG2PAv3mdOs hzBuFXnu7ItacKES8EPoRUmLOwNlaSpVy456ogAk+b3AvJs50CaoJHkq+qNUj/jAN7jE nz/ejjux5nP3MClh8TxQkpm3o2EHZgigNxCMOh+n0EV8+CdMxCSQVXStaua0ZgUJCiBt Br5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SHogG2LDNYMpKAnj+yA1kU5df/jIvMfB3AX9e8CKk5Q=; b=Toj/rxOMKkoNnoD5jl5NXcesCzA4fQ/4psJGmc9mOLh0KtJVnZsL7ROHeb5bkui51m ctIhIuI13839n/WpV8kdqSKG8ScYL3wyoXYJ6n5VHBHmEvbYQRC2VaqAgHWyKdmT5Hy2 1lYiqutRJiZtD85jx0g4/a2PHcgZ7SKh6q5uDd/2K9g7FrMDuDaI/kw6krncPKvaUzjV pdzRBUwNf1kHfugUbuEx/hhvbA24I7VAEdCBtELGKGBO+X/+ItKt5uFr7tu5HElSqdB3 khmAAPfnBBC2VYs4p5VY/Fdm2ZoGR3Dxl3h47PNt6X+cl2vQHp8nXVZza/bbgZw+icCP oK5w== X-Gm-Message-State: AO0yUKWEK00/pWWff/HcRBZzBP7jiVkksM1jR5uRqFhekqYT7Qam9/fe 28bulOKTvmbdn9rmTEiON5gaUO9AlIdW6TwLc+iPdA== X-Google-Smtp-Source: AK7set8Tlpt0l9zSd2Ls40nRHuuybUPIQY9OPfJ8q+1se4mX40SUAsOH3ldxioQc54rTxF2xHul/dQj3q3UO1rqhHfo= X-Received: by 2002:a17:907:7b8a:b0:8af:2ad8:3453 with SMTP id ne10-20020a1709077b8a00b008af2ad83453mr10329720ejc.6.1677114310566; Wed, 22 Feb 2023 17:05:10 -0800 (PST) MIME-Version: 1.0 References: <20230207025259.2522793-1-mcgrof@kernel.org> <20230207025259.2522793-3-mcgrof@kernel.org> In-Reply-To: From: Yosry Ahmed Date: Wed, 22 Feb 2023 17:04:32 -0800 Message-ID: Subject: Re: [RFC 2/2] shmem: add support to ignore swap To: Luis Chamberlain 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 Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 45AFE80011 X-Stat-Signature: 9enr71cxg71fk4jfkrzdhux1nsesqyot X-HE-Tag: 1677114312-841821 X-HE-Meta: U2FsdGVkX1/Nq6iQOvUU2MFPS6jMfYxrThiJ2eF29yRljGqU/GtjQz5MipAlAIhrPFGWrjE+9HT9/q73prZXxF2xM/EgHROrdGTnfsUiRvmfQb24w7o+aJRzGyXzqU9WHrxnlb+YwJsJzLxqrhfStimzLVGxhi3xbR4DZ9pSWgABSk3SP3AQ0RVm/Ck04NW6pQLs7l1pK3NBczonHiv3WY4tPPa1ga/sh01cPmOvEftdF1g8NEwpHpzdEbVBE7x4XJRDG80rB2GDxIePNRqXb8pCIBowdCf4VawAf/F6HJmg3lbCUv3fPaFM5WKi555sGiZB0VFiJnUZvIQuGy0IVYSdmTErikbdxfr+oHs9RDLjUYew/huTNXf6E7qlGDtcBTEk6I/GKa778J4v7Q607pPkJSsEe/Ik/VeNzv5i1xvCfZTq2vBRkHgbEwcy0QzcqQpISIq1fyx+9/dlhAGu6OJtzOcoW9/gJJQJ2Uabtie5Etx2Au/upq/6J4Nev4WnxRh+IuARiuCyYxLZXRSProrZ7YnsL0AaS8W7u3Emh522qtoBLbt3ZFkgbDHXxsiPK8mMiHMZ6seGRXqk4dYDeRR4uxCmcMXsbK5p0KVZokmPpYGKjJdEB+Dl3tD7+BH26rlSqM6O1NLqXDcFUe0cJzDEWcJIhvQaonkUUc7oU9z9w5BYp4oeG4h0UavGge0oAQlmIJcCo7G3w+0K8x7LgGFx1wYeDcNhbH89lH+M659GF/taXJ28Z5XDCtqrLmL5f40yHMUbWFMgHtHrjJ5slGt2aKdDHJxz6C1B0uzxOmOgbnN7hJlkpaM1kfoR07J1ziJ7Qxe6SgEPRWYIH/d+tbXQ1e42gx7UTAul5C7HMKHgA8kLD29DdeNOi7Ifuhf6mimzKYAHfO7eJSiEN83b9phyuwTEy3NZWumjq8+nGfLvqJmRGSoZWNQ+8nReNmOyhJ+tgcbHSvNwoJg5AjI XT2nmjOm +stufrLDD+XEKIeI1UhdBMl+FKtWT2DCmzmWEspZbFyflkQpFgFvpVoGuOnJ5gJXKp14+sQm8qmLVPOojDzrpLmRea2ge1lduhDLscnbKqRlFPo25dsINMcDHqBA9YiDwddsyL4MfolIhhqv1YMvJ/NQ+Qjzl7jTQnkGo+kl3zcMIKgXnxWtJel0i8ez7aQad9qlc7AJCSW6acV7YlQBwxvsXFGOPxHjolSyDauTIeKUOEV45IIQ67C4cjlPd50sQH3T0CrcbAwdmUcNX4Ms3DTNQHzYE3wDkqk27458nBV5t8qsDoTexF3M/qmAu57UFPB9SGWeyOmMAffzQb+rErKctLoLQmgRqv0b5/FRh097HKsI= 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 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. 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). Anyway, I am not very knowledgeable here so take anything I say with a grain of salt. Thanks. > > Luis