Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3257821imc; Wed, 13 Mar 2019 12:59:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWd+3EEPyrw6VNYU3o8KJp+XcNaW8miwhNxbcmWiuBbxEDV9OZN7OdU+TfD/PTBmL1GI97 X-Received: by 2002:a62:20d2:: with SMTP id m79mr46719650pfj.135.1552507179345; Wed, 13 Mar 2019 12:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552507179; cv=none; d=google.com; s=arc-20160816; b=qR5wCJXil2s6+QiiCbwRYQpTCrOac4OjXwUS2Bb14gNxbEaBEbOyB+XvJ8aafFwxg+ s+s5b0oyLRzRah7aS9Ju8eV+ofQQOLxXPbPNhYdVbwE9MiEf0OcCUhnf49nv/sL5hc8z 0jRM/F1oAE1lsMx03uznfzit6gjEdGmTmU8033fFJyWbA2BfydfgkO2yt2NSMsoX82nD NXAjJwFAjJFNyAZtov6crP7R4olzWwZRsSYIClwcB2fGLIxyA2UBfC2ZSAk6AwtHOUuC 3R7srZFDmKGh67uyZmBQNkBh3/eVS7bvVFPMPzJy5yCBkNw186pTUCve4CkZTfb3HwiM G6Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=SajRrUaUGaud6Nn4Qj6K9i18P4JO+MNtdJ37Bn8y7bQ=; b=I1sDXVDy7m5VrUqNVgJ1fvuEkRRkrutnf4KJHX8ddeHhR9bzkvBDm0n1uIyuhpxP9H JkaoFdRaIH5POn5XfJmIqj0jeZLWY+3U9E99YsnnWjAS6L+3N+YaHsMJsw+I4MMDaAl6 EhbT3neRNdDk5geULKiE6eUyjzjdb3ERQ5KZDxyfGDvNnI044wZzuFT/X7aBzVURyvvq Q0u7ksY5KkKG7e/jihq2TsiyIMYizEU7WlT0qW13fXTqItXPwC/E8kfo3lk4DDl96kLQ S5FA/wKcal9umk5G0wK9Xr/BT/crRuE6J0jhVy789VbhDYF8vtMQBgvbE//bedpneX/n fFgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="SBr3m5X/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j187si11276180pfc.251.2019.03.13.12.59.23; Wed, 13 Mar 2019 12:59:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="SBr3m5X/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727207AbfCMT7B (ORCPT + 99 others); Wed, 13 Mar 2019 15:59:01 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41450 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727151AbfCMT7A (ORCPT ); Wed, 13 Mar 2019 15:59:00 -0400 Received: by mail-pg1-f194.google.com with SMTP id k11so2260526pgb.8 for ; Wed, 13 Mar 2019 12:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=SajRrUaUGaud6Nn4Qj6K9i18P4JO+MNtdJ37Bn8y7bQ=; b=SBr3m5X/eJzdT+sEonH+SmkvXYruM+CrkEu9nppT3EY0319WJl+seG3l5xz3A4DZYE A+oRZ9HXJeu60cYin5WicOu2UtNbEI4SBvN25Tni1LO2EXl+FCnyKxPkxb7K6d9IRthM 6sVG/zHpR+leoapOgFGFCQayKJJr81IyKkQ3KgWD9FHZEi+H7GyYf9aGJILNWm3j5MJv 7X8Ap3skyXpWAGZJbnrxBuZltTxhekSKYPjUddN1oy4zJFFHkKnvFlvpnuorr/qczwVy su7wZJV7u72Q1W1t881hlTX/VvhqJdGEGK+UJpXt/fG3xqpYm9CN7TbG1JfQPB8qIvCu Uy9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=SajRrUaUGaud6Nn4Qj6K9i18P4JO+MNtdJ37Bn8y7bQ=; b=Z08cRfoZmjttKG2H41p/OvNXc5/4ZLorvgNQ/pFNQ7NgZBgVMiNUc5z1yaHtOKJsvh N2NWy6R65h+UcBpvPfgIxgLqeBPmBpoPSj6+LfGGS1Ij/dcYnFDJ+1Ek+Zg27O5a92Gp 7mGloC1WMy3wvx5dnTrOkR99V29pKKadCCSh4LyoxeLWEEMmgdfAfHL5PSoqN/dfvcQc UleCyv3yTOicPXnJGWR6Th5uR8YlnrKdVrWM7BU3LURu5LIbzx02NsJQKJWQCfhQSjvt SUCvL+rFu6+Kd9wPKFN7bhssY92+lip++6MbRwIm9nNq0AChdWdoAlUTuWT6phfN+I5c ZWVg== X-Gm-Message-State: APjAAAXhOELIKirVRjFhq63bgU02ZN3YZxKs2IEXSuZWf0ZVckOD0x0b iNlad7rZ3YDtUaNvQ4PucBUGFyYNexM= X-Received: by 2002:a63:2bcd:: with SMTP id r196mr40920203pgr.355.1552507138925; Wed, 13 Mar 2019 12:58:58 -0700 (PDT) Received: from [100.112.89.103] ([104.133.8.103]) by smtp.gmail.com with ESMTPSA id e63sm17933208pfa.116.2019.03.13.12.58.57 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Mar 2019 12:58:58 -0700 (PDT) Date: Wed, 13 Mar 2019 12:58:26 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Sasha Levin cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, "Darrick J. Wong" , Hugh Dickins , Andrew Morton , Linus Torvalds , linux-mm@kvack.org Subject: Re: [PATCH AUTOSEL 4.20 37/60] tmpfs: fix link accounting when a tmpfile is linked in In-Reply-To: <20190313191021.158171-37-sashal@kernel.org> Message-ID: References: <20190313191021.158171-1-sashal@kernel.org> <20190313191021.158171-37-sashal@kernel.org> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org AUTOSEL is wrong to select this commit without also selecting 29b00e609960 ("tmpfs: fix uninitialized return value in shmem_link") which contains the tag Fixes: 1062af920c07 ("tmpfs: fix link accounting when a tmpfile is linked in") Please add 29b00e609960 for those 6 trees, or else omit 1062af920c07 for now. Thanks, Hugh On Wed, 13 Mar 2019, Sasha Levin wrote: > From: "Darrick J. Wong" > > [ Upstream commit 1062af920c07f5b54cf5060fde3339da6df0cf6b ] > > tmpfs has a peculiarity of accounting hard links as if they were > separate inodes: so that when the number of inodes is limited, as it is > by default, a user cannot soak up an unlimited amount of unreclaimable > dcache memory just by repeatedly linking a file. > > But when v3.11 added O_TMPFILE, and the ability to use linkat() on the > fd, we missed accommodating this new case in tmpfs: "df -i" shows that > an extra "inode" remains accounted after the file is unlinked and the fd > closed and the actual inode evicted. If a user repeatedly links > tmpfiles into a tmpfs, the limit will be hit (ENOSPC) even after they > are deleted. > > Just skip the extra reservation from shmem_link() in this case: there's > a sense in which this first link of a tmpfile is then cheaper than a > hard link of another file, but the accounting works out, and there's > still good limiting, so no need to do anything more complicated. > > Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1902182134370.7035@eggly.anvils > Fixes: f4e0c30c191 ("allow the temp files created by open() to be linked to") > Signed-off-by: Darrick J. Wong > Signed-off-by: Hugh Dickins > Reported-by: Matej Kupljen > Acked-by: Al Viro > Signed-off-by: Andrew Morton > Signed-off-by: Linus Torvalds > Signed-off-by: Sasha Levin > --- > mm/shmem.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > index 5d07e0b1352f..7872e3b75e57 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -2852,10 +2852,14 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr > * No ordinary (disk based) filesystem counts links as inodes; > * but each new link needs a new dentry, pinning lowmem, and > * tmpfs dentries cannot be pruned until they are unlinked. > + * But if an O_TMPFILE file is linked into the tmpfs, the > + * first link must skip that, to get the accounting right. > */ > - ret = shmem_reserve_inode(inode->i_sb); > - if (ret) > - goto out; > + if (inode->i_nlink) { > + ret = shmem_reserve_inode(inode->i_sb); > + if (ret) > + goto out; > + } > > dir->i_size += BOGO_DIRENT_SIZE; > inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode); > -- > 2.19.1